失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > 实现自动带密码登陆远程机执行shell命令(linux)

实现自动带密码登陆远程机执行shell命令(linux)

时间:2018-10-08 10:45:02

相关推荐

实现自动带密码登陆远程机执行shell命令(linux)

在centos下使用expect,实现带密码登陆远程机并执行shell命令。

第一步:安装expect

sudo yum install expect

第二步:建立测试脚本

#!/usr/bin/expectset timeout 10if {[llength $argv]<2}{puts "Usage:"puts "$argv0 local_file remote_path"exit 1}set local_file[lindex $argv 0]set remote_path [lindex $argv 1]set passwd xxxxxx(your passwd)set passwderror 0spawn scp $local_file $remote_pathexpect{"*assword:*"{if {$passwderror == 1}{puts "passwd is error"exit 2}set timeout 1000set passwderror 1send "$passwd\r"exp_continue}"*es/no)?*"{send "yes\r"exp_continue}timeout {puts "connect is timeout"exit 3}}

第三步:测试脚本

./scp.exp test.sh username@host:/xx/yy

引自/article/62349.htm

如果觉得《实现自动带密码登陆远程机执行shell命令(linux)》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。