#!/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'