Exercises content
answer
1 answer
[root@centos7 ~]# echo '*/1 * * * * /usr/bin/cp /etc /data/`/usr/bin/date +\%Y-\%m-\%d` -av' > /var/spool/cron/root
[root@centos7 ~]# crontab -l
*/1 * * * * /usr/bin/cp /etc /data/`/usr/bin/date +\%Y-\%m-\%d` -av
effect
[root@centos7 ~]# ls /data
1.txt~ 2019-07-23 2.txt~ 7.txtx a fi.log rootdir sysconfig-bak
[root@centos7 ~]# ll /data/2019-07-23 -d
drwxr-xr-x. 143 root root 8192 7月 23 08:49 /data/2019-07-23
Problems encountered:
1, the direct use
cp /etc/ /data/`date +%Y-%m-%d` -av
No problem
2, but the write crontab error, put the cp, date written as absolute path or command error,
Richard:
https://yq.aliyun.com/articles/539103
% Percent use the backslash ,finally:
[root@centos7 ~]# crontab -l
*/1 * * * * /usr/bin/cp /etc /data/`/usr/bin/date +\%Y-\%m-\%d` -av
2, the answer
[root@centos7 ~]# cp /root /data/rootdir -a