I was used to have a rsync call in my crontab to perform backup from my laptop to my desktop. My idea was to backup my laptop everyday even if I wasn’t at home, so before the time that the rsync ran I had to make sure that I was connected to my home network via OpenVPN and that my desktop was on.
If the day was calm, no problem, but when I was busy at work that meant no backup for that day.
I decided to code my own script to solve this problem.
#Vars for remote computer
#Vars for my OpenWrt router
#this part checks if I'm on my LAN, if not it tries to connect to
# my OpenVPN server running in my Linksys with OpenWrt
echo "Checking if my router is on this network"
ssh $LINKSYS -p $LINKSSHPORT -l $LINKUSER ls &> /dev/null
while [ ! $PSTATE1 -eq 0 ]; do
echo "it isn't"
if [ ! -f /var/lock/subsys/openvpn ]; then
echo "openvpn is down, let's try to connect"
$HOME/vpn $(Xdialog --stdout --title "OpenVPN password" --no-close \
--screen-center --password --inputbox "Password" 10 100);
ssh $LINKSYS -p $LINKSSHPORT -l $LINKUSER ls &> /dev/null;
PCTRL=`expr $PCTRL + 1`
if [ $PCTRL -eq 5 ]; then
notify-send "connection failed"
#this part checks if my home computer is up, if not, it will
#try to turn it on by WOL from my OpenWrt router.
echo "hmmm, is my Computer up?"
ssh $DSTROOT@$DSTIP ls
while [ ! $PSTATE2 -eq 0 ]; do
echo "it's not.."
ssh -l $LINKUSER -p $LINKSSHPORT $LINKSYS /root/wakeup &> /dev/null
ssh $DSTROOT@$DSTIP ls
PCTRL2=`expr $PCTRL2 + 1`
if [ $PCTRL2 -eq 5 ]; then
notify-send "cannot power on remote computer";
exit 2 ;
echo "it's now"
# backup part
echo "starting backup..."
notify-send "starting backup..."
rsync -vaHx --progress --numeric-ids $HOME/ $DSTUSR@$DSTIP:$DSTFOLDER
notify-send "backup done"
#here it asks me if I want to turn off my home computer
Xdialog --title --stdout "remote computer is on..." --screen-center --yesno \
"Turn off computer?" 10 50
if [ $? -eq 0 ]; then
#the following line will set something in my Ethernet card that allows me to
#wake up my computer with WOL
ssh $DSTROOT@$DSTIP /sbin/ethtool -s eth0 wol g &> /dev/null
ssh $DSTROOT@$DSTIP poweroff &> /dev/null
for the dialogs, I had to install ‘xdialog’
Also, I’m calling another script called ‘vpn’ that I made with expect, it’s used to connect to my OpenVPN server with the passphrase I specify with a parameter.
if $argcsend_user “usage: \n”
send_user “$argv0 password \n”
spawn sudo /usr/sbin/openvpn –config /etc/openvpn/openvpn.conf –daemon
expect “Enter Private Key Password:”
send “[lindex $argv 0]\r”
In my router I made an script called ‘wakeup’ that only runs:
Hope you can use it for something, if not, you have a good example of how to use Xdialog, expect and some other things.