几个shell

一.远程连接一台机器,不必输入密码:

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

 

 

 

 

 

 

 

 

 

 

 

posted @ 2012-09-06 17:49  念槐聚  阅读(278)  评论(0编辑  收藏  举报