0

I have looked for an answer everywhere I can think of and either I'm looking in the wrong places or no one is attempting to enter cron jobs from scrips.

I have two cron jobs (below) that I am wanting to check or setup and run from another main bash script. the main bash script does the cron job entry ( no manual entry ). here they are (adjusted the paths for easier viewing):

if ! crontab -l | grep "@reboot /home/john/this_script.sh > /home/john/this_script_log.txt 2>&1"; then
  (crontab -l ; echo "@reboot /home/john/this_script.sh > /home/john/this_script_log.txt 2>&1") | crontab -

and

if ! crontab -l | grep "/home/john/that_script.sh > /home/john/that_script_log.txt 2>&1"; then
  (crontab -l ; echo "* * * * * /home/john/that_script.sh > /home/john/that_script_log.txt 2>&1") | crontab -
fi

the permission are set and have been tested. so they both run.

I don't want to use crontab -e to adjust or enter any of the above cron jobs (thus the pipe to crontab -). as far as I know the above if statements check to see if the cron job is already there and if it is not, it enters it.

the challenge is I mistakenly entered the wrong path on one of them. after discovering the mistake, I attempted to edit it.

I used crontab -e and couldn't find it.

crontab -l and it doesn't show up.

does anyone know how to find and edit any of the above script entered (crontab -) crontabs?

thank you

trstone
  • 13
  • 4
  • cron jobs are stored in `/var/spool/cron/crontabs`. But if you don't see what you want with `crontab -l` then looking at the files won't help. – Barmar Feb 13 '20 at 19:40
  • 2
    Is the script running with a different user? – abhishek phukan Feb 13 '20 at 20:27
  • @Barmar and abhishek phukan thank you for the replys. checked both user john and root @ /var/spool/cron/crontabs , /etc/cron.d/ , /etc/cron.daily/ , /etc/cron.hourly/ , /etc/cron.monthly/ , and /etc/cron.weekly/ . makes me want to look for alternatives to cron cause I really need the main bash script to set this up. – trstone Feb 13 '20 at 23:56
  • @abhishek phukan answered above. system wouldn't let me @ more than one person – trstone Feb 13 '20 at 23:57
  • found a potential answer -> https://stackoverflow.com/a/17975418/8157967 . still doesn't give a solution for editing bash script entered crontabs – trstone Feb 14 '20 at 00:35
  • I don't understand the question here. You edit crontab the same way whether it was created interactively or through a script. – Barmar Feb 14 '20 at 00:39
  • The `crontab` command doesn't do anything related to the crontabs in `/etc`. – Barmar Feb 14 '20 at 00:40
  • If you can't find the cron job with `crontab -l`, you didn't really create it when you thought you did. – Barmar Feb 14 '20 at 00:42
  • @Barmar when I added it earlier, I didn't receive any errors. so I assumed it entered. I should have checked for it then. I assumed wrong. it did not enter in and didn't show. please forgive me for wasting your time. I re-entered the above and it worked. don't know why it didn't before. Thank you and everyone who attempted to help. have a great day – trstone Feb 14 '20 at 01:04
  • The code looks good but if you run this with `sudo` then it's in root's crontabs. – Ivan Feb 14 '20 at 11:10

0 Answers0