A
A
Alikhan Khartumov2018-05-25 18:41:58
Automation
Alikhan Khartumov, 2018-05-25 18:41:58

Why is the sh script not running?

Greetings! I can't understand why the sh script is not executed...
There is a script in crontab with parameters:

*/1 * * * * /root/astrachecker.sh > checkerlogs.log

The script itself:
nc -vz 127.0.0.1 8080
if [ $? -eq 0 ]; then
    echo OK
else
    echo FAIL
    perl pushmsg.pl
    /usr/bin/astra --relay -l ip -p 8080 --log /var/log/astra/astra.log
fi

There is nothing (empty) in the original checkerlogs.log file, although the script itself seems to be run via crontab.
Log torn from /var/log/syslog
May 25 18:32:01 d1 CRON[1443]: (root) CMD (/root/astrachecker.sh > checkerlogs.log)

What am I doing wrong? I would like to know your opinion on this matter. Thank you all in advance!

Answer the question

In order to leave comments, you need to log in

4 answer(s)
C
CityCat4, 2018-05-27
@GiaNT_05

Well, first.
Shebang is a must! For a long time already, all scripts without a shebang may well be executed in the wrong place, not in the right way, or not executed at all.
Second.
PATH at the beginning of the script is required . Do not rely on defaults, set somewhere by something - they may turn out to be completely different from what you think.
Third.
For safety net, each command needs to specify the path. That is, not "nc", but "/usr/bin/nc" (well, or where you have it)

A
AVKor, 2018-05-25
@AVKor

google://cron + path

J
jcmvbkbc, 2018-05-25
@jcmvbkbc

*/1 * * * * /root/astrachecker.sh >& checkerlogs.log

That errors too got to a broad gull.

R
Reshh4rd, 2018-05-26
@Reshh4rd

Problems with cron always rested on:
1) The need to write the full path to programs / scripts, because how else can the system understand what to run from where
2) PATH, try to write the full path of the pearl in PATH:
On the command line:
PATH=$PATH: /usr/bin/perl ##(this is just an example, I don't know where your perl is)
export PATH
PS
View the path where perl is located:
which perl
PS2:
And yes, does everything work correctly through the command line?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question