打版

亲测可用
#!/bin/sh
echo "shell script"
#声明一个函数查看指定目录下的服务名
function ls_server(){
    echo "hello world"
/usr/bin/expect <<EOF
set force_conservative 0 
spawn ssh oracle@192.168.6.37 {uname -a;df -h;cd /home/oracle;ls -lh}
#match_max 100000
expect "*?assword: "
send -- "oracle\r"

#指定交互
#interact
expect eof
EOF
}

ls_server
file=0
#指定同步文件
function scp_file(){
read file
#/usr/bin/expect <<EOF
#spawn ssh oracle@192.168.6.37 
#expect "*?assword: "
#send -- "oracle\r"
#send "cd /home/oracle\r"
#send "scp ./$file saoge@192.168.6.108:/home/saoge/NiuBi/testShell/"
#expect "*?assword: "
#send -- "123456\r"
#expect eof
#EOF
#echo "oracle" > scp oracle@192.168.6.108:/home/oracle/$file .
scp oracle@192.168.6.37:/home/oracle/$file .
}
scp_file
操作:目标;
登录到指定用户服务器目录下,列出所有的服务名
输入指定的服务名;然后进行拷贝;
然后重启本地对应的服务;
spawn:产卵;引发;引起;导致;造成

跳网例子
#!/bin/bash
passmsmallq10="a"
passzhsh="a"
passfcwr="b"
passwapfx="c"
passadfx="d"
 
ip1="200.100.10.10"
ip2="10.100.100.70"
ip3="10.100.100.60"
ip4="10.100.100.10"
ip5="10.100.100.20"
 
case $1 in 
"zhsh") passstr=$passzhsh ipstr=$ip2 ;;
"fcwr") passstr=$passfcwr ipstr=$ip3 ;;
"wapfx") passstr=$passwapfx ipstr=$ip4 ;;
"adfx") passstr=$passadfx ipstr=$ip5 ;;
*) echo "The parameter $1 isn't exist"
exit 0 ;;  www.2cto.com  
esac
command1="ssh -l m_smallq -p 36000 $ip1"
command2="ssh -l mqq -p 36000 $ipstr"
 
expect -c "
        set timeout 60;
        spawn $command1;
        expect {
                \"221.130.15.10's password:\" {send \"$passmsmallq10\r\"; exp_continue}
                \"m_smallq\" {send \"$command2\r\"; exp_continue}
                \"mqq's password:\" {send \"$passstr\r\";interact}
                }
        "
#!/bin/bash
ip1="183.62.178.191"
command1="ssh -l root -p 14322 $ip1"
 
expect -c "
        spawn $command1;
        expect {
                \"183.62.178.191's password:\" {send \"aa\r\"; exp_continue}
                \"root@\" {send \"df -h\r exit\r\"; exp_continue}
                }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值