How do I return an exit code with Rsync?

Posted on 2005-04-11
Last Modified: 2013-12-16
Hi all,

Take any rsync script... I'm interested to know how to use the exit code rsync provides to determine success or failure.

For example,

# /bin/bash
rsync -a /foo /bar

How do I do an "if then" to catch the exit code then perform an action (i.e. if exit code > 0, echo "there is a problem" into a logfile)

Question by:dsstao
    1 Comment
    LVL 51

    Accepted Solution

    rsync ....
    if [ $? -ne 0 ]; then
      echo error >> logfile

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
    I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension ( This reminded me of questions tha…
    Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
    Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now