将条目插入/ etc/crontab的首选方法是什么,除非它存在,最好使用单行?
这是我希望放入/ etc/crontab的示例条目,除非它已存在于那里.
*/1 * * * * some_user python /mount/share/script.py
Run Code Online (Sandbox Code Playgroud)
我在CentOS 6.6上,到目前为止,我有这个:
if grep "*/1 * * * * some_user python /mount/share/script.py" /etc/crontab; then echo "Entry already in crontab"; else echo "*/1 * * * * some_user python /mount/share/script.py" >> /etc/crontab; fi
Run Code Online (Sandbox Code Playgroud)
arc*_*444 16
你可以这样做:
grep 'some_user python /mount/share/script.py' /etc/crontab || echo '*/1 * * * * some_user python /mount/share/script.py' >> /etc/crontab
Run Code Online (Sandbox Code Playgroud)
如果该行不存在,grep将返回1,因此该权利的右侧||将被执行.