简体   繁体   中英

Recurring bash script execution without cron

I need to execute a bash script every Saturday at 2 AM on a very minimal Linux-based system that does not allow for the regular user to add cronjobs. In particular, the crontab file gets resetted to some manufacturer's default every day by the system.

I therefore need a way to keep this script running in the background forever but it needs to sleep while currentTime != Saturday, 2 AM (it's a backup script, btw).

How can I do that? Thank you to all.

If you can make use of at , it might be possible to automatically call a script that call's itself:

Creating a script at_periodic with the following content:

#!/usr/bin/env bash
timespec="$1"; shift
"$@"
printf "%q " "$(readlink -f -- "$0")" "$timespec" "$@" | at "$timespec"

Now it is possible to run:

$ ./at_periodic "2am Saturday" command with -- complex arguments

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM