Auto-Shutdown PROXMOX Host Cronjob Not Working

Windows7ge

Active Member
Sep 12, 2019
35
1
28
29
Most simple solution I could think of was crontab. So, as root I created a cronjob entry:
Code:
30 15 * * * /root/shutdown.sh
Then created /root/shutdown.sh with simply:
Code:
shutdown now

When 4:30PM rolls around, nothing happens...I've checked the system time with the date command and verified the time of day. Is something wrong with my syntax? Am I missing an argument? I used chmod +x shutdown.sh so it's executable but again 4:30PM rolls around and nothing happens.

Any ideas? Should I try something else?
 
cron does not load user profile settings, such as PATH
You should always specify absolute path to binaries: /usr/sbin/shutdown


Blockbridge : Ultra low latency all-NVME shared storage for Proxmox - https://www.blockbridge.com/proxmox
There's an actual file called shutdown? interesting. So I should try:

Code:
30 15 * * * /usr/sbin/shutdown

I won't have a chance to test it until Tuesday so I'll get back to you on that.
 
Usually, you provide a method (halt or restart) and a time to the shutdown command. Try /usr/sbin/shutdown -h now for example.
Ah, right, it's basically the absolute file path to the command. It still needs it's arguments. I guess the last question I have for now then would be is crontab hours 0-23 or 1-24? Cause looking up crontab online suggests 0-23 but the commented section of crontab -e on proxmox suggests 1-24...
 
Ah, right, it's basically the absolute file path to the command. It still needs it's arguments. I guess the last question I have for now then would be is crontab hours 0-23 or 1-24? Cause looking up crontab online suggests 0-23 but the commented section of crontab -e on proxmox suggests 1-24...
It is 0-23, I don't know where you got a different impression.
Code:
 The time and date fields are:

              field          allowed values
              -----          --------------
              minute         0-59
              hour           0-23
              day of month   1-31
              month          1-12 (or names, see below)
              day of week    0-7 (0 or 7 is Sunday, or use names)
PS: You could just have tried it...
 
Last edited:
It is 0-23, I don't know where you got a different impression.

PS: You could just have tried it...
PROXMOX provided example inside the crontab editor:
Code:
...
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
...
0 5 would suggest 6AM not 5AM unless it was 1 - 24...

And I did test both (30 16, 30 15)...with the script absolute file path which seems to be why it wasn't running. That's what led me here. Wasn't sure where the problem was with this distribution. Running scripts like this through cron works fine on others. Thought I'd ask about the hours while I was here.
 
PROXMOX provided example inside the crontab editor:
Code:
...
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
...
0 5 would suggest 6AM not 5AM unless it was 1 - 24...
To me, it reads as 5:00. And the comment states 5 AM (05:00). I don't see why this implies 1-24, but I agree that it might not be as clear as man crontab.
And I did test both (30 16, 30 15)...with the script absolute file path which seems to be why it wasn't running. That's what led me here. Wasn't sure where the problem was with this distribution. Running scripts like this through cron works fine on others. Thought I'd ask about the hours while I was here.
Fair enough.
 
To me, it reads as 5:00. And the comment states 5 AM (05:00). I don't see why this implies 1-24, but I agree that it might not be as clear as man crontab.
Oh wait...
0 0 = Midnight
0 1 = 1AM
0 2 = 2AM
etc...
0 23 would be 11PM

I'm an idiot I do want 30 16 for 4:30PM not 30 15. Well in either case what I wanted crontab to do wasn't a compatible request...

Will follow up Tuesday evening when I have access to the server again. It doesn't get used every day so this is for when my forgetful butt doesn't remember to turn it off before leaving. It ran overnight one day, onsite IT guy's idea of taking care of it was ripping the AC cable out the back...I question his qualifications...
 
Oh wait...
0 0 = Midnight
0 1 = 1AM
0 2 = 2AM
etc...
0 23 would be 11PM
Indeed
I'm an idiot I do want 30 16 for 4:30PM not 30 15. Well in either case what I wanted crontab to do wasn't a compatible request...
Well, I don't want to complicate matters but 30 16 * * * to me is the same as 4:30 PM. (the minutes equals 30 and the hour equals 16 and 16 mod 12 equals 4).
Half four in some countries means half past four (16:30 or 04:30) but in other countries it means half to four (15:30 or 03:30). Countries,timezones and languages can get complicated quickly. Use dpkg-reconfigure tzdata to change your timezone.
Will follow up Tuesday evening when I have access to the server again. It doesn't get used every day so this is for when my forgetful butt doesn't remember to turn it off before leaving. It ran overnight one day, onsite IT guy's idea of taking care of it was ripping the AC cable out the back...I question his qualifications...
Electricity is expensive and every computer has its buttons in different places. Or maybe he has ambitions to becoming a QA tester and your system just got tested for power failure ;-)
 
  • Like
Reactions: Windows7ge
Use dpkg-reconfigure tzdata to change your timezone.
That's a whole other confusing thing I opted to cheat instead of confront. It seems without Internet access if I set the BIOS clock to the current time PROXMOX will set it to UTC time which for me (EST) is supposed to be +4 or 5hrs? So if the BIOS says 10AM PROXMOX says 6AM EDT...

I'd have to research the difference between EDT and EST but EDT doesn't sound like UTC so I don't know why it's taking the BIOS EST and subtracting 4 fours.

So I "cheated" by just advancing the BIOS clock 4 hours. Not perfect but it works.

Electricity is expensive and every computer has its buttons in different places. Or maybe he has ambitions to becoming a QA tester and your system just got tested for power failure ;-)
I can rule out electricity, whole server rack full of 2U's doing nothing all night every night. Couldn't be bothered to find the power button is a possibility. It's really not a server as much as it is a "server" (repurposed dumpster pc) so the power button is in a bit of an oddball location as it's a Dell mid-tower for Micro-ATX boards. It passed QA I can say that because the host & both running VM's recovered like it never happened. Still. Not recommended.

My running theory is I had it plugged into a spare monitor that went to sleep from it's DisplayPort input so the server took over (VGA input) and the onscreen log kept spitting out that the network interface was down and apparently that bothered him. A lot...
 
That's a whole other confusing thing I opted to cheat instead of confront. It seems without Internet access if I set the BIOS clock to the current time PROXMOX will set it to UTC time which for me (EST) is supposed to be +4 or 5hrs? So if the BIOS says 10AM PROXMOX says 6AM EDT...

I'd have to research the difference between EDT and EST but EDT doesn't sound like UTC so I don't know why it's taking the BIOS EST and subtracting 4 fours.

So I "cheated" by just advancing the BIOS clock 4 hours. Not perfect but it works.
I doubt that last part. Proxmox can set the virtual RTC to UTC or the local time. The default depends on the OS type. I had to lookup EST and EDT but it is UTC -4 and -5 respectively. I strongly suggest letting Proxmox set the virtual time to UTC and selecting the right timezone (without daylight savings etc.) inside the VM (as well as on the Promox host). With a Linux (or similar) VM, this will take care of daylight savings automatically and correctly (when keeping tzdata up to date). No need to calculate the right offsets manually (which is error prone).
I can rule out electricity, whole server rack full of 2U's doing nothing all night every night. Couldn't be bothered to find the power button is a possibility. It's really not a server as much as it is a "server" (repurposed dumpster pc) so the power button is in a bit of an oddball location as it's a Dell mid-tower for Micro-ATX boards. It passed QA I can say that because the host & both running VM's recovered like it never happened. Still. Not recommended.

My running theory is I had it plugged into a spare monitor that went to sleep from it's DisplayPort input so the server took over (VGA input) and the onscreen log kept spitting out that the network interface was down and apparently that bothered him. A lot...
People problems cannot be solved by technology, but in this case turning off the display (until you need it) might prevent such issues.
 
  • Like
Reactions: Windows7ge
@bbgeek17 & @leesteken It worked! :)
Code:
30 16 * * * /usr/sbin/shutdown -h now
I'd like to see it work more than once before I let myself think it's the solution but it's good to see it do what I wanted.
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!