当前位置: 移动技术网 > 科技>操作系统>Linux > crontab中的%

crontab中的%

2019年08月09日  | 移动技术网科技  | 我要评论

方梓媛,时代周刊中文版,阜新网

crontab中的%是换行的意思,在使用时需要使用\做转义。

-----------------

在用crontab执行一段定时任务时,想要把数据输出到一个日期命名的文件中

1 * * * * *  cd /home/data/youtubeapi && /bin/php /home/data/youtubeapi/channelsections.php  &> /home/data/youtubechanneldata/channel.2.`date +%y%m%d`

预期每天会产出

channel.2.20190807

channel.2.20190808

channel.2.20190809

这样的文件,但是命令并没有正常执行起来

 

我是通过 mail 命令和 cat /var/spool/mail/data 这两个命令去查看的问题,错误信息中有可以很清楚看到 %y%m%d 这样的日期格式信息丢失了

 

在网上找到两个相关的文章,说到了crontab中的%为换行的意思,所以做了转义,可以正常运行了。

# 不正确的写法
1 * * * * *  cd /home/data/youtubeapi && /bin/php /home/data/youtubeapi/channelsections.php  &> /home/data/youtubechanneldata/channel.2.`date +%y%m%d`

# 正确的处理方式,注意转义 %
1 * * * * *  cd /home/data/youtubeapi && /bin/php /home/data/youtubeapi/channelsections.php  &> /home/data/youtubechanneldata/channel.2.`date +\%y\%m\%d`

参考的文章:

1. 

2. linux crontab命令详解

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网