Why is cron not running my sh script?

Hi Digital Ocean forum!

I have a script running every minute with crontab. The script looks like this:

UP=$(pgrep node | wc -l);
dt=`date '+%d/%m/%Y_%H:%M:%S'`;
if [ "$UP" -lt 1 ];
        pushserver -c /var/www/config.json
        echo"$dt Node is down.";
        echo "$dt Node is all good.";

So I’m checking if node is running, if it is, it’s all good, if not it starts it. It works when I fire the script by running sh

So, i’ve put this into my crontab:

* * * * * sh /home/ >> /home/pushCheck.log
* * * * * echo ‘Run this command every minute’ >> /home/crontab.log
* * * * * cd /home/ && sh>>pushCheck.log

It’s not really working, but the echo to the logfile, is being logged. So crontab should be up and running. I’ve tried the * * * * * sh too, but it doesn’t seem to work and I’m out of ideas.

Hope someone can help me out here :-)

  • Kasper

I just want to say I got it fixed. The solution was to add the following in my script:


Thanks for your help ryanpq, that was much appreciated :-)

@heathweaver It has something to do with the path that cron uses can be different than the path that bash uses as far as I know. There is a more detailed explanation here:

@kawa Just out of curiosity, why was it necessary to add this?

Could it possibly be that the environment path is wrong?

I’ve marked it executable chmod +x, but i’m sure it was like that before. I’ve also removed the file one level up to the root, but it’s still not working unfortunately. Also thank you very much for the quick response :)

I’ve got a couple questions about your configuration:

1.) Is marked as executable? chmod +x

2.) is /home/ the correct directory? Normally the only thing that should be in /home is the individual user’s home directories.

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.


Your solutions also work for me so thank you very much.


Just for future reference, it’s often better to use

#!/usr/bin/env bash



This is for portability since paths often vary from one OS to another depending on how the package maintainer has it setup at installation. Debian & Ubuntu will likely always use the same paths, much like how CentOS and Fedora most likely will, though when you bounce from one OS to an entirely different one, that’s when the differences make a difference :-).

IIRC, you should be able to use it in a cronjob script as well.