-   Linux - Newbie (
-   -   Help with setting cron job with if condition (

dragon777 12-02-2015 12:24 PM

Help with setting cron job with if condition
Hi guys,
I own a vu+ solo se v2 box and the external usb hdd spins down automatically every 5 minutes.
To fix this I used successfully this cron job:
*/4 * * * * touch /media/hdd/keepalive.log
The problem is that I would like this cron job to NOT work when the vu+ BOX is in standby so the hdd can have a rest.
For this purpose I had some help but something is missing I guess because it does not work.
Here is what I tried:
if (wget -O - -q http://localhost/web/powerstate|grep -i false) then
touch /media/hdd/keepalive.log

-crontab file to:
*/4 * * * * /root/ 2>&1 > /dev/null

- and
wget -O - http://localhost/web/powerstate


Any ideas, please??? and remember that I have no clue about all this, so be patient

berndbausch 12-02-2015 05:12 PM

The parentheses around the if condition are unlikely to work. Remove them.
Inside cron, you have a very limited environment, so that you need to use absolute pathnames for commands like wget.

chrism01 12-02-2015 05:14 PM

Something like

wget -O - -q http://localhost/web/powerstate|grep -i false >/dev/null 2>&1
if [[ $? -eq 0 ]]      # check results code of last cmd in pipeline
    touch /media/hdd/keepalive.log

NB: I don't have the HW to test this....

Also, as above, use full paths for cmds in cron jobs

All times are GMT -5. The time now is 02:02 AM.