Running script with crontab at boot

Hi everyone! Hoping someone can help with this. It’s an extremely simple crontab execution , but doesn’t run under UCS.

I have a command to set sleep and idle time parameters on a second HDD. I’ve tried adding this to crontab logged into the root user via “crontab -e” , the line is @reboot hdparm -B127 -S120 /dev/disk/by-id/ata-ST4000LM024-2AN17V_WCK1P3C7

When that didn’t work, I also tried adding it in the form of a script under /etc/cron.hourly and also added it to the crontab just to see if either or both would work…

crontab line is: @reboot echo /etc/cron.hourly/DiskStandby.sh | at now + 2 minutes

Unfortunately, it doesn’t run at boot and doesn’t run hourly. Yet the script runs fine manually and the command runs fine in terminal separately.

I’m not hard set on using cron jobs… if there’s another way in the UCS, I’m open to other options.

Would still love to know if I had something wrong in the crontab setup, but I had luck with the deprecated rc.local service. If this helps anyone

  1. Create file rc-local.service in /etc/systemd/system with the following content:

[Unit]
Description=/etc/rc.local
ConditionPathExists=/etc/rc.local

[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99

[Install]
WantedBy=multi-user.target

  1. Create file rc.local in /etc with the following content:

#!/bin/sh -e
hdparm -B127 -S120 /dev/disk/by-id/ata-ST4000LM024-2AN17V_WCK1P3C7

exit 0

  1. Add execute permissions to rc.local and enable the script:

chmod +x /etc/rc.local
systemctl enable rc-local
systemctl start rc-local.service

  1. Edit rc.local and add your content

Note: you can check the status (or errors) using the command
systemctl status rc-local.service

Note: a little side effect is the disk I intended to sleep after 10min of idle time now starts in sleep at boot, when the service starts. Not a bad side effect, it’s actually fine. It wakes on data requests and goes back to sleep after 10min of idle. so, I’m happy with it :slight_smile:

1 Like

Just for completeness, did the script DiskStandby.sh contain a shebang for the shell? ("#!/bin/bash") or did you define SHELL in the crontab? Is the script executable? Did you try with the full path to “at” or did you define PATH in the crontab?

Yes, the script contained a shebang for the shell. I found out it’s more of a drive specific / firmware issue. I’m using a Seagate 4TB 2.5" as an extra backup. Just found out that it doesn’t like being set at anything lower than -B254. Oddly the idle timer set via “-S120” works fine when Power management is set at “-B254”.