1

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.

8
  • 2
    Add an @reboot line in a crontab with sudo shutdown -h +‭6240‬ that will activate in 60*104 minutes from now.
    – Dougie
    Mar 6, 2020 at 15:01
  • Might need to give the full path to shutdown.
    – joan
    Mar 6, 2020 at 17:59
  • 2
    Thank you, Dougie and Joan, for the replies! It sounds like this is the line I need to add to cron: @reboot /sbin/shutdown -h +6240 Mar 6, 2020 at 19:05
  • An alternative to cron is the at command for one-time tasks that you want to run at a specific time. Running shutdown 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. Then at may not be a good option.
    – Kate
    Mar 6, 2020 at 20:26
  • 2
    You could use a systemd timer here too, but crontab is probably the simplest.
    – goldilocks
    Mar 6, 2020 at 21:05

1 Answer 1

2

Run shutdown command each 104h.

0 */104 * * * /sbin/shutdown  

It will run the command every 104h.

  1. When you turn it on, the counter is 0h.
  2. Wait for 104 hours.
  3. Then the counter gonna be 104h.
  4. 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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