分类: LINUX
2010-01-12 20:51:35
1.自动scp脚本scp.exp:
#!/usr/local/bin/expect
spawn scp /home/nagios/tuning-primer.sh nagios@192.168.100.104:/home/nagios/
expect "Password:"
exec sleep 2
send "nagios&*(\n"
interact
执行:expect scp.exp
2.自动telnet脚本:
#!/bin/sh
( echo sybase
sleep 2
echo sybase
sleep 3
echo "\n"
sleep 2
echo "ps "
sleep 2
echo logout ) | telnet alpha
自动ssh脚本:
#!/usr/bin/expect -f
# ssh连接的expect脚本
set host [lindex $argv 0]
spawn ssh -l notsobad $host
expect {
"*(yes/no)*" { send "yes\r" }
"*password*" { send "my_password\r" }
}
expect "*Last login*" { interact }
wang@wang-desktop:~$ ssh.exp 10.16.2.1
自动ftp的脚本1:
#!/bin/sh
echo "open 10.0.0.2 21
user anonymous passwd
bin
cd kscfg
get $1
bye"|ftp -i -in
自动ftp脚本2:
#!/bin/sh
F="xxxx.ftp"
echo "open 192.168.7.51 21" > $F
echo "user anonymous passwd" >> $F
echo "bin" >> $F
echo "cd /home/xxx/" >> $F
echo "mput $1" >> $F
echo "bye" >> $F
ftp -i -in < $F
rm -rf $F