I have a project where I'd like to plug in (to power) the Raspberry Pi, have it start running a Python program to write data to a USB stick, and shut itself down after 104 hours. It will NOT be connected to a network.
For example. I plug in the Pi at 9:00 AM on Monday morning, it runs all week, and shuts itself down at 5:00 PM on Friday.
I thought about doing this with cron as described in this entry... Automatic shutdown of Pi based on timer ...but given that the Pi will not be connected to a network, I'm not sure if this will work.
Any ideas on how to handle the automatic shutting down? Thanks!
Note: I am using a Raspberry Pi 3B+ running Rasbian Buster.
1 Answer 1
Run shutdown
command each 104h
.
0 */104 * * * /sbin/shutdown
It will run the command every 104h
.
- When you turn it on, the counter is
0h
. - Wait for 104 hours.
- Then the counter gonna be
104h
. - Finally, it will
shutdown
the raspberry pi.
After you turns the raspberry pi on, the counter would be 0h
. Again will follow step 1 to 4.
Explore related questions
See similar questions with these tags.
@reboot
line in a crontab withsudo shutdown -h +6240
that will activate in 60*104 minutes from now.@reboot /sbin/shutdown -h +6240
cron
is theat command
for one-time tasks that you want to run at a specific time. Runningshutdown
with a delay is a good answer for your purpose though. But I am wondering if your PI has a realtime clock backup up by battery since it will not be able to do network time synchronization. Thenat
may not be a good option.