wget
to run a PHP script on a web server that dumps some MySQL databases, zips up the dumps and emails them to me. After doing this I want the bash script to shut down my computer.Here's the bash script:
Code: Select all
#!/bin/bash
# Run the backup script to backup all client MySQL databases on iServe
echo "Starting database backup"
outputFile="/home/murray/cron/clientdbs/$(date +%Y%m%d).txt"
logFile="/home/murray/cron/clientdbs/log.txt"
wget --append-output=$logFile --output-document=$outputFile --user=backup --password=xxxxxx http://xxxxxx.com/backup.php?verbose=1
exitCode=$?
if [ $exitCode -ne 0 ]; then
echo "wget returned error code $exitCode"
else
echo "Finished database backup"
fi
/sbin/shutdown -h --no-wall +3
cron emails me all the output from the bash script, this is what I receive:
Code: Select all
Starting database backup
Finished database backup
Failed to set wall message, ignoring: Interactive authentication required.
Failed to call ScheduleShutdown in logind, proceeding with immediate shutdown: Interactive authentication required.
shutdown
command requires authentication, even though I can run it ok manually from a CLI without having to sudo it. I'm also unsure why it's complaining about setting a wall message when I've used the --no-wall
option to specify that I don't want one.I did a bit of Googling and found I could edit the sudoers files to specify that my user didn't require authentication for the shutdown command, so I did this by adding the following line:
murray ALL=(ALL:ALL) NOPASSWD: /sbin/shutdown
If I do a
sudo -l
this is what I receive:Code: Select all
Matching Defaults entries for murray on mercury:
env_reset, mail_badpass,
secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin,
pwfeedback
User murray may run the following commands on mercury:
(ALL : ALL) ALL
(root) NOPASSWD: /usr/lib/linuxmint/mintUpdate/checkAPT.py
(ALL : ALL) NOPASSWD: /sbin/shutdown
shutdown
command. Unfortunately this didn't help, I still receive the same error message.Have I done something wrong? How can I run
shutdown
via my personal crontab? Or is there a better way to do what I'm trying to do?