首页 > 服务器 > 管理维护 > 正文

shell脚本连接并重启远程服务器的方法

2020-07-28 14:39:40
字体:
来源:转载
供稿:网友

shell重启远程服务器

#connServer.sh 登陆服务器脚本 本地文件#!/usr/bin/expectexpect -c "spawn ssh ali@192.168.1.1expect {/"*assword/" {set timeout 30; send /"123456/r/";}/"yes/no/" {send /"yes/r/"; exp_continue;}}send /"cd /home/ali/demoProject /r/"     #根据系统而定 maybe /User/alisend /"sh reboot.sh /r/"expect eof"

echo "重启成功!"

#reboot.sh 重启脚本 该文件是放在远程服务器的文件#!/usr/bin/bashps aux | grep /home/ali/demoProject/index.js | awk '{print $2}' | xargs killps -ef | grep /home/ali/demoProject/index.jsecho "success reboot!"

#下面这条命令以绝对路径启动 方便以后kill 该进程

nohup node /home/ali/demoProject/index.js &

不知道什么原因,如果想再connecServer.sh中发送reboot.sh 的脚本命令,

有一个问题 : $2 没了. 奇迹般的消失在命令行中.

现在采取折中的办法就是将这条带有$2的命令,放在服务器端单独一个文件里, 在本地执行这个reboot.sh文件.

以上所述是小编给大家介绍的shell脚本连接并重启远程服务器,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对错新网之家网站的支持!

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表