The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
please convert the below program into shell script mail2sant Shell Programming and Scripting 3 04-10-2008 09:39 AM
convert cpp program to c shell script ? domain Shell Programming and Scripting 2 12-12-2007 06:43 AM
looping through a variable in a shell script ramachandranrr Shell Programming and Scripting 1 03-04-2007 08:02 PM
C Shell Script to convert a number into minutes Ringo Shell Programming and Scripting 1 08-07-2003 02:24 PM
Looping a perl script in a shell script edkung Shell Programming and Scripting 8 10-04-2002 11:28 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-06-2007
le0pard13's Avatar
le0pard13 le0pard13 is offline
Registered User
  
 

Join Date: Jun 2007
Location: Los Angeles, CA
Posts: 3
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:
Code:
#!/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.
  #2 (permalink)  
Old 06-06-2007
[MA]Flying_Meat [MA]Flying_Meat is offline
Registered User
  
 

Join Date: Sep 2002
Location: San Fran
Posts: 131
This should help...
Code:
#!/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
  #3 (permalink)  
Old 06-07-2007
le0pard13's Avatar
le0pard13 le0pard13 is offline
Registered User
  
 

Join Date: Jun 2007
Location: Los Angeles, CA
Posts: 3
Yes, it does. This is exactly what I was looking for. Thanks, much.
  #4 (permalink)  
Old 06-07-2007
le0pard13's Avatar
le0pard13 le0pard13 is offline
Registered User
  
 

Join Date: Jun 2007
Location: Los Angeles, CA
Posts: 3
Done

With the help provided by the kind forum member, I was able to convert the script for looping:
Code:
#!/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.
  #5 (permalink)  
Old 06-07-2007
[MA]Flying_Meat [MA]Flying_Meat is offline
Registered User
  
 

Join Date: Sep 2002
Location: San Fran
Posts: 131
I can't claim credit, really.

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

Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:38 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0