Running a zfs snapshot in rc.local 2 minutes after boot

It is i think something with zsh -c "mycommand"
Something with an &
Something with nohup
Something like ?
Code:
nohup /usr/local/bin/zsh -c "sleep 120;logger snapshot0h;nohup /root/bin/snapshot_usr_home_0h &" &
There is also "daemon" ???
The script produces some output.
The script has "pv" in it showing how far
The proces dies without a snapshot, I'm doing something wrong because it does not work non-interactive.
Running " /root/bin/snapshot_usr_home_0h" from command line works fine.
Do rc.local scripts have the right root privileges ?
 
Without pv it worked. Why I don't know.
And how many nohup or & i need is also unknown to me.
For weekly i have,
Code:
export weekday=`date | awk '{print $3 %7 }' `
echo $weekday
if [[ $weekday -eq 0 ]]
then
    nohup /usr/local/bin/zsh -c  "sleep 300;sleep  3000;logger snapshotweek;nohup /root/bin/snapshot_usr_home_weekly &" &
fi
 
rc scripts don't have /usr/local/bin in $PATH
use
weekday=$(date +%w) or date +%a
Code:
[09:09:54] [host!user]~$nohup sh -c "date +%s;sleep 10;date +%s" &
[1] 82209
[09:09:57] [host!user]~$appending output to nohup.out

[1]+  Done                    nohup sh -c "date +%s;sleep 10;date +%s"
[09:10:20] [host!user]~$cat nohup.out
1622009397
1622009407
 
cron is literally for this sort of thing, for your first question look at @reboot
Code:
cat /etc/crontab
@reboot root  sleep 120; /usr/local/bin/example_script
note, use lock files to prevent overlapped running in your script

or you can do it in root's crontab with crontab -e (note the user is not specified below, but is in /etc/crontab (see above))
Code:
# crontab -l
#after boot
@reboot sleep 120; /usr/local/bin/example_script
#weekdays, 1 minute past midnight.
1 0 * * 1-5 /usr/local/bin/example_script
 
I call a script with a sleep command from /etc/rc.local with &:
Code:
# cat /etc/rc.local
/root/hdd/sleeptimer.sh &
The script contains:
Code:
#!/bin/sh
sleep 120
camcontrol standby ada1 -t 1100
sleep 2
camcontrol standby ada0 -t 1110
[…]
 
rc scripts don't have /usr/local/bin in $PATH
use
weekday=$(date +%w) or date +%a
Code:
[09:09:54] [host!user]~$nohup sh -c "date +%s;sleep 10;date +%s" &
[1] 82209
[09:09:57] [host!user]~$appending output to nohup.out

[1]+  Done                    nohup sh -c "date +%s;sleep 10;date +%s"
[09:10:20] [host!user]~$cat nohup.out
1622009397
1622009407
changed it to, including full path,
Code:
export weekday=`/bin/date | /usr/bin/awk '{print $3 %7 }' `
echo $weekday
if [[ $weekday -eq 0 ]]
then
/usr/local/bin/zsh -c      "sleep 300;sleep  3000;logger snapshotweek;/root/bin/snapshot_usr_home_weekly" &
fi
 
Back
Top