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.

Ingo
43k20 gold badges87 silver badges207 bronze badges
asked Mar 6, 2020 at 14:32
8
  • 2
    Add an @reboot line in a crontab with sudo shutdown -h +‭6240‬ that will activate in 60*104 minutes from now. Commented Mar 6, 2020 at 15:01
  • Might need to give the full path to shutdown. Commented 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 Commented 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. Commented Mar 6, 2020 at 20:26
  • 2
    You could use a systemd timer here too, but crontab is probably the simplest. Commented 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.

answered Mar 9, 2020 at 16:39

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.