Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am using duplicity to create nightly backups of my server over FTP. I wrote a script that does both a local and remote backup and logs the output results. When I run this script as the root user, it executes just fine. However when I set it as a cron job and run it, the script executes but the ftp portion fails. Shortly after I get an error message saying "ncftpls - command not found, please install ncftp 3.1.9 or later" but it is installed! Is there some reason that cron job would not be able to find a command that exists on the machine? Does it have it's own PATH or something like that?

Any help is greatly appreciated,

Mike

share|improve this question
    
Is it root's cronttab? –  Dave Holland Sep 14 '10 at 2:24
    
Yes, it is root's script, root's crontab, and I compiled and installed ncftp as root. –  Mike C Sep 14 '10 at 2:25
    
Can you show the line from crontab? –  Dave Holland Sep 14 '10 at 2:45
add comment

2 Answers

up vote 4 down vote accepted

Are you using absolute paths? Cron jobs won't open an interactive shell, so bash init scripts (bashrc, bash_profile, etc.) that usually set the PATH may not be run--and if they are, they'll be using root's, not yours. If you're unsure about where the command is, you can use which <command> to find out the absolute path.

When dealing with cron scripts, the general rule of thumb is, you either (a) want to set the PATH or (b) use absolute paths.

Good luck!

share|improve this answer
add comment

You should either give the full path to the command you want to run or you should define PATH in the cron job.

Example of running the foobar command without giving a path:

PATH=/sbin:/bin:/usr/sbin:/usr/bin
01 * * * * root foobar

With a path:

01 * * * * root /usr/bin/foobar

You can also specify things like which shell to run the jobs in by setting SHELL like: SHELL=/bin/bash for bash. See man 5 crontab for some more examples.

share|improve this answer
add comment

Your Answer

 
discard

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.