can I get proxmox shell to run a command after 120 second when restart/startup.

Kiptanoi

New Member
Mar 21, 2024
3
0
1
Hello.
In my fstab, I have this: //xxx.xxx.xxx.xxx/media/audiobooks /media/audiobooks cifs auto,_netdev,credentials=/root/.smbcredentials,uid=3000,gid=3000 0 0

And I run truenas in a vm on this proxmox, so this smb share will not be ready until my truenas has booted up.
And for me to get it to work, I need to wait for truenas to boot, and then go in shell of pve and run mount -a
After that I got my share to work....

So, I am now wonder, if I can get pve shell to run this command automatic after x amount of seconds, lets say 120 seconds after a reboot or startup.
Is that possible?
 
sure, write a basic script that runs via crontab on boot and sleeps 120s as first step
https://phoenixnap.com/kb/crontab-reboot


Blockbridge : Ultra low latency all-NVME shared storage for Proxmox - https://www.blockbridge.com/proxmox
Thanks
If I read at this page: https://www.redswitches.com/blog/crontab-reboot/
I can see that this command can be used in the crontab @reboot sudo apt update && sudo apt upgrade -y
Does that mean that I can do this in my crontab: @reboot sleep 120 sudo mount -a ?
Or how does this work?
I am all new to proxmox and linux stuff.

If you could give a complete example on how a basic script of a command that do mount -a after 120 seconds when server is rebooted, So I can learn how it works would be great.
 
Does that mean that I can do this in my crontab: @reboot sleep 120 sudo mount -a ?
No. You need to write a script (example bash: delayed_mnt.sh) containing the sleep command & the mount command, and then enter in the crontab @reboot /PathToScript/delayed_mnt.sh

If I were you, I would also remove/comment out the line in the fstab, & enter the complete mount command in the script for the TrueNas share.
 
Last edited:
Does that mean that I can do this in my crontab: @reboot sleep 120 sudo mount -a ?
Basically yes. But you need ";" (unconditionally) or "&&" (only if successful), so I would try @reboot sleep 120 && sudo mount -a (for a user-crontab) or @reboot sleep 120 && mount -a for the system-wide crontab, run directly as root.

Putting it into a separate script is easier to debug ;-)
 
I would also work with absolute paths and pipe output to /dev/null so you won't get spammed with mails each reboot.
So adding something like @reboot root /usr/bin/sleep 120 && /usr/bin/mount -a >/dev/null 2>&1 to the /etc/crontab.
 
  • Like
Reactions: UdoB
But even cleaner might be a proper script that will loop through a routine that checks via TrueNAS API if the SMB service is up and running, if not waits some seconds and only mounts the SMB shares when the SMB shares are actually available. That way you won't end up with a failed mount and it will speed up reboots as you don't need to wait the full 120 seconds in case the SMB share is available earlier.
But yes, this won't be a simple one-liner and this is one of the reasons every (homelab) admin should learn some at least one scripting language.
 
Last edited:
  • Like
Reactions: gfngfn256
I still would personally go with a script - apart for Dunuin excellent idea above, which justifies a script on it's own - I guarantee you (from experience) you are still going to have to tinker with the exact command/s sequence/s you require to granularly control what you want to happen. A script is easily reproducible, editable & removable. You can also easily save/backup this script elsewhere.
 

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!