将条目插入 /etc/crontab 的首选方法是什么(除非它存在),最好使用单行?
这是我希望放入 /etc/crontab 中的示例条目,除非它已经存在于其中。
*/1 * * * * some_user python /mount/share/script.py
我使用的是 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
你可以这样做:
grep 'some_user python /mount/share/script.py' /etc/crontab || echo '*/1 * * * * some_user python /mount/share/script.py' >> /etc/crontab
如果该行不存在,grep
将返回1
,所以 or 的右侧||
将被执行。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)