0

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?

2
  • 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, 2018 at 16:08
  • I expanded my comment into an Answer - please Accept.
    – waltinator
    Feb 10, 2018 at 18:24

1 Answer 1

3

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.