linux expect实现sudo自动交互的问题求助
答案:2 悬赏:10 手机版
解决时间 2021-02-20 18:11
- 提问者网友:雨不眠的下
- 2021-02-20 03:03
linux expect实现sudo自动交互的问题求助
最佳答案
- 五星知识达人网友:杯酒困英雄
- 2021-02-20 04:28
1 #!/usr/bin/expect
2
3 set timeout 20
4 spawn ssh root@172.16.111.222
5 expect "*password*"
6 send "root123\r"
7
8 expect "*#"
9 send "rm -rf /var/FTP.tar.gz\r";
10
11 expect "*#"
12 send "sudo -i\r"
13 expect "*password*"
14 send "root123\r"
15
16 expect "*#"
17 send "tar zcvf /var/FTP.tar.gz /var/ftp/\r"
18
19 expect "*#"
20 send "exit\r"
21 sleep 1
22 spawn scp root@172.16.111.222:/var/FTP.tar.gz ./
23 expect "*password"
24 send "root123\r"
25 expect "*#"
26
27 exit
2
3 set timeout 20
4 spawn ssh root@172.16.111.222
5 expect "*password*"
6 send "root123\r"
7
8 expect "*#"
9 send "rm -rf /var/FTP.tar.gz\r";
10
11 expect "*#"
12 send "sudo -i\r"
13 expect "*password*"
14 send "root123\r"
15
16 expect "*#"
17 send "tar zcvf /var/FTP.tar.gz /var/ftp/\r"
18
19 expect "*#"
20 send "exit\r"
21 sleep 1
22 spawn scp root@172.16.111.222:/var/FTP.tar.gz ./
23 expect "*password"
24 send "root123\r"
25 expect "*#"
26
27 exit
全部回答
- 1楼网友:罪歌
- 2021-02-20 05:25
#!/usr/bin/expect set time 30 set passwd xxxxx (xxxx是你的密码内容) spawn sudo expect "password:" 引号里是你手动执行sudo时候 。系统返回给你的提示,可以只匹配最后几个字母, 也可以写全 send "$passwd\r" expect eof eof
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯