文件部署

功能:

将文件发送到配置文件中指定的服务器上, 且目录为最大分区.


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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值