Problem with cron job

llundberg

New Member
Joined
Jun 10, 2022
Messages
1
Reaction score
0
Credits
24
Hi, I am posting this in the Command Line forum, if this is incorrect, mods please move as required.
Also, I am a complete newbie so please be gentle and help me. I have no where else to turn.

I am trying to set up a cron job to run scheduled backups to a QNAP box. When I run the executable manually, it works perfect.


I have an Expect file (pmsbackup.exp) for the purpose of authentication (I have to do this because I need to shut down the app before backup so I need to enter a password automatically). This file spawns the actual script that does the backup (pmsbackup-external2.sh) and when I run the Expect file manually, the backup script works perfectly.

But not when I try and schedule it as a cron job.


I created a file jobinfo which has:

5 0 * * 3 /home/leif/pmsbackup.exp >/home/leif/mycron.log

By my calculations, the job should run 5 minutes after midnight on Wednesdays.



I then enter it by crontab jobinfo.



I can see it scheduled:

leif@HP-ProLiant-MicroServer:~$crontab -l

05 0 * * 3 /home/leif/pmsbackup.exp >/home/leif/mycron.log



But the job never runs. If I go grep CRON /var/log/syslog, I see:

Jun 8 00:05:01 HP-ProLiant-MicroServer CRON[109200]: (leif) CMD (/home/leif/pmsbackup.exp)



Plus:
sudo systemctl status cron



Jun 08 00:05:01 HP-ProLiant-MicroServer CRON[127581]: pam_unix(cron:session): session opened for user leif>

Jun 08 00:05:01 HP-ProLiant-MicroServer CRON[127581]: (CRON) info (No MTA installed, discarding output)

Jun 08 00:05:01 HP-ProLiant-MicroServer CRON[127581]: pam_unix(cron:session): session closed for user leif



So it looks like the cron job is scheduled to run.



This is in the file I have to see the results:

leif@HP-ProLiant-MicroServer:~$ catmycron.log

spawn pmsbackup-external2.sh


Please help.
 
Last edited:


Unless I'm missing something, the logs and the presense of the log file appear to me to indicate that job has run. I would check the date on mycron.log and see it it has the expected date and time. Plus you can always remove the log file so then you would know if the job has run and created it.

If the job is writing errors to stderr, you are not catching that output. To do that you would need to redirect file descriptor 2 (stderr) to file descriptor 1 (stdout).

05 0 * * 3 /home/leif/pmsbackup.exp >/home/leif/mycron.log 2>&1

You could approach this in steps. You could perhaps run the main job from a bash script, the bash script could do things like output the date, just so you know it's running (you could do that with expect too, but I feel bash is more flexible). You could setup a test job that runs more frequently, but does not actually do the backup, just so you can debug it, get it right.
 


Top