Destination directory creation

Dave Markham dave.markham at
Fri Feb 16 13:42:47 GMT 2007

Hi people. My first post so be lenient :)

I have read stuff on rsync, looked through the options and read the man
page but cannot seem to find an answer to my problem.


I have a script which connects to a remote machine via ssh and pulls
back a list of source directories/files from a config file on the remote
server. I then loop these lines and do an rsync for each item to pull
the files back to my local machine.

The rsync syntax im using is this (there is much more in the script im
just pulling out important bits) :-

RSYNC_BIN=$(/usr/bin/which rsync)
# May want to drop the v verbose
RSYNC_OPTS=" -Pvprtlz --delete --delete-excluded --copy-unsafe-links

# Ok here is the Rsync loop
        for RLIST in ${remote_get_list}
                # Going to put a safety test here in case / is file list
                if [ "${RLIST}" = "/" ];then
                        echo "\n[Remote_Get for
${remote_get_host}]\n\tWARNING:We dont want / as a source. Too intense
so skipping." >> ${remote_errorlog}

                # Rsync output will be logging to error file so
                # need list there too for clarity
                echo "\n\tStaring get of [${RLIST}]" >> ${remote_mainlog}
                echo "\n\tStaring get of [${RLIST}]\n" >> ${remote_errorlog}

                ${RSYNC} -e ssh 2>/dev/null
user@${remote_get_host}:${RLIST} ${remote_get_localdir} >>
${remote_errorlog} 2>> ${remote_errorlog}
                # Check each Rsync run was successful or had errors
                if [ $? = 0 ];then
                        echo "\tGet of [${RLIST}] status [Successful]"
>> ${remote_mainlog}
                        echo "\tGet of [${RLIST}] status
[Suspect]\n\tSee [${remote_errorlog}]" >> ${remote_mainlog}


Now ${remote_get_list} is a variable containing a list of files or dirs
from a config file which looks like this :- ( obviously comments, blank
lines are ignore )

# This is a comment line
# so is this
## multiple hashes
#/dir/dir2/file #Plus comments here

The question i have is this :-

when i run the script using the above config file it only creates locally :-


I see this as a problem as what if i have the following in the config
file :-


This will create ${remote_get_localdir}/hosts from source
/etc/inet/hosts and then overwrite it with /export/home/user/hosts.

Is this correct? What i want is for rsync to create this :-


Anyone any ideas?

More information about the rsync mailing list