get '/api/auto_publish/publish' => sub{ my $c = shift; my $env = $c->param('env'); my $app = $c->param('app'); my $ip = $c->param('ip'); my $stderr=""; my $stdout=""; my $XDATE = strftime("%Y%m%d%H%M%S",localtime()); #and info='$app' and ip='$ip' use DBI; my %hash=(); my $dbUser='DEVOPS'; my $user="root"; my $passwd="1234567"; my $dbh = DBI->connect("dbi:mysql:database=$dbUser;host=192.168.32.161;port=3306",$user,$passwd) or die "can't connect to database ". DBI-errstr; my $hostSql = qq{select script from publish_info where env='$env' and info='$app' and ip='$ip'}; my $selStmt = $dbh->prepare($hostSql); print "\$hostSql is $hostSql\n"; $selStmt->execute(); my $script = $selStmt->fetchrow_array(); print "\$script is $script\n"; use Net::SSH::Perl; my $host="$ip";; my $user='root'; my $passwd='xxxx'; my $cmd="sh $script"; my $ssh = Net::SSH::Perl->new($host,port=>22); $ssh->login($user,$passwd); my ($stdout,$stderr,$exit) = $ssh->cmd("$cmd"); $ssh->cmd("exit"); if($exit != 0){ print "ErrorCode:$exit\n"; print "ErrorMsg:$stderr"; open( F, ">>", "/home/scan/mojo/log/$app-$ip-$XDATE.log" ); print F ("ErrorCode:$exit\n"); print F ("ErrorMsg:$stderr\n"); close F; $c->render(text => "ErrorCode:$exit;ErrorMsg:$stderr") } else { print $stdout; open( F, ">>", "/home/scan/mojo/log/$app-$ip-$XDATE.log" ); print F ("ErrorCode:$exit\n"); print F ("ErrorMsg:$stderr\n"); print F ("$stdout\n"); close F; $c->render(text => 'publish success') } }; 脚本名字存放在数据库中: mysql> select * from publish_info; +----+----------------+-----------------+------+---------------------------+ | sn | ip | info | env | script | +----+----------------+-----------------+------+---------------------------+ | 1 | 121.xx.xx.9xx | uat-frontend | uat | /root/auto_run/publish.sh | | 2 | 1.1.1.1 | aa | test | /root/auto_run/publish.sh | | 3 | 121.xx.1xxx.1xx | zjzc-hy-pre-01 | uat | /root/auto_run/publish.sh | | 6 | 121.0.1.8 | zjzc-hy-core-01 | uat | /root/auto_run/publish.sh | +----+----------------+-----------------+------+---------------------------+ 4 rows in set (0.00 sec) 调用的shell脚本内容:
Mojo 自动发布接口
转载本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
上一篇:表单提交
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
接口持续集成方法 Windouws+Jmeter+ant+jenkins+企业微信 自动发送接口执行报告
Windouws+Jmeter+ant+jenkins执行自动发布接口报告 线上接口定时巡检
jmeter ant jenkins 接口持续集成 -
Mojo~
Mojo 最初的目标是比 Python 快 35000 倍,近日该团队表示,Mojo 将动态与静态语言的优点结合起来,一举将性能提升达 Python 的 6
人工智能 Python 编程语言 基础设施 -
mojo plugins
http://mojo.codehaus.org/plugins.htmlPluginsDepending on their maturity, the available plugins are organized i
plugins maven generation compilation localization -
NDArray implementation in mojo
【代码】NDArray implementation in mojo。
mojo python 开发语言 Express List