Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

For some reason my cronjob is not working:

4 20 * * * /home/ubuntu/db_backup/ 1 > /home/ubuntu/db_backup/cron_log.txt

And my bash script looks like this:

#! /bin/bash
mysqldump -h anotherhost -P 3306 -u usen -pmypass --all-databases > $1.sql
java -jar myJar.jar param1 $1.sql

So the jar file takes in 2 parameters, the first one i want always to be the same, the second one comes from the first bash parameter. Inside /var/spool/mail/ubuntu I see this error:

Unable to access jarfile myJar.jar

I set the crontab up under user: ubuntu

owner and group of the jar file is ubuntu and it has octal permissions of 700.

What am I doing wrong?

share|improve this question
up vote 3 down vote accepted

Try with full paths:

#! /bin/bash
mysqldump -h anotherhost -P 3306 -u usen -pmypass --all-databases > /path/$1.sql
java -jar /path/myJar.jar param1 /path/$1.sql
share|improve this answer
Thank you for the response, I will try this, do you think I could try full path for the jar file too? – Doug Molineux Apr 25 '11 at 20:21

You should use absolute paths! I think neither the jar-file nor the sql-file can be found...

#! /bin/bash
mysqldump -h anotherhost -P 3306 -u usen -pmypass --all-databases > $SQLFILE
java -jar /path/to/myJar.jar param1 $SQLFILE
share|improve this answer
Yep it works, I'm afraid I'll have to accept hmontoliu's answer since it was a bit quicker +1 tho cheers! – Doug Molineux Apr 25 '11 at 20:26

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.