D
D
DdarkX2017-10-25 08:34:43
Debian
DdarkX, 2017-10-25 08:34:43

Why is the script not running in cron?

Good to everyone
The problem is that when the network card is heavily loaded, it loses the link, restarting the
service netrorking restart service helps.
Actually, changing the card did not give much result, then I made a decision, for example, ping the gateway every 5 minutes and if there is no answer, then restart the service, for this I wrote a fairly simple script, and if you work it out manually, then everything is fine, but if you put the task in crontab, then in the logs it swears at the wrong command.
#!/bin/bash
IP=8.8.8.8
RES=0
ping -q -c 2 $IP > /dev/null && RES=1
if [ $RES = 0 ];
then
ifdown enp3s0
sleep 2
ifup enp3s0
fi
In the logs:
netw.sh: line 7: ifdown: command not found
netw.sh: line 9: ifup: command not found
It's not even about quotes or syntax, it just swears at commands. What is done wrong? Why is the script not working. ubuntu server system 16.04.
PS I wanted to add more time, but something doesn't work.
Thanks to everyone who replies.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Karabanov, 2017-10-25
@karabanov

Write the full path to the executable file. Or, at the beginning of the script, define the PATH variable in which specify the path to this executable file.

O
ololo pishpish, 2017-10-25
@ololopishpishrealne

Add to the beginning of the script:
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question