Convert shell script for looping

Situation: I have a working shell script on our file server (OSXS Tiger) to connect to a workstation, which is using a portable home directory (phd), and rsync a user's MirrorAgent.log. I'm not that strong of a scripter (obviously), but I would like to add other workstations to this script as they are converted to phd's so they can be checked to see if the phd is working as it should (another script down the line). I reason that I need to convert this script to loop through the workstation names. I'm looking for any helpful suggestions for how to do this:

#!/bin/bash 
# 
# purpose: to use rsync to synchronize the MirrorAgent.logs of PHD users 
# 
# create variables 
RSYNC="/usr/bin/rsync" 
ROpts="-az -e ssh" 
ADMIN="alatorre@cshs.org" 
SRC="cardenasv@awm2212a.csmc.edu:~/Library/Logs/MirrorAgent.log" 
DST="/Volumes/Data2/MA_logs/cardenasv/" 
theLog="/Library/Logs/mySync.log" 
# 
# sync MirrorAgent.log 
time $RSYNC $ROpts $SRC $DST >> $theLog 
# test to see if sync completed successfully 
if [ ! $? = 0 ]; then 
        echo "MA_log SYNC NOT COMPLETED!!!" >> $theLog 
        echo "MirrorAgent.log not synced!" | mail -s "MA log sync problem" $ADMIN 
fi 
exit 0 
# end script

Thanks in advance.

This should help...

#!/bin/sh
#

inputstuff=`ls -1 /Users/`

for names in $inputstuff
do
	if [ $names = "Shared" ]; then
		continue
	else
		echo "put your stuff here"
		echo
	fi
	
done

Yes, it does. This is exactly what I was looking for. Thanks, much.

With the help provided by the kind forum member, I was able to convert the script for looping:

#!/bin/bash
#
# purpose: to use rsync to synchronize the MirrorAgent.logs of PHD users
#
# create variables
PHDUSERS=`cat /Library/Scripts/shell/phd_users.txt`
RSYNC="/usr/bin/rsync"
ROpts="-az -e ssh"
ADMIN="alatorre@cshs.org"
#SRC="cardenasv@awm2212a.csmc.edu:~/Library/Logs/MirrorAgent.log"
theLog="/Library/Logs/mySync.log"
#
# sync MirrorAgent.logs
echo "*** MirrorAgent Log Sync ***" >> $theLog
echo "===> sync'd the following user MirrorAgent logs:" >> $theLog
for names in $PHDUSERS
do
        theUser=`echo $names | awk -F@ '{print $1}'`
        SRC="${names}:~/Library/Logs/MirrorAgent.log"
        DST="/Volumes/Data2/MA_logs/${theUser}/"
        $RSYNC $ROpts $SRC $DST
        # test to see if sync completed successfully
        if [ ! $? = 0 ]; then
                eRR="${theUser} SYNC NOT COMPLETED!!!"
                echo $eRR >> $theLog
                echo $eRR | mail -s "MirrorAgent.log sync problem" $ADMIN
        else
                echo $theUser >> $theLog
        fi
done
date >> $theLog
echo "---" >> $theLog
exit 0
# end script

This forum is awesome. Thanks, again.

I can't claim credit, really.

I got it from
http://www.tldp.org/LDP/abs/html/

:slight_smile: