Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 12-02-2015, 12:24 PM   #1
LQ Newbie
Registered: Dec 2015
Posts: 1

Rep: Reputation: Disabled
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
Old 12-02-2015, 05:12 PM   #2
Senior Member
Registered: Nov 2013
Location: Tokyo
Distribution: Redhat/Centos, Ubuntu, Raspbian, Fedora, Alpine, Cirros, OpenSuse/SLES
Posts: 3,279

Rep: Reputation: 854Reputation: 854Reputation: 854Reputation: 854Reputation: 854Reputation: 854Reputation: 854
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.
1 members found this post helpful.
Old 12-02-2015, 05:14 PM   #3
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.10, Centos 7.5
Posts: 17,655

Rep: Reputation: 2484Reputation: 2484Reputation: 2484Reputation: 2484Reputation: 2484Reputation: 2484Reputation: 2484Reputation: 2484Reputation: 2484Reputation: 2484Reputation: 2484
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
1 members found this post helpful.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Strange cron job time setting tamtam Linux - Server 5 12-29-2014 03:27 PM
Having trouble setting an environment variable with a cron job PaulB0 Linux - Newbie 5 06-23-2012 02:06 AM
problem in cron job setting gauravdream Linux - General 1 02-23-2004 12:08 AM
Selfhost Domain Service (Setting up a cron job) ASP Linux - Newbie 3 12-02-2003 12:49 AM
need help setting up a cron job !! J.I.L. Linux - Software 1 10-19-2003 08:54 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:05 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration