linux推送文件到另一台主机
方法1:
#!/bin/bash ssh admin@IP1 > /dev/null 2>&1 << eeooff cd /export/Data/idiff/app/ cat app_commonurl.list | tail -n 500 >500.csv sleep 2 scp 500.csv searchguest@IP2:路径 sleep 20 eeooff
方法2:
#!/usr/bin/expect set timeout 2 set user_ip admin@IP1 set password 密码1 set password_local 密码2 spawn ssh ${user_ip} expect { "*yes/no*" {send "yes\r" } "*assword:*" { send "${password}\r"} "*yes/no*" {send "yes\r" } } expect "*4.1$" send "\r" expect "*4.1$" send "cd /export/App/jsfProxy/log\r" expect "*4.1$" send {more service_xtl.log | grep "ori reqParam" | awk -F 'reqParam=' '{print $2}' > 500.txt } sleep 5 expect "*4.1$" send { scp 500.txt admin@IP2:/路径 } expect { "*yes/no*" {send "yes\r" } "*assword:*" { send "密码\r"} "*yes/no*" {send "yes\r" } } expect eof