In a bash script, I have some code that needs to run when the script is executed, then a function that I want executed at a specific time. How can I do that?
# Do this now
read -s -p "Password: " password
backup() {
7z ... -p$password
}
# Do this starting at 5am - how?
while true; do
backup
sleep 86400
done
I've looked at at, but the man page is very scant, without any examples. I can't tell if or how to schedule a function. Do I need the extract that function to an external file?
In case this is an XY problem, what I want to do is a password-protected backup every morning at 5am. The first part of the script asks for the password via read, and feeds it via an environment variable to 7z. The archiving part can be put in a while true; loop that sleeps for 86400 seconds to implement the "daily" part. The problem is starting at 5am. cron doesn't seem like a good option because the password should be persisted in a file, which is less secure than typing it once.
atscript, you can define a function and then call it. But if you want to do it every day, it's more suited forcron.cronwas my first thought, but how do I pass the password to7zsecurely?