功能:
将文件发送到配置文件中指定的服务器上, 且目录为最大分区.
batch.sh
#! /bin/sh
list_file=$1
src_file=$2
cat $list_file |
while read line
do
host_ip=`echo $line | awk '{print $1 }'`
username=`echo $line | awk '{print $2 }'`
password=`echo $line | awk '{print $3 }'`
echo "$host_ip"
./ssh_test $host_ip $username $password
./SCP2 $host_ip $username $password
cat log.txt | grep -i '/dev/' > log2.txt
sort -k4 log2.txt > log3.txt
tail -1 log3.txt > log4.txt
dest_file=`awk '{print $6}' log4.txt`
./SCP $host_ip $username $password $src_file $dest_file
done
SCP
#! /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
SCP2
#! /usr/bin/expect
set timeout 10
set host [lindex $argv 0]
set username [lindex $argv 1]
set password [lindex $argv 2]
spawn scp $username@$host:./logtest.txt ./log.txt
expect {
"(yes/no)?"
{
send "yes\n"
expect "*assword:" {send "$password\n"}
}
"*assword:"
{
send "$password\n"
}
}
expect "100%"
expect eof
ssh_test
#! /usr/bin/expect
set host [lindex $argv 0]
set username [lindex $argv 1]
set password [lindex $argv 2]
spawn ssh $username@$host
expect {
"(yes/no)?"
{
send "yes\n"
expect "*assword:" {send "$password\n"}
}
"*assword:"
{
send "$password\n"
}
}
expect "*#"
send "df > logtest.txt\n"
expect "*#"
send "exit\n"
expect eof