Hi all,
I have this script that I wrote and was thinking about contributing to the community of this site.
It's a script that maintains mirrors of all shares on workstations in an office by mounting a Windows "documents" share using 'samba' on the server and then using 'rsync' to update the backup on the server from from the mounted share.
However, after upgrading from 5.6, using the collection of rpms, I notice that the:
grep /etc/mtab &&
...now fails.
Also, I might just work this out shortly myself, but was also wanting some feedback on the script as well.
TODO: I will rewrite some of this script; redirecting STDOUT using 'exec' for the log writing, changing 'echo' to 'printf', and using 'declare and shopts' just to be more correct.
Any feedback is welcome:
=======================================================
#!/bin/bash
#############################################################
# This was originally written to work on a Mitel Server.
# This script implies that there will be directories already
# created as such: /mnt/workstation_shares/USER/documents
# These shares must also correspond to the home directories
# located in: /home/e-smith/files/users/USER/home/
# The "users" file should idealy contain a tab/space seperated
# list of user, pass, machine name for all workstations on
# the network. Quotes are preceeded with ";"
# The "users" file should be owned by root and have permissions
# of 600 and also be in a directory called "priv" that is owned
# by root and has permissions of 700.
# Run as a root Cron job.
# This software is written by Nick Sinclair and is distributed
# under the terms of the GNU General Public License 2004
#
# TODO: Add functionality to accept arguments such as:
# priv file, and addidional .conf file (file locations etc)
#
#############################################################
### A few variables
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/root/bin
# USER_FILE is the full/absolute path
USER_FILE=/usr/local/sbin/priv/users
RSYNC=/usr/bin/rsync
LOG_FILE=/var/log/workstation_backup_log
datevar=date +%d.%m.%y
day=date +%A
echo -e "\n\n-------------------------------------------------------\\/\n\
Starting auto backup of worksations: $day $datevar\n" >> $LOG_FILE
echo -e "> date +%r\n" >> $LOG_FILE
### Read through the "users" file
while read line_data; do
### Get rid of any comments
line=echo $line_data | sed -e 's/\;.*$//'
### Check to see if we have anything to parse
if [ ! -z "$line" ]; then
### Parse the line from the "users" file
user=echo $line | awk '{print $1}'
pass=echo $line | awk '{print $2}'
machine=echo $line | awk '{print $3}'
echo -e "Attempting to mount $user:$machine\documents " >> $LOG_FILE
### Attempt to mount the workstation share
grep "$machine" /etc/mtab &>/dev/null || \
mount -t smbfs \\\\"$machine"\\documents /mnt/workstation_shares/"$user"/documents/ \
-o ro -o username="$user" -o password="$pass" >> $LOG_FILE && \
echo -e "> success" >> $LOG_FILE
### Now try to rsync the data into the home directory for that user
grep "$machine" /etc/mtab &>/dev/null && \
echo -e "Attempting to start rsync" >> $LOG_FILE && \
$RSYNC -avz --exclude-from=exclude-file /mnt/workstation_shares/"$user"/documents/* \
/home/e-smith/files/users/"$user"/home/ &>/dev/null && \
echo -e "> rsync job done\n" >> $LOG_FILE
### Unmount the share
sleep 5
grep "$machine" /etc/mtab &>/dev/null && \
echo -e "Unmounting $user:$machine\documents" >> $LOG_FILE
umount /mnt/workstation_shares/"$user"/documents/ >> $LOG_FILE && \
echo -e "> success" >> $LOG_FILE
echo -e "> date +%r" >> $LOG_FILE
echo "----------------------------------------" >> $LOG_FILE
fi
done < "$USER_FILE"
echo -e "Process complete: \n\n" >> $LOG_FILE