将一台服务器上的日志文件拷贝到另外一台上

将一台服务器上的日志文件拷贝到另外一台服务器上。要求只拷贝每个月1号、11号、21号的日志

首先在当前目录下新建一个date的文件夹,里面输入要截取的日期01、11、21

for i in `cat /luyan/date`
do
scp -r /var/applog/*.2018-*-$i.*.log   root@172.29.1.219:/luyantest/src
echo "/var/applog/*.2018-*-$i.*.log"
done

结果如下:

 

[root@pays01pre luyan]# sh cp.sh
root@172.29.1.219's password:
action-access.2018-07-01.0.log 100% 306KB 306.5KB/s 00:00
action-access.2018-08-01.0.log 100% 3883KB 3.8MB/s 00:00
action-access.2018-09-01.0.log 100% 578KB 577.7KB/s 00:00
action-access.2018-10-01.0.log 100% 383KB 383.3KB/s 00:00
action-access.2018-11-01.0.log 100% 661KB 660.8KB/s 00:00
action-access.2018-12-01.0.log 100% 96KB 95.7KB/s 00:00
error.2018-07-01.0.log 100% 257KB 257.0KB/s 00:00
error.2018-08-01.0.log 100% 55MB 54.6MB/s 00:00
error.2018-09-01.0.log 100% 195KB 195.2KB/s 00:00
error.2018-11-01.0.log 100% 1716KB 1.7MB/s 00:00
main.2018-07-01.0.log 100% 14MB 14.2MB/s 00:00
main.2018-08-01.0.log 100% 68MB 67.6MB/s 00:01
main.2018-09-01.0.log 100% 6323KB 6.2MB/s 00:00
main.2018-10-01.0.log 100% 719KB 719.0KB/s 00:00
main.2018-11-01.0.log 100% 12MB 12.2MB/s 00:00
main.2018-12-01.0.log 100% 102KB 102.1KB/s 00:00
other.2018-07-01.0.log 100% 8626KB 8.4MB/s 00:00
other.2018-08-01.0.log 100% 16MB 15.6MB/s 00:01
other.2018-09-01.0.log 100% 6596KB 6.4MB/s 00:00
other.2018-10-01.0.log 100% 6566KB 6.4MB/s 00:00
other.2018-11-01.0.log 100% 7440KB 7.3MB/s 00:00
other.2018-12-01.0.log 100% 3280KB 3.2MB/s 00:00
/var/applog/*.2018-*-01.*.log
root@172.29.1.219's password:
action-access.2018-07-11.0.log 100% 342KB 342.4KB/s 00:00
action-access.2018-08-11.0.log 100% 725KB 724.7KB/s 00:00
action-access.2018-09-11.0.log 100% 699KB 698.6KB/s 00:00
action-access.2018-10-11.0.log 100% 501KB 501.4KB/s 00:00
action-access.2018-11-11.0.log 100% 407KB 407.1KB/s 00:00
error.2018-07-11.0.log 100% 1657KB 1.6MB/s 00:00
error.2018-08-11.0.log 100% 561KB 561.3KB/s 00:00
error.2018-09-11.0.log 100% 796KB 795.8KB/s 00:00
error.2018-10-11.0.log 100% 274KB 274.5KB/s 00:00
error.2018-11-11.0.log 100% 265KB 264.8KB/s 00:00
main.2018-07-11.0.log 100% 16MB 15.9MB/s 00:00
main.2018-08-11.0.log 100% 14MB 13.6MB/s 00:00
main.2018-09-11.0.log 100% 11MB 11.3MB/s 00:01
main.2018-10-11.0.log 100% 6118KB 6.0MB/s 00:00
main.2018-11-11.0.log 100% 2191KB 2.1MB/s 00:00
other.2018-07-11.0.log 100% 8040KB 7.9MB/s 00:00
other.2018-08-11.0.log 100% 7391KB 7.2MB/s 00:00
other.2018-09-11.0.log 100% 7527KB 7.4MB/s 00:00
other.2018-10-11.0.log 100% 7008KB 6.8MB/s 00:00
other.2018-11-11.0.log 100% 6716KB 6.6MB/s 00:00
/var/applog/*.2018-*-11.*.log
root@172.29.1.219's password:
action-access.2018-07-21.0.log 100% 723KB 723.0KB/s 00:00
action-access.2018-08-21.0.log 100% 1741KB 1.7MB/s 00:00
action-access.2018-09-21.0.log 100% 731KB 731.4KB/s 00:01
action-access.2018-10-21.0.log 100% 439KB 439.5KB/s 00:00
action-access.2018-11-21.0.log 100% 631KB 630.7KB/s 00:00
error.2018-07-21.0.log 100% 197KB 197.2KB/s 00:00
error.2018-08-21.0.log 100% 11MB 10.9MB/s 00:00
error.2018-09-21.0.log 100% 1581KB 1.5MB/s 00:00
error.2018-10-21.0.log 100% 1573KB 1.5MB/s 00:00
error.2018-11-21.0.log 100% 1220KB 1.2MB/s 00:00
main.2018-07-21.0.log 100% 9526KB 9.3MB/s 00:00
main.2018-08-21.0.log 100% 32MB 32.0MB/s 00:00
main.2018-09-21.0.log 100% 8569KB 8.4MB/s 00:00
main.2018-10-21.0.log 100% 4991KB 4.9MB/s 00:01
main.2018-11-21.0.log 100% 7522KB 7.4MB/s 00:00
other.2018-07-21.0.log 100% 7106KB 6.9MB/s 00:00
other.2018-08-21.0.log 100% 10MB 9.8MB/s 00:00
other.2018-09-21.0.log 100% 7690KB 7.5MB/s 00:00
other.2018-10-21.0.log 100% 6718KB 6.6MB/s 00:00
other.2018-11-21.0.log 100% 8282KB 8.1MB/s 00:00

但是我这个写法每执行一次就需要输入一个密码,研究下以后怎么写不需要输入密码

 

转载于:https://www.cnblogs.com/ddddddf0917/p/10066339.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值