Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Search for a cronjob with crontab -l

Tags:

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 
like image 373
user0000001 Avatar asked Jan 22 '13 02:01

user0000001


People also ask

How do I find cron jobs?

You can use the cat, crontab and other Linux commands to view, list and display all cron jobs. The cron service searches its spool area (usually /var/spool/cron/crontabs) for crontab files (which are named after user accounts); crontabs found are loaded into memory.

What is the use of * * * * * In cron?

It is a wildcard for every part of the cron schedule expression. So * * * * * means every minute of every hour of every day of every month and every day of the week .

How do I see cron output?

On CentOS, my cron output gets "mailed" to /var/spool/mail. See it by running less $MAIL if you want to see cron output for the current user or less /var/spool/mail/root if you want to see cron output for commands running as root.


1 Answers

/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' 
like image 194
jim mcnamara Avatar answered Sep 20 '22 09:09

jim mcnamara