How to set crontab to shutdown rasberry shake

Hi.
We have a task to measure low frequency noise in different locations. What i have planned is to set Rasberryshake to shutdown after 120 hours. But i cant solve the correct expression in crontab.
I did put following expression in crontab:

          • root shutdown -h +10
            The system then refresh every minute the shutdown time incresing i 1 minute intervals.
            My goal is to plan a controlled shutdown after 120 hours (5 days) after reboot/startup.
            Can anyone help here?. Im not experinced in linux,
1 Like

Hello Luffe, and welcome back to the community!

You can do this in two ways:

  1. using a script that contains the shutdown command and then executing it 120 hours after booting the Shake; or
  2. doing everything from crontab.

I’ll show how the second method should work, and if you want, I can add the first too.

Open the crontab file for editing with the usual

sudo crontab -e

Clear all present lines (if they are not essential to your work), and add the following one:

@reboot /sbin/shutdown -c; /sbin/shutdown +7200

This line does the following when the Raspberry Pi boots or reboots:

/sbin/shutdown -c cancels any previously scheduled shutdowns while /sbin/shutdown +7200 schedules a shutdown 7200 minutes (which is 120 hours) from now.

Then save and exit the crontab editor with Ctrl+X, then Y to confirm, and finally Enter.

You can test this by changing the 7200 with 10 or even 2 minutes to check if everything works as you want.

A note: keep in mind that if your Shake is powered off unexpectedly (e.g., due to a power failure) and then turned on again, the 120-hour countdown will restart from the beginning when the instrument boots up again. This is because the script schedules the shutdown relative to the current time at each boot, without keeping track of any previous uptime duration.

HI. Stormchaser
Thanks for your help.
But I cant make it work yet? Its not shutting down.
I have added the commands that you tell me to. The only present lines in crontab is what is present from start. And the last line is added when saving by the system.
The content is as follow:

@daily /usr/local/bin/myShake
@hourly /usr/local/bin/clean-logs
@reboot /sbin/shutdown -c; /sbin/shutdown +10
30 22 * * 5 /usr/local/bin/rsh-sw-fetcher C >/dev/null 2>&1

Where is the catch ??
regards
Luffe

2 Likes

You are right, as I forgot to add a sudo in front of the crontab command, so that the shutdown after boot would be executed by the root user.

You will have to then open crontab with:

sudo crontab -e

and then add the shutdown line in there. I have adjusted my initial message accordingly.

OK. But it seem that im not logged in ad administrator, as the Sudo crontab -e command just respond with a, kinnd of “empty page”… I use the default logon on the RS.
I read that i need to create a administrator user, for security reasons.
Is that correct?, and if, how do i do that on RS.
Im sorry that im so helpless!
regards
Lasse

1 Like

No issue, don’t worry! I can guide you through the process.

To use a more familiar crontab editor in sudo, execute this after logging into the Shake:

sudo EDITOR=nano crontab -e

You will then get an empty file; this is OK. Copy and paste the following (after copying, a single right-click on the black screen should be enough):

@reboot /sbin/shutdown -c; /sbin/shutdown +7200

Then save and exit the crontab editor with Ctrl+X, then Y to confirm, and finally Enter.

To check that the crontab has been modified successfully, you can see its contents with:

sudo crontab -l

To test everything with a smaller amount of time, you can reopen the crontab in the same way as above, modify the minutes’ value, and then save/close it as usual. After you reboot, the Shake should remain on for the amount of time you set before turning off.

Succes. Thank you.
To learn a new language is not that easy, and im happy that you are patient.
I now understand a little bit more about how to acces, and the levels into root commands ao.
Thanks for your support.
a pleasure!
Lasse

2 Likes

Great to hear this!

You’re right; it’s always hard at first. But that’s why we are here. And learning step-by-step is the best way to do it.

No problem at all; you’re very welcome!