Is it possible, to run background nested vbash scripts in VyOS ?
Would scheduled tasks meet your needs?
Not in this case. Basically, I need to start a few jobs in background, however as soon I’m using set/commit commands inside it, the scripts are killed and get frozen in zombie state, until killed manually with kill -9. But not sure why is this yet.
I managed to get this working on VyOS VyOS 1.4-rolling-202308180646:
Create file /config/custom/testsleep.sh (chmod 775 + chown root:vyattacfg) containing:
#!/bin/sh
# Script debugging
#set -x
# Set variables
LOGFILE=/config/custom/testsleep.log
# Perform stuff
while true; do
NOW=$(date +"%y%m%d_%H%M%S")
echo ${NOW} >> ${LOGFILE}
sleep 2s
done
Then in /config/scripts/vyos-postconfig-bootup.script add this:
/config/custom/testsleep.sh &
And then reboot.
After reboot you can verify that its running in the background:
root@vyos:~# ps auxwww | grep -i testsleep
root 2761 0.0 0.0 6936 3444 ? S 14:09 0:00 /bin/sh /config/custom/testsleep.sh
but also check the log it spits out to its logfile:
root@vyos:~# tail -f /config/custom/testsleep.log
230822_141456
230822_141458
230822_141500
The proper way would of course (since this is a systemd based system) to utilize systemd.service because this way the script can have a watchdog through systemd to get restarted if it crashes and such. Or by adding it as a “cronjob” to be triggered once an hour or such.