linux scp文件脚本 附带ftp脚本
ssh-keygen -t rsa获取密钥
cat /root/.ssh/id_*.pub 查看密钥,黏贴到服务器的.ssh/authorized_keys中(用户家目录)
vi scp.sh
#!/bin/bash
IP=`hostname -I | awk '{print $2}'`;
#获取本机IP,有的不止一个IP
TIME=`date '+%Y%m%d'`;
scp -P 60522 /var/log/wtmp 用户名@IP:/home/systemlog/${TIME}_${IP}_wtmp
scp -P 60522 /var/log/btmp 用户名@IP:/home/systemlog/${TIME}_${IP}_btmp
scp -P 60522 /var/log/history 用户名@IP:/home/systemlog/${TIME}_${IP}_history
###ftp上传脚本
#!/bin/bash
#本机log文件目录
log_dir="/home/systemlog/"
#因为本机的日志,规范化命名后,上传至 /home/systemlog/
time=`date '+%Y%m%d'`;
IP=`hostname -I`;
cp /var/log/wtmp /home/systemlog/${time}_${IP}_wtmp
cp /var/log/btmp /home/systemlog/${time}_${IP}_btmp
cp /var/log/history /home/systemlog/${time}_${IP}_history
#ftp连接4A服务器,上传日志至4A
#ftp服务器目录按年月日生成目录,共有三级
#连接ftp服务器
ftp -v -n 10.243.96.101< user 4A服务器ftp账号 密码 binary hash #进入服务器上的目录 cd AQ014/${time}/01 #进入/home/systemlog/ lcd $log_dir #免交互 prompt off #上传当前目录下全量当天日志文件 mput ${time}_* close bye EOF