一.远程连接一台机器,不必输入密码:
ssh 192.168.82.3 -tt<<EOF #cd /root/AT_EInfoworks/svn/public cd /home/hao ./su_all.sh logout EOF
链接之后执行的脚本:
二.su_all.sh
echo "1.from root change to hao..." echo "::::::::::::::::::::::::::::" /home/hao/rootTohao.sh echo "2.from hao change to localuser,than from localuser change to hao..." echo "::::::::::::::::::::::::::::" /home/hao/haoTolocaluser.sh echo "3.from hao change to localuser..." echo "::::::::::::::::::::::::::::" /home/hao/haoToroot.sh
1.rootTohao.sh
#!/usr/local/bin/expect set timeout 1 spawn su hao expect "密码:" #exec sleep 1 #send "hao\r" send "exit\r" interact
2.haoTolocaluser.sh
#!/usr/local/bin/expect set timeout 1 spawn su localuser #spawn ssh hao@192.168.77.80 expect "密码:" #exec sleep 1 send "123\r" expect "$" send "exit\r" interact #interact eof
3.haoToroot.sh
#!/usr/local/bin/expect set timeout 1 spawn su hao expect "密码:" #exec sleep 1 #send "hao\r" send "exit\r" interact
本文转自 念槐聚 博客园博客,原文链接:http://www.cnblogs.com/haochuang/archive/2012/09/06/2673934.html,如需转载请自行联系原作者