This may not belong in the issue queue for Drush, but I can't find my answer on drupal or google.

I have created a .sh script file to run on cron once a week to clear my sites cache, update all drupal modules, backup the server files, and backup the database.

The problem is this:
sh: line 4: drush: command not found
sh: line 5: drush: command not found

That happens only if I run an .sh file. If I put the commands straight in to terminal, they run great. Any ideas why this could be happening? Any additional information you need before you can help?


msonnabaum’s picture

The drush executable isn't available in cron's $PATH.

Just specify the full path like so:

*/15 * * * *  /usr/local/bin/drush cron
Branndon’s picture

Thanks msonnabaum. I understand that is a cron command you're putting there, but I am new to bash, in fact I only learned it for Drush :)

Let me clear this up:
*/15 * * * * /usr/local/bin/drush cron
means this?
run every 15 minutes /path/to/my/drush/location

Is that what you spelled out? Thanks.

edit just tried it a few times and a few settings

[ps9318]$ ~/drush ~/.scripts/
-bash: /home/branndon/drush: is a directory
[ps9318]$ bash ~/drush ~/.scripts/
/home/branndon/drush: /home/branndon/drush: is a directory
[ps9318]$ sh ~/drush ~/.scripts/
/home/branndon/drush: /home/branndon/drush: is a directory
[ps9318]$ sh home/branndon/drush ~/.scripts/
sh: home/branndon/drush: No such file or directory

Didn't work from command line.

msonnabaum’s picture

Sorry, I misspoke before, but the general idea was there.

Since you're putting drush in a shell script, that's where you need to specify the full path to drush, so you'll want to do something like this in your .sh file:


$DRUSH cron
$DRUSH updb -y

I'm not really sure what you're trying to do in your examples there…

Branndon’s picture

Here is my bash script



$DRUSH -r ~/$sitename cc all

and here is the resulting output. line 6: /home/branndon/drush/drush: Permission denied

msonnabaum’s picture

Status: Active » Fixed

Well, we're in bash territory now, so I'll give you another tip here, but you might want to google for some bash help if you're still having trouble.

You'll need to also specify the full path to your root argument. I'd guess that "" should be something like "/var/www/" or "/var/www/drupal/sites/". If your site's root is actually at ~/, that should work as long as the user who's running that script is the same user who's home directory that's in (i.e. /home/brandon/ Your permissions error at the end there suggests maybe that's not the case.

Keep in mind, there's nothing in a bash script that won't work on the command line, so you can test all of this there before you put it in the script. Once its there, pay attention to relative paths, what's in the $PATH variable, and what user is running the script.

Feel free to reopen if you're having drush specific issues.

Branndon’s picture

Priority: Normal » Minor

Thanks for the help. I am still having bash issues, but thanks for your help, you got me pointed in the right directions, I will search google for the bash fixes.

stuwat’s picture

Any luck? I'm having the same issues here.

greg.1.anderson’s picture

Try one of the result pages from this search. Maybe add the name of your distro to be more specific.

stuwat’s picture

Thanks for the help on this; I now more fully understand the importance of paths.

I have the paths issue sorted out but the problem is really with permissions. I have solved the problem by changing the permissions on drush from 644 to 744, so that it is now executable, however I don't really understand why this should be necessary, because Drush works fine from the command line without this. I am forever a newbie and will be grateful if anyone could educate me on why this should be the case.

greg.1.anderson’s picture

Try man bash and man chmod.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

grip media’s picture

Version: » 7.x-5.9
Issue summary: View changes

I struggled with this for about 3 hours... this thread ultimately helped me. But here is what I had to do:

This is for CENTOS and a cron job from CPANEL.

1) Created a .sh file and it contained:

cd /home/*YOURACCOUNTNAME*/public_html
$DRUSH safe-cache-form-clear

2) The file is located in my public_html directory so that Drush can find the drupal installation.

3) The cron job command is for Cpanel:

*/5 * * * * /home/dev1tfff/public_html/ > logfile 2>&1


  • This runs the safe cache clear command for Drush, every 5 minutes.
  • I had to set the permissions of drush binary to 755 to get it to work. I am not certain of the security implications yet.
  • The logfile 2>&1 command writes a log inside your directory and it is invaluable for debugging.