Use of hdparm state in script works only manually and not by cron

Clash Royale CLAN TAG#URR8PPP up vote
0
down vote
favorite
I use the following if ... then test in an auto shutdown script which is started every 15 minutes by cron.
# Check if disk1 is currently spinning
if [ "$(hdparm -C /dev/sdb1 | grep -o "active/idle|standby")" = "active/i$
logit disk1 running, auto shutdown terminated
return 1
This works fine if I start the script manually with ./autoshutdown.sh. The disk state will be detected correctly.
But if cron is starting this script and the state is not detected the else statement is used.
Why this difference? And what do I need to change?
bash scripts cron hdparm
add a comment |Â
up vote
0
down vote
favorite
I use the following if ... then test in an auto shutdown script which is started every 15 minutes by cron.
# Check if disk1 is currently spinning
if [ "$(hdparm -C /dev/sdb1 | grep -o "active/idle|standby")" = "active/i$
logit disk1 running, auto shutdown terminated
return 1
This works fine if I start the script manually with ./autoshutdown.sh. The disk state will be detected correctly.
But if cron is starting this script and the state is not detected the else statement is used.
Why this difference? And what do I need to change?
bash scripts cron hdparm
1
Probabhly because your$PATHdiffers in cron jobs, and it cannot findhdparm. SPecify the whole path tohdparm, which you can find viatype -p hdparm.
â waltinator
Feb 10 at 16:08
I expanded my comment into an Answer - please Accept.
â waltinator
Feb 10 at 18:24
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I use the following if ... then test in an auto shutdown script which is started every 15 minutes by cron.
# Check if disk1 is currently spinning
if [ "$(hdparm -C /dev/sdb1 | grep -o "active/idle|standby")" = "active/i$
logit disk1 running, auto shutdown terminated
return 1
This works fine if I start the script manually with ./autoshutdown.sh. The disk state will be detected correctly.
But if cron is starting this script and the state is not detected the else statement is used.
Why this difference? And what do I need to change?
bash scripts cron hdparm
I use the following if ... then test in an auto shutdown script which is started every 15 minutes by cron.
# Check if disk1 is currently spinning
if [ "$(hdparm -C /dev/sdb1 | grep -o "active/idle|standby")" = "active/i$
logit disk1 running, auto shutdown terminated
return 1
This works fine if I start the script manually with ./autoshutdown.sh. The disk state will be detected correctly.
But if cron is starting this script and the state is not detected the else statement is used.
Why this difference? And what do I need to change?
bash scripts cron hdparm
bash scripts cron hdparm
edited Feb 10 at 16:14
Yufenyuy Veyeh Dider
879823
879823
asked Feb 10 at 16:03
MelBourbon
155
155
1
Probabhly because your$PATHdiffers in cron jobs, and it cannot findhdparm. SPecify the whole path tohdparm, which you can find viatype -p hdparm.
â waltinator
Feb 10 at 16:08
I expanded my comment into an Answer - please Accept.
â waltinator
Feb 10 at 18:24
add a comment |Â
1
Probabhly because your$PATHdiffers in cron jobs, and it cannot findhdparm. SPecify the whole path tohdparm, which you can find viatype -p hdparm.
â waltinator
Feb 10 at 16:08
I expanded my comment into an Answer - please Accept.
â waltinator
Feb 10 at 18:24
1
1
Probabhly because your
$PATH differs in cron jobs, and it cannot find hdparm. SPecify the whole path to hdparm, which you can find via type -p hdparm.â waltinator
Feb 10 at 16:08
Probabhly because your
$PATH differs in cron jobs, and it cannot find hdparm. SPecify the whole path to hdparm, which you can find via type -p hdparm.â waltinator
Feb 10 at 16:08
I expanded my comment into an Answer - please Accept.
â waltinator
Feb 10 at 18:24
I expanded my comment into an Answer - please Accept.
â waltinator
Feb 10 at 18:24
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
Probably because your $PATH differs in cron jobs, and it cannot find hdparm. Specify the whole path to hdparm, which you can find via type -p hdparm.
I also suggest running a cron job like:
env | sort >$HOME/cron.env
echo $PATH | tr ':' "n" >$HOME/cron.path
To see what your cron environment looks like. More generally, look at all your run environments.
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
Probably because your $PATH differs in cron jobs, and it cannot find hdparm. Specify the whole path to hdparm, which you can find via type -p hdparm.
I also suggest running a cron job like:
env | sort >$HOME/cron.env
echo $PATH | tr ':' "n" >$HOME/cron.path
To see what your cron environment looks like. More generally, look at all your run environments.
add a comment |Â
up vote
1
down vote
accepted
Probably because your $PATH differs in cron jobs, and it cannot find hdparm. Specify the whole path to hdparm, which you can find via type -p hdparm.
I also suggest running a cron job like:
env | sort >$HOME/cron.env
echo $PATH | tr ':' "n" >$HOME/cron.path
To see what your cron environment looks like. More generally, look at all your run environments.
add a comment |Â
up vote
1
down vote
accepted
up vote
1
down vote
accepted
Probably because your $PATH differs in cron jobs, and it cannot find hdparm. Specify the whole path to hdparm, which you can find via type -p hdparm.
I also suggest running a cron job like:
env | sort >$HOME/cron.env
echo $PATH | tr ':' "n" >$HOME/cron.path
To see what your cron environment looks like. More generally, look at all your run environments.
Probably because your $PATH differs in cron jobs, and it cannot find hdparm. Specify the whole path to hdparm, which you can find via type -p hdparm.
I also suggest running a cron job like:
env | sort >$HOME/cron.env
echo $PATH | tr ':' "n" >$HOME/cron.path
To see what your cron environment looks like. More generally, look at all your run environments.
answered Feb 10 at 18:23
waltinator
20.8k74168
20.8k74168
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1004887%2fuse-of-hdparm-state-in-script-works-only-manually-and-not-by-cron%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
1
Probabhly because your
$PATHdiffers in cron jobs, and it cannot findhdparm. SPecify the whole path tohdparm, which you can find viatype -p hdparm.â waltinator
Feb 10 at 16:08
I expanded my comment into an Answer - please Accept.
â waltinator
Feb 10 at 18:24