由于shell不熟,首先想到的是scp命令,把日志拷贝走之后,再rm -rf 删除日志,把这个脚本写到
crontab里就行了,结果开始就碰到问题,scp要提示输入密码,先解决这个问题
在服务器端,也就是要执行脚本的机器上输入:ssh-keygen -b 1024 -t rsa
出现下面的提示:[root@linux-test1 ~]# ssh-keygen -b 1024 -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
07:8d:14:fd:e6:ab:d5:b8:85:62:7b:38:50:4a:c1:26 root@linux-test1
一路回车。。。。。 代表无证书密码。
上述命令将生成私钥证书id_rsa和公钥证书id_rsa.pub,存放在用户家目录的.ssh子目录中。
将公钥证书id_rsa.pub复制到机器Server的root家目录的.ssh子目录中,同时将文件名更换为authorized_keys。
[root@linux-test1 ~]# scp -p .ssh/id_rsa.pub root@192.168.1.1:/root/.ssh/authorized_keys
[root@linux-test1 ~]# scp -p .ssh/id_rsa.pub root@192.168.1.1:/root/.ssh/authorized_keys
Address 192.168.1.1 maps to localhost, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT!
root@10.10.1.11's password:
id_rsa.pub 100% 226 0.2KB/s 00:00
再测试下,OK,直接就拷贝过去了。
vi 个脚本,
vi logs.sh
scp -r /usr/local/tomcat71/logs/ root@192.168.1.1:/home/logbackup/71
scp -r /usr/local/tomcat72/logs/ root@192.168.1.1:/home/logbackup/72
scp -r /usr/local/tomcat73/logs/ root@192.168.1.1:/home/logbackup/73
scp -r /usr/local/tomcat74/logs/ root@192.168.1.1:/home/logbackup/73
rm -rf /usr/local/tomcat71/logs/*
rm -rf /usr/local/tomcat72/logs/*
rm -rf /usr/local/tomcat73/logs/*
rm -rf /usr/local/tomcat74/logs/*
:wq 保存退出
我是保存4个tomcat的日志,写到crontab里
crontab -e
30 2 10 * * /bin/sh /data/scropts/log.sh
保存退出,测试/bin/sh /data/scropts/log.sh能不能执行
/bin/sh /data/scropts/log.sh
阅读(2410) | 评论(0) | 转发(0) |