Operating System - HP-UX
1855590 Members
2147 Online
104112 Solutions
New Discussion

Re: "rsync" return response status for executing shell scripts remotely on remote servers via ssh

 
SOLVED
Go to solution
Shivkumar
Super Advisor

"rsync" return response status for executing shell scripts remotely on remote servers via ssh

Hi,

We use rsync scripts to push the contents to remote servers.
We want to execute some shell scripts on remote servers via ssh only if the contents of the target server directory changed with newer
contents.

Someone said that rsync returns some respose which needs to be captured when new contents are pushed to the target servers.
Once it is known that new contents are pushed then only the remote shell scripts should be executed via ssh.

Can someone explain how this can be done ?

Appreciate your help.

Thanks,
Shiv
6 REPLIES 6
Andrew Young_2
Honored Contributor

Re: "rsync" return response status for executing shell scripts remotely on remote servers via ssh

Hi Shiv

When you run your rsync with the -v optione redirect your STDOUT to a file.

Running grep on that file could give an indicaction of what has changed. Usually as a rule the output will give the following if nothing has changed otherwise list the files that have changed too.

building file list ... done

sent 22307 bytes received 16 bytes 8929.20 bytes/sec total size is 58029642 speedup is 2599.54


HTH

Andrew Y
Si hoc legere scis, nimis eruditionis habes
Steven E. Protter
Exalted Contributor

Re: "rsync" return response status for executing shell scripts remotely on remote servers via ssh

Shalom Shiv,

rsync handles pushing content only if its newer.

Just keep the ntp set properly on the server and use the -e ssh and --delete and stats options and it will work.

rsync checks the time and date stamp on files and directories.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Shivkumar
Super Advisor

Re: "rsync" return response status for executing shell scripts remotely on remote servers via ssh

Appreciate any more ideas on this ?

Thanks.
Shivkumar
Super Advisor

Re: "rsync" return response status for executing shell scripts remotely on remote servers via ssh

Bill,

Do you also have any opinion on this ?

Best Regards,
Shiv
PeterWolfe
Respected Contributor
Solution

Re: "rsync" return response status for executing shell scripts remotely on remote servers via ssh

cfengine is a good tool for this. It has the explicit feature to synchronize a set of files and then optionally execute shell scripts on the target hosts only if synchronization actions were required.

cfengine is oriented toward synchronizing system admin data. If you are sync'ing
lots and lots of data (where rsyncs file
delta/diff region technology starts to cfengine is a good tool for this. It has the
explicit feature to synchronize a set of files and
then optionally execute shell scripts on the
target hosts only if synchronization actions were
required.

cfengine is oriented toward synchronizing system
admin data. If you are sync'ing lots and lots of
arbitrary data (MB's to GB's - where rsync's file
delta/diff region technology starts to come into
play) then it's not the appropriate tool - rsync
would be better there and you're back to parsing
rsync's stdout as suggested in the previous post.

It would be nice if rsync had a specific
exit status that could be used for this purpose
(i.e. success and work has been performed)
Andrew Young_2
Honored Contributor

Re: "rsync" return response status for executing shell scripts remotely on remote servers via ssh

Hi Shiv

Use the following script as a basis for what it is you wish to do. It's not elegant, but the best I could come up with in 10 minutes. Although I am using bash it should work with most shells

#!/usr/local/bin/bash

if `/usr/local/bin/rsync -avcz --rsh="ssh" /app/live/linux/fmx/ appsrv01:/app/oracle/live/fmx > filelist.txt`
then
moved=""
for id in `grep -v "building file list" filelist.txt | grep -v "total size is"`
do
if [ "x$id" != "x" ]
then
moved="true"
fi
done
if [ "$moved" = "true" ]
then
ssh appsrv01 "echo 'It Worked'"
fi
else
echo "rynsc failed"
fi

Regards

Andrew Y
Si hoc legere scis, nimis eruditionis habes