# Problem to run script auto from crontab.



## gordone (May 13, 2013)

Hello,

I have made an rsync script: http://temp.dynamitt.net/div/rsync.sh.txt

The crontab line looks like this:

```
0 2 * * * /root/scripts/rsync.sh
```

But the script will not start or something goes wrong?

When I run the command manually `/root/scripts/rsync.sh`, it starts and runs fine.

Thank you for feedback and help.


----------



## ondra_knezour (May 13, 2013)

Use full paths.


----------



## freebuser (May 13, 2013)

You can check the error in the log file /var/log/cron(?)


----------



## gordone (May 13, 2013)

Full path? I think I have full path?

I can see this in the log:

```
May 13 02:00:00 dynamitt /usr/sbin/cron[1437]: (root) CMD (/root/scripts/rsync.sh)
```


----------



## SirDice (May 13, 2013)

@ondra_knezour meant using full paths to commands inside the script. So instead of using find and assuming the PATH is correct you should use /usr/bin/find (it's just an example but you get the idea).

Keep in mind that scripts run from cron(8) have a very limited PATH.


----------



## chatwizrd (May 13, 2013)

I would just add a MAILTO line above the job you are running to get the full output emailed to you. For example like the following. Then if there is a problem with it running you can get an email with the details:


```
MAILTO="your@email.com"

0 2 * * * /root/scripts/rsync.sh
```


----------



## phoenix (May 13, 2013)

Please read The Interrupted Unix FAQ.


----------



## gordone (May 13, 2013)

I got it now, you're talking about the rsync full path. *S*o cron is reading the line another way than a command in the shell. I will edit the script and report back


----------



## pkubaj (May 13, 2013)

But the PATH is specified in /etc/crontab, so it can be edited, can't it?


----------



## DutchDaemon (May 14, 2013)

System's crontab is best left alone. If you need to run a job as root, use root's own crontab (`crontab -e` as the root user).


----------



## gordone (May 14, 2013)

ondra_knezour said:
			
		

> Use full paths.



You were correct, it is working perfect now. 

Thank you all!


----------



## marwis (May 14, 2013)

DutchDaemon said:
			
		

> System's crontab is best left alone. If you need to run a job as root, use root's own crontab (`crontab -e` as the root user).



Why?  Thanks.


----------



## kpa (May 14, 2013)

Because the system crontab(5) might get changed by an OS upgrade and if you use root's crontab(5) for custom stuff you have one less file to worry about when you run mergemaster(8) (with freebsd-update(8) the procedure might be a bit different but the end results are the same).


----------

