Linux 使用 crontab -l 搜索 cronjob
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14450866/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Search for a cronjob with crontab -l
提问by user0000001
I am trying to find a cronjob that was created to ensure that the script doesn't duplicate the same exact cronjob.
我试图找到一个创建的 cronjob,以确保脚本不会复制完全相同的 cronjob。
I've been trying to use something along these lines but haven't had much luck:
我一直在尝试使用这些方法,但运气不佳:
if ! crontab -l | xargs grep -l '/var/www/arix/update.php'; then
echo "Cronjob already exists"
else
echo "Cronjob doesn't exist"
fi
采纳答案by jim mcnamara
/var/spool/cron/crontabs
is the usual parent directory for crontab files. There are files there that have names of users - root is the root crontab, for example. There is a potential for every user on the system to have used crontab -e and created his/her own crontab.
/var/spool/cron/crontabs
是 crontab 文件的常用父目录。那里有一些文件有用户名——例如,root 是根 crontab。系统上的每个用户都有可能使用 crontab -e 并创建他/她自己的 crontab。
As root you can :
作为根用户,您可以:
cd /var/spool/cron/crontabs
grep 'search string' *
This command (as root) will tell you what user's crontab has the string. And if it exists.
这个命令(作为 root)会告诉你哪个用户的 crontab 有这个字符串。如果它存在。
You would do this if if you are not sure what crontabs things are in. crontab -l
only gives the stuff in YOUR crontab, the user who is currently logged in. If you are sure that is the best place to check:
如果您不确定 crontab 中crontab -l
的内容,您会这样做。 只提供您的 crontab 中的内容,即当前登录的用户。如果您确定这是检查的最佳位置:
crontab -l | grep -q 'search string' && echo 'entry exists' || echo 'entry does not exist'