#!/bin/bash # Backuppc user script if [ "$#" != 2 ]; then echo echo "The BackupPC user script takes two arguments:" echo " First: a host name ( with a corresponding /etc/hosts entry )" echo " Second: - either a number corresponding to the output of the backup process (0 = failed / 1 = success)" echo " - OR -f to force shutdown a host" echo exit 1 fi # Array of computers, in the form: [hostname]='Username%Password' # these must be Administrator's accounts # Modify these according to your needs declare -A names names=( [hostname1]='adminuser1%password1' [hostname2]='adminuser2%password2' [hostname3]='adminuser3%password3' ) for i in "${!names[@]}" do if [ $i = $1 ]; then host_name=$i upwd=${names[$i]} fi done # Exit if no corresponding host name found [ "$host_name" = "" ] && echo "Host unknown!" && exit 1 # To stop a pc, if -f argument given ( wol script wasn't used and there is no host file ) if [ "$2" = "-f" ] then /usr/bin/net rpc SHUTDOWN -f -I $host_name -U "$upwd" -t 1 exit 0 fi # File to record the host status filename=/var/lib/backuppc/$host_name.laststate if [ -f $filename ] then echo "Filename=$filename" declare -i laststate read laststate < $filename echo "Last State Host $host_name = $laststate" else echo "Missing host file!" exit 1 fi # Actions after backup if [ $2 = 1 ] # Successfull backup then echo "Backup of $host_name OK" if [ $laststate = 0 ] then # Last state off, send shutdown echo "Sent SHUTDOWN to host $host_name" /usr/bin/net rpc SHUTDOWN -f -I $host_name -U "$upwd" -t 30 else # Last state : up echo "SHUTDOWN not sent to $host_name cause Host already UP before" fi elif [ $2 = 0 ] # backup error then echo "Problem during backup of $host_name" # Only shutdown after unsuccesfull backup during out of office hours #if [ $(date +%k) -lt 07 -o $(date +%k ) -gt 22 ] #then #/usr/bin/net rpc SHUTDOWN -f -I $host_name -U "$upwd" -t 30 #fi fi if [ -f $filename ] then echo "Delete $filename" unlink $filename fi