shell 自动登录

#!/bin/bash
expect -c '
spawn  scp /iManagerNastarV600R010C00SPC600_HP_X86_64.tar.gz  root@10.144.113.215:/test/
expect /iManagerNastarV600R010C00SPC600_HP_X86_64.tar.gz
send   Changeme_215\n
expect eof
interact
wait'

{
echo Changeme_123
sleep 1s
echo Changeme_123
} |passwd root

{
echo Changeme_123
}| su - omcuser -c '
echo `whoami`'

function remote()
{
expect -c "
spawn  ssh $1@$3 $4
expect "password:Changeme_215"
send  $2\n\r
expect eof"
}
#################################################################################################################
expect -c '
spawn  ssh -l root 10.144.113.215
expect "password:"
send  Changeme_215\n
expect eof
interact
wait'

expect -c "
spawn  ssh root@10.144.113.215 {ifconfig|grep 'inet addr:'|sed -n '1p'|cut -d: -f2|cut -d' ' -f1 ;whoami}
expect "password:"
send  Changeme_215\n
expect eof"
ifconfig|grep 'inet addr:'|sed -n '1'p|awk -F' ' '{print $2}'|awk -F':' '{print $2}'
ifconfig|grep 'inet addr:'|sed -n '1p'|cut -d: -f2|cut -d' ' -f1

expect -c "
spawn  ssh root@10.144.113.215 {/sh.sh; python /py.py;cp /sh.sh /test;echo cp is ok;cd /;ls *.gz}
expect "password:Changeme_215"
send  Changeme_215\n\r
expect eof"

##############################################################################################################

expect -c '
spawn  ssh root@10.144.113.215 {/sh.sh; python /py.py;cp /sh.sh /test;echo cp is ok;cd /;ls *.gz}
expect {
"Password*"
{send "Changeme_215\n"}
}
expect eof'
#############################################################################################################

 #!/usr/bin/expect
set timeout 10
set host [lindex $argv 0]
set username [lindex $argv 1]
set password [lindex $argv 2]
set src_file [lindex $argv 3]
set dest_file [lindex $argv 4]
spawn scp $src_file $username@$host:$dest_file
expect {
"(yes/no)?"
{
send "yes\n"
expect "*assword:" { send "$password\n"}
}
"*assword:"
{
send "$password\n"
}
}
expect "100%"
expect eof

 

expect -c "
  set timeout 30;  
  spawn ssh user@ip ls -l;
  expect {
         \"*yes/no*\" {send \"yes\r\"; exp_continue}
         \"*password*\" {send \"$passwd\r\";}
         }
  expect eof;"
###########################################################################################################
expect -c '
spawn  scp /iManagerNastarV600R010C00SPC600_HP_X86_64.tar.gz  root@10.144.113.215:/test/
expect {
"(yes/no)?"
{
send "yes\n"
expect "*assword:" { send "Changeme_215\n"}
}
"*assword:"
{
send "Changeme_215\n"
}
}
expect eof
interact
wait'

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值