linux免交互远程执行脚本,密码在脚本中配置

来源:互联网 发布:windows卸载ruby 编辑:程序博客网 时间:2024/05/21 21:48

先安装expect

yum install expect

编写下面的脚本:

#!/bin/expect

set timeout 30
spawn ssh -l root 192.168.201.225
expect "password:"
send "远程主机的密码"
expect "#"
#send "echo '111'>/root/111.txt\r"
send "cd /root\r"
expect "#"
send "wget http://192.168.192.24:8080/monitor.tar\r"
expect "#"
send "tar -xvf monitor.tar\r"
expect "#"
send "sed -i '/monitor.sh/d' /etc/crontab\r"
expect "#"
send "echo '* * * * * sh /root/monitor/monitor.sh' >> /etc/crontab\r"
expect "#"
send "exit\r"

interact


注意:

send 后面的命令结尾必须加上\r

每个命令后面必须加上expect "#",再执行下一个命令

阅读全文
0 0
原创粉丝点击