script doesn't work when run as cron job

From: Nick Sinclair (null_device_at_NOFRILLS.ssl-mail.com)
Date: 10/13/04


Date: Wed, 13 Oct 2004 14:29:52 +1000

Hi all,
I have this script that I wrote to automate worstation backups on a Mitel
server (RedHat).

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 in the users home directory on
the server from from the mounted share.

However, after upgrading from 5.6, using the collection of rpms, I notice
that the:

grep "something" /etc/mtab && do something

... lines in the script now fail.

When I run the script from the command line, it works fine.

Q. It's real strange. Does anyone know what might be causing this, or maybe
can offer something for my epiphany?

TODO: As I wrote this a while ago, 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 most 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

/dev/sig



Relevant Pages

  • Re: Can CGI script un-virtualize a relative path?
    ... while cgi-bin is a server wide alias. ... > located in respective home directory, ... > script being able to read files located in respective ... Sample Tcl scripts are stored in plain text files on the server. ...
    (comp.lang.tcl)
  • Re: Multiple Site Login Scripts
    ... |>> When they login at those remote sites, I need them to run a local logon ... |>> to the local server, not to the site A server. ... Simplest is to have just a single script that can determine the site ... |> users rely on their home directory, that will remain mapped to their home ...
    (microsoft.public.windows.server.scripting)
  • Re: PLEASE!!! HELP!!! ASAP!!! Mapping drives
    ... workstations is a command prompt first. ... try running the script. ... > If it's in workgroup mode, then you might need to either set up user> accounts on the server that match, including the password, those on the> workstations, or enable the Guest account on the server, or supply> credentials in the 'NET USE' command. ...
    (microsoft.public.windows.server.general)
  • Re: Multiple Site Login Scripts
    ... >> who is located in site A, travels to B, I need them to login and map ... >> to the local server, not to the site A server. ... Simplest is to have just a single script that can determine the site ... > users rely on their home directory, that will remain mapped to their home ...
    (microsoft.public.windows.server.scripting)
  • Re: Multiple Site Login Scripts
    ... > the remote sites for a day or two. ... > to the local server, not to the site A server. ... Simplest is to have just a single script that can determine the site you ... users rely on their home directory, that will remain mapped to their home ...
    (microsoft.public.windows.server.scripting)