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
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.
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 .
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.
/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'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With