搜索用的crontab -l一个cronjob [英] Search for a cronjob with crontab -l

查看:276
本文介绍了搜索用的crontab -l一个cronjob的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好了,所以我想找到的建立是为了确保脚本不重复完全相同的cronjob一个cronjob。

我一直在尝试使用这些方针的东西,但没有多少运气:

 如果! crontab的-l | xargs的grep的-l/var/www/arix/update.php';然后
  回声的cronjob已经存在
其他
  回声的cronjob不存在
科幻


解决方案

的/ var /线轴/ cron的/ crontab中是crontab文件通常的父目录。有文件那里有用户的名字 - 根是根crontab,例如。还有就是为系统中的每个用户的潜力已经用crontab -e来创造他/她自己的crontab。

作为根用户,您可以:

  CD的/ var /线轴/ cron的/ crontabs中
grep的搜索字符串*

此命令(作为root)会告诉你用户的crontab有串。而如果它的存在。

您会如果,如果你不知道什么东西的crontab都在这样做。的crontab -l <​​/ code>只给了东西在你的crontab,谁是当前登录的用户如果你确信是检查最好的地方:

 的crontab -l | grep的-q'搜索字符串'和;&安培;回声条目存在'||回声项不存在

Okay, so I am trying to find a cronjob that was created to ensure that the script doesn't duplicate the same exact 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

解决方案

/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.

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.

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 -l | grep -q 'search string'  && echo 'entry exists' || echo 'entry does not exist'

这篇关于搜索用的crontab -l一个cronjob的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆