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.
-rw-r--r--. 1 myusername developers 169 May 17 09:01 build.sh

Why is it I can execute the build.sh script from the command line if it does not have execute permissions but when crontab tries to execute it, it fails?

share|improve this question
2  
how are you executing it from the command line ? –  Iain May 23 '12 at 8:05
1  
You can execute a script even if it does not have execute permission using sh build.sh or bash build.sh. –  Khaled May 23 '12 at 8:27
add comment

1 Answer

up vote 5 down vote accepted

You can't execute that from the command line, because it doesn't have execute permissions.

What you can do, is to source it from the command line,

. ./build.sh

which causes the current shell to execute the commands in the file as if they were being typed on the command line.

You can't do this from cron, so you'll need to give the script execute permissions (chmod 744 build.sh).

You can also 'run' scripts by executing a shell and passing the script to it, such as,

sh build.sh

This is because you're executing sh (which has the +x permission), and it is reading the file build.sh and running the commands as if they were typed on the command line, before exiting.

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.