I took a slightly different approach. The ping replacement script is
called with 1 argument (the hostname) for ping, or 2 arguments hostname
MAC_address for wol. It means putting the mac address in $conf{PingCmd}
for hosts that need wol rather than in a separate file like Michael uses.
My default PingCmd is:
$Conf{PingCmd} = '$pingPath $host'
On WOL hosts I over ride it with:
$Conf{PingCmd} = '$pingPath $host <mac_address>'
where <mac_address> is replaced with the actual value for that host.
My script is messy since I did home-rolled wake-on-lan with xxd and
netcat. That avoided installing wakeonlan as an extra dependency on
FreeBSD. If you already have wakeonlan you'd want to change the script
to use that instead of xxd.
WOL of course needs to be configured on the windows machines, possibly
in bios as well as in windows. I'd test that from the command line
before putting it into backuppc.
RP
The script:
#!/bin/sh
# BackupPC_pingwol
# Ping replacement for use with BackupPC that sends optional wake on lan
packets
# Russ Poyner 9/8/2014
PATH="/sbin:/bin:/usr/bin:/usr/local/bin"
export PATH
# No wol by default
wakeme=
# Send wol with xxd.
# Best re-write this to use linux wakeonlan if you have it.
wol()
{
# Convert the wol packet to binary with xxd
# and send it to the client through netcat.
echo "Sending wake on lan packet to $hostname at $cleanmac"
echo $packet | xxd -r -p | nc -w 1 -v -u $hostname 9
}
# Minimal argument parsing
if [ "$#" = "2" ]
then
wakeme="yes"
hostname=$1
# Construct the wol packet in hexadecimal
cleanmac=`echo $2 | sed -r 's/:|-//g' | tr '[:lower:]' '[:upper:]'`
# Next 2 lines not needed if you use a real wakeonlan utility
mac4="${cleanmac}${cleanmac}${cleanmac}${cleanmac}"
packet="FFFFFFFFFFFF${mac4}${mac4}${mac4}${mac4}"
elif [ "$#" = "1" ]
then
hostname=$1
else
echo "Usage:"
echo "$0 hostname [mac address]"
echo "Including the mac address will cause $0 to send WOL packets"
echo "if the host doesn't answer the first ping"
fi
ping -qc 1 $hostname
ret=$?
if [ "$ret" != "0" -a "$wakeme" = "yes" ]
then
for n in $(seq 1 15)
do
wol
ping -qc 1 $hostname
ret=$?
if [ "$ret" = "0" ]
then
exit 0
fi
done
fi
exit $ret
On 03/06/2015 12:07 AM, Russ Russ wrote:
Dear all,
Any ideas/assistance will be highly appreciated.
I have backuppc server on Gentoo which works fine with regular client
backups. Now I am configuring wake-on-lan to wake windows clients up
before backup.
The following has been done:
1.Bash script has been a bit modified from the one suggested on this
forum (details of the current script are provided at the end of the
message).
2.Config.pl has been modified on server as the following:
$Conf{PingPath} = '/usr/local/bin/wolping.sh';
$Conf{NmbLookupFindHostCmd} = ' ';
3.Appropriate 777 rights have been granted to wolping.sh. This is
output of ls –l:
-rwxrwxrwx 1 backuppc backuppc 1246 12:00 wolping.sh
4.I have tested wolping.sh and it works great from terminal under
backuppc user
But when I fire manual backup on any client which is in standby mode,
I got the following message: “2015-03-06 11:29:14 no ping response”
Seems that backuppc does not even fire the script as “logger”does not
appear in tail -f /var/log/messages
Could you please advise what might cause such an issue
Many thanks
wolping.sh:
----------------------------------------------------------------------
#!/bin/bash
#this script is totally designed for the backuppc ping command
#which is the first thing it does before it starts a backup
#this is a substitute which pings the machine, if it is not
#awake then it wakes it using a magic packet - using the wol.bsh script
#then pings again to make sure
PING=/bin/ping
ARG1=$1
ARG2=$2
ARG3=$3
ARG4=$4
WAKEHOST=$5
ETHWAKE="/sbin/ether-wake -i enp3s0"
SLEEPTIME=3m
logger "Backuppc pinging$1 $2 $3 $4 $5"
function fwol {
TO_WAKEUP=$1
sudo $ETHWAKE $1
if [ $? -eq 0 ]
then
WOL_RES="OK"
else
WOL_RES="FAIL"
fi
}
$PING $ARG1 $ARG2 $ARG3 $ARG4 $WAKEHOST >>/dev/null 2>&1
if [ $? -ne 0 ]; then
fwol $WAKEHOST
if [ "$WOL_RES" = "FAIL" ]; then
exit 1
fi
sleep $SLEEPTIME
$PING $ARG1 $ARG2 $WAKEHOST
if [ $? -eq 0 ]
then
logger "success waking $WAKEHOST."
else
logger "unable to wake $WAKEHOST."
exit 1
fi
else
$PING $ARG1 $ARG2 $ARG3 $ARG4 $WAKEHOST
fi
exit 0
------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
BackupPC-users mailing list
BackupPC-users@lists.sourceforge.net
List: https://lists.sourceforge.net/lists/listinfo/backuppc-users
Wiki: http://backuppc.wiki.sourceforge.net
Project: http://backuppc.sourceforge.net/
------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
BackupPC-users mailing list
BackupPC-users@lists.sourceforge.net
List: https://lists.sourceforge.net/lists/listinfo/backuppc-users
Wiki: http://backuppc.wiki.sourceforge.net
Project: http://backuppc.sourceforge.net/