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

I have a crontab job setup. In the crontab file, I have a path to a text file. My text file has a wget command (which in turn, executes a PHP file). If the crontab file just has the path to the text file, will it automatically bash (execute) that text file? Or do I need to prefix the path to the text file with bash?

share|improve this question
    
You can try it out by copying the "command" portion of the line into a shell, and pressing return. If it says "Permission denied" or another error, then you'll need to check things as suggested by other answers. –  fredden Mar 4 '10 at 20:08

1 Answer 1

up vote 10 down vote accepted

If the file is executable (check if it has x in ls -l, if not, then use chmod to set the executable bit) and the first line contains #!/bin/bash then it will be interpreted in bash.

The other option is, as you suggest, to pass it as an argument to bash:

/bin/bash /path/to/your/file.sh
share|improve this answer
    
Thanks mate! I will take care of this now. –  StephenPAdams Mar 4 '10 at 22:21
    
So, my script should do the following: 1stline: #!/bin/bash 2ndline: wget insertweburl here Is that correct? –  StephenPAdams Mar 4 '10 at 22:23
1  
Correct. And use chmod +x <file> to set the executable bit. Also, you should probably use the full path to wget, since cronjobs usually run a "bare" environment where $PATH might not include the directory where the wget binary resides. –  Mikael S Mar 5 '10 at 4:44

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.