PDA

View Full Version : Script for Automated Rsync



ductiletoaster
September 11th, 2010, 11:51 PM
Simply put im writing a script to do an automated rsync. The Issues I am having is that i have the script setup to wake up the remote machine and then shut it down. however I wanted to also test to see if the machine was on before the wakeonlan cmd was given. adn if so to not Shutdown the machine when the rsync is done.

My issues how would i check the the remote machine to see if it was on and then run seperates commands based on the situation

Example sudo code:


if remote machines is off {
wakeonlan that machines
} else do nothing



My linux server has a mounted windows share. Could i just do something like

if share is there then continue else break.....

ductiletoaster
September 12th, 2010, 12:07 AM
Any body?

v1ad
September 12th, 2010, 12:16 AM
ping ?

ductiletoaster
September 12th, 2010, 12:25 AM
I guess im just a little lost on how i would write it out in a script

v1ad
September 12th, 2010, 02:28 AM
did you start on the script? or are you asking for one.

people would probably help out more if they knew more info.

* did you start the script?
* if yes can you post the script minus any sensitive information?
* figure it out bit by bit and piece em together, then ask for help on specific parts.

ductiletoaster
September 12th, 2010, 05:19 AM
No I am writing one on my own i just need to be able to turn off a windows machine remotely and i didn't know how. but i figured it out and I finished the script



#!/bin/bash
# Description: This script first wakes up the client machine and syncs the appropriate folders.
# Finally the script shuts down both client and server.

# Default Variables
IP_ADDRESS="192.168.1.180"
MAC_ADDRESS="00:00:00:00:00:00"
MOUNT_SHARE="/mnt/windowshare"

ping -c3 $IP_ADDRESS
if [ $? -ne 0 ]; then
wakeonlan $MAC_ADDRESS # Wakes Windows Client
client_status=0 # Sets the computers status to was OFF
sleep 120 # Waits 2 mins for the computer to boot
else
client_status=1 # Sets the computers status to was ON
fi

sudo smbmount //$IP_ADDRESS/D$ $MOUNT_SHARE -o username=user,password=password # Mounts Windows Share

# Synchronizes All direcotries between both computers
rsync -ruz --delete --progress $MOUNT_SHARE/Development/* /home/user/Development/
#rsync -ruz --delete --progress $MOUNT_SHARE/Downloads/* /home/user/Downloads/
rsync -ruz --delete --progress $MOUNT_SHARE/Documents/* /home/user/Documents/
#rsync -ruz --delete --progress $MOUNT_SHARE/Music/* /home/user/Music/
#rsync -ruz --delete --progress $MOUNT_SHARE/Pictures/* /home/user/Pictures/
#rsync -ruz --delete --progress $MOUNT_SHARE/Videos/* /home/user/Videos/

sudo umount //$IP_ADDRESS/D$ # Unmounts Windows Share

if [ $client_status -eq 0 ]; then
net rpc SHUTDOWN -I $IP_ADDRESS -U user%password # Shutsdown Windows Client
fi
# Shutsdown Linux Server
sudo halt


Now the problem I am having is that im trying to figure out how to have this run let say every monday on startup. Like a cron job but i need it to happen before any users login. But i only wanted it to happen once a week.... O and it needs root permissions