Reputation: 493
I have a backup script that executes the poweroff command to shutdown my machine once all backups are finished. However it happens that I want to deny the poweroff, but without killing the script process, as it would corrupt my backup and leave a bad mess.
How can I make the poweroff not execute without pausing or killing the script?
Here's my script:
#!/bin/bash
/unfa/Scripts/Daily\ backup/backup.sh > ~/backup-unfa.log; echo "data thread finished" &
/mnt/system-backup/system-backup.sh > ~/backup-system.log; echo "system thread finished" &
sleep 1m
while [[ -n $(pgrep rdiff-backup) ]]
do echo "Backing up yo data, dude..."; sleep 3s
done
echo "POWER OFF"
poweroff
Upvotes: 0
Views: 105
Reputation: 493
The script will execute the poweroff command. If you want that to fail, you can temporarily change the /sbin/poweroff file permissions so it is not executable.
First, become root to gain full access to protected system files:
sudo su
Now remove the "is executable" permission from the poweroff binary:
chmod -x /sbin/poweroff
After the script is finished remember to revert this change, as otherwise you'll be left with a non-working poweroff command:
chmod +x /sbin/poweroff
Tested, works well.
Upvotes: 1