question

DeeJay1984-1892 avatar image
0 Votes"
DeeJay1984-1892 asked RobinHolt-3131 edited

Scheduled restart raspberry pi windows iot

Hi

What is the easiest way to auto restart a raspberry pi 3 once a week?

windows-iot-10core
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RobinHolt-3131 avatar image
1 Vote"
RobinHolt-3131 answered

Create a powershell script which schedules itself again in three weeks and then calls 'shutdown /r /t0'.

Your script could be something like:

$schdTime = [DateTime]::Now.AddDays(7)
$sts = $schdTime.ToString("MM/dd/yyyy")
$taskToRun = "powershell -command " + $Script:MyInvocation.MyCommand.Path
SchTasks.exe /Create /RU "SYSTEM" /SC ONCE /TN "Periodic-Restart" /TR $taskToRun /SD $sts /ST "00:00" /F

shutdown /r /t 0

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RobinHolt-3131 avatar image
2 Votes"
RobinHolt-3131 answered RobinHolt-3131 edited

After looking at the SchTasks.exe documentation here, it would be much cleaner to just

SchTasks /Create /TN "Periodic-Restart" /TN "shutdown /r /t 0" /sc weekly/mo 1 /st 00:00 /f


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

SandervandeVelde42 avatar image
0 Votes"
SandervandeVelde42 answered SandervandeVelde42 edited

Cron is a tool for configuring scheduled tasks on Unix systems.

How to schedule a job is explained here

So scheduling a reboot is possible too. I recommend wrapping the actual shutdown command in a shell script (with the right execution rights using 'chmod'). This way you are more flexible in what is executed (and you can add multiple commands which are executed in one go.)

Executing your script at 12:00AM on the first of every month looks like:

 0 0 1 * * /etc/yourscripts/rebooteachmonth.sh


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.