By kawa
Hi Digital Ocean forum!
I have a script running every minute with crontab. The script looks like this:
#!/bin/bash
UP=$(pgrep node | wc -l);
dt=`date '+%d/%m/%Y_%H:%M:%S'`;
if [ "$UP" -lt 1 ];
then
pushserver -c /var/www/config.json
echo"$dt Node is down.";
else
echo "$dt Node is all good.";
fi
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 scriptname.sh
So, i’ve put this into my crontab:
* * * * * sh /home/pushCheck.sh& >> /home/pushCheck.log
* * * * * echo ‘Run this command every minute’ >> /home/crontab.log
* * * * * cd /home/ && sh pushCheck.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 pushCheck.sh too, but it doesn’t seem to work and I’m out of ideas.
Hope someone can help me out here :-)
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Just for future reference, it’s often better to use
#!/usr/bin/env bash
Over
#!/bin/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.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.