Find the answer to your Linux question:
Results 1 to 3 of 3
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    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:

    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
    St. Petersburg, FL
    To cycle through a list of places, use a:
    for foo in "$bar"
    baz $foo
    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
    if a file called links.txt contains only a list of links, one on each line, the following could help:

    #! /bin/bash
    for link in `cat links.txt`
       echo -n "testing $link..."
       if rsync -rvvv $link
          echo "good"
          echo "bad"
    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.

  4. $spacer_open

Posting Permissions

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