943,929 Members | Top Members by Rank

Ad:
Jun 6th, 2007
0

Convert shell script for looping

Expand Post »
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, 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:
Shell Scripting Syntax (Toggle Plain Text)
  1. #!/bin/bash
  2. #
  3. # purpose: to use rsync to synchronize the MirrorAgent.logs of PHD users
  4. #
  5. # create variables
  6. RSYNC="/usr/bin/rsync"
  7. ROpts="-az -e ssh"
  8. ADMIN="alatorre@cshs.org"
  9. SRC="cardenasv@awm2212a.csmc.edu:~/Library/Logs/MirrorAgent.log"
  10. DST="/Volumes/Data2/MA_logs/cardenasv/"
  11. theLog="/Library/Logs/mySync.log"
  12. #
  13. # sync MirrorAgent.log
  14. time $RSYNC $ROpts $SRC $DST >> $theLog
  15. # test to see if sync completed successfully
  16. if [ ! $? = 0 ]; then
  17. echo "MA_log SYNC NOT COMPLETED!!!" >> $theLog
  18. echo "MirrorAgent.log not synced!" | mail -s "MA log sync problem" $ADMIN
  19. fi
  20. exit 0
  21. # end script
Thanks in advance.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
le0pard13 is offline Offline
2 posts
since Jun 2007
Jun 14th, 2007
0

Re: Convert shell script for looping

Does this help ?
bash Syntax (Toggle Plain Text)
  1. #!/bin/bash
  2.  
  3. file_with_workstations_list=/tmp/input_list.txt
  4.  
  5. while read workstation_name
  6. do
  7. #do you stuff with workstation_name
  8. echo "Read workstation name: " $workstation_name
  9. done < $file_with_workstations_list
Reputation Points: 254
Solved Threads: 74
Practically a Posting Shark
thekashyap is offline Offline
804 posts
since Feb 2007
Jun 14th, 2007
0

Re: Convert shell script for looping

Yes, it does. This is exactly what I need. Thanks, much. :-)
Reputation Points: 10
Solved Threads: 0
Newbie Poster
le0pard13 is offline Offline
2 posts
since Jun 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Shell Scripting Forum Timeline: shell script crontab
Next Thread in Shell Scripting Forum Timeline: script to email new ip





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC