Arc*_*ing 0 cron io-redirection here-document
是否可以crontab
使用 heredocument打印?
我尝试了这些但失败了:
cat <<-"CRONTAB" > crontab
0 0 * * * cat /dev/null > /var/mail/root
0 1 * * 0 certbot renew -q
CRONTAB
Run Code Online (Sandbox Code Playgroud)
和:
bash <<-"CRONTAB" > crontab
0 0 * * * cat /dev/null > /var/mail/root
0 1 * * 0 certbot renew -q
CRONTAB
Run Code Online (Sandbox Code Playgroud)
另一方面,这不是此处的文档,而是有效的:
# CRONTAB
echo "
0 0 * * * cat /dev/null > /var/mail/root
0 1 * * 0 certbot renew -q
" | crontab
Run Code Online (Sandbox Code Playgroud)
因此,我想知道是否可以使用 heredocument。
正如其他人指出的那样,crontab
是一个命令,因此您需要做的就是将其提供给 heredoc:
crontab <<-"CRONTAB"
Run Code Online (Sandbox Code Playgroud)
但正如前面已经提到的,这是一个可怕的很多容易被操纵的文件管理cron作业/etc/cron.daily
,/etc/cron.d
等等。