Find the answer to your Linux question:
Results 1 to 3 of 3
I'm working on a script that uses rsync to replicate data to a central storage site for dozens of remote offices. Each remote office has a server set up with ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Sep 2005
    Posts
    4

    Capturing exit values and using a parameters file


    I'm working on a script that uses rsync to replicate data to a central storage site for dozens of remote offices. Each remote office has a server set up with an rsync daemon running. I'm not using SSH because all of the traffic between these sites are on a private network so the rsync daemon is running in socket mode.

    Currently the script looks something like:


    Code:
    #!/bin/bsh
    
    rsync -rvvv location_1::temp /tmp/loc_1/
    rsync -rvvv location_2::temp /tmp/loc_2/
    rsync -rvvv location_3::temp /tmp/loc_3/
    ...

    ...what I really want to do is have this script loop through the locations (reading them from a file) and then have the script use the exit values from rsync to identify when a particular location fails. If a location fails, it would place the location into a error file that could be used to retry the locations automatically. I'm still learning shell scripting so any help would be appreciatted.

  2. #2
    Linux Guru lakerdonald's Avatar
    Join Date
    Jun 2004
    Location
    St. Petersburg, FL
    Posts
    5,035
    To cycle through a list of places, use a:
    Code:
    for foo in "$bar"
    do
    baz $foo
    done
    Where $bar is a space-delimited list of things to loop through, and baz $foo is something to do to each one.
    To capture error codes, you can check the variable $? after each command.

  3. #3
    Just Joined!
    Join Date
    Apr 2005
    Posts
    23
    if a file called links.txt contains only a list of links, one on each line, the following could help:

    Code:
    #! /bin/bash
    
    for link in `cat links.txt`
    do
       echo -n "testing $link..."
       if rsync -rvvv $link
       then
          echo "good"
       else
          echo "bad"
       fi
    done
    if the links file doesn't contain just one link on each line, then you could add some pipes to the `cat links.txt` command to manipulate the output and give you what you need.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •