3
votes
What things can be done to make a Bash script containing sudo commands, running with the timer schedule ‘crontab’ work?
Instead of trying to trigger a root-requiring operation through your user's crontab, you should use the system crontab, and then you simply don't need sudo, because things are already running as root.
...
1
vote
save the output to multiple files in crontab
Using tee works with no issues. tty is just the device that is used to interact with the operating system and is located at /dev/tty#.
0 2 * * * /usr/local/bin/backup.sh | tee /root/output_all.txt ...
1
vote
How can I "cache" a variable in Bash?
You can store your variables inside a simple plain text file.
I used two bash functions for that:
# the cache file in /tmp
CACHE_FILE="/tmp/your-file.txt"
touch "$CACHE_FILE"
# ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
cron × 2299linux × 343
shell-script × 281
bash × 280
ubuntu × 169
debian × 136
shell × 133
scripting × 102
centos × 101
scheduling × 77
python × 73
logs × 71
email × 55
raspberry-pi × 51
ssh × 46
environment-variables × 42
systemd × 40
rhel × 40
rsync × 40
php × 36
permissions × 33
io-redirection × 33
backup × 33
raspbian × 31
reboot × 31