crontab woes

I have a script in a jail, /home/aisling/BackupJob.sh, that calls a job that backs up to an external server. After the backup is complete the server sends me an email with the details, which works great when I fire the script manually. The problem is when I add the job to crontab, After the scheduled time I run tail /var/log/cron and see no errors, but the backup does not happen. Below is the cron job and the results of the tail.

Thank you.

Code:
SHELL=/bin/sh
PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin
#
#minute hour mday month wday who command 3
#
44 08 * * * root /home/aisling/BackupJob.sh

Code:
Jul 24 08:44:00 syncrify /usr/sbin/cron[12337]: (operator) CMD (/usr/libexec/save-entropy)
Jul 24 08:44:00 syncrify /usr/sbin/cron[12338]: (root) CMD (root /home/aisling/BackupJob.sh)
Jul 24 08:45:00 syncrify /usr/sbin/cron[12370]: (root) CMD (/usr/libexec/atrun)
 
Yep, that would be my guess too :e

And I suggest using # crontab -e and leave the system's /etc/crontab alone. The reason is that /etc/crontab may get overwritten during an update. Whereas a user's (that includes the root user) crontab isn't.
 
Yes, that makes sense, thank you. I believe the issue lies in my use of JRE in the script:

Code:
java -Dsyncrify.custom.home=/root/.syncrify -jar /home/aisling/SyncrifyClient.jar -console tcdc-backup.syncrify

My next problem as a noob is how do I find the path of the Java JRE?
 
chellea said:
My next problem as a noob is how do I find the path of the Java JRE?

Code:
root@molly:~ # whereis -b java
java: /usr/local/bin/java
 
So, I ran the following as instructed;

Code:
syncrify# whereis -b java
java: /usr/local/bin/java

but got the same results... Below is my script;

Code:
#!/bin/sh
/usr/local/bin/java -Dsyncrify.custom.home=/root/.syncrify -jar /home/aisling/SyncrifyClient.jar -console tcdc-backup.syncrify

I am clearly still doing something wrong, any thought would be greatly appreciated.
 
It looks like the recommended cron method.

I would try following:
- see if any logs exist
- check related FreeNAS how-to (probably not too useful if everything works under an regular user)
- check the file rights (same as above, script runs under the root account)
- compare the PATH enviroment variable for your user and root. Put something like
Code:
printenv PATH > /home/user/cronpath.txt
at start of the failing script and then compare file content with $ printenv PATH as regular user
 
The results were identical.

printenv PATH
Code:
/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:/root/bin

Code:
#!/bin/sh
printenv PATH > /home/aisling/cronpath.txt /usr/local/bin/java -Dsyncrify.custom.home=/root/.syncrify -jar /home/aisling/SyncrifyClient.jar -conso
le tcdc-backup.syncrify

Result:

Code:
/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:/root/bin

I am running the script manually as root, and the cron job is set to run as root as well.

Thanks.
 
chellea said:
Below is my script;

Code:
#!/bin/sh
/usr/local/bin/java -Dsyncrify.custom.home=/root/.syncrify -jar /home/aisling/SyncrifyClient.jar -console tcdc-backup.syncrify

I am clearly still doing something wrong, any thought would be greatly appreciated.
You say that this script works as expected when you run it from the console. From which directory are you usually running this script, and even more importantly: have you ever tried to execute this script from another location?

Of course I'm not sure here, but I wonder if your Java program isn't using any external files or data (libraries for example), and therefore requires a specific environment to be in place.

For example; in their most basic form some Java programs need the classpath parameter to be set before you can execute them from another location. This is required so that the program knows where to look for any classes.

Although I doubt this is the case here (you're using a jar file after all which should contain everything required) it might be worth looking into.
 
ShelLuser said:
Although I doubt this is the case here (you're using a jar file after all which should contain everything required)

Good point. I have one java application, which has to be started from the application directory like $ java -jar lib/app.jar [params], otherwise it runs but silently fails to work. Only long digging in the embeded Tomcat logs hints me what is going wrong.

Also running the failing utility under truss(1) may show something like file not found errors etc.

So you can try this
Code:
#!/bin/sh
/path/to/truss -fa -o /where/to/store/output /usr/local/bin/java -Dsyncrify.custom.home=/root/.syncrify -jar /home/aisling/SyncrifyClient.jar -console tcdc-backup.syncrify

and of course try @ShelLuser's advice
Code:
#!/bin/sh
cd /home/aisling #or directory where it works manually
/usr/local/bin/java -Dsyncrify.custom.home=/root/.syncrify -jar /home/aisling/SyncrifyClient.jar -console tcdc-backup.syncrify
 
Last edited by a moderator:
Back
Top