compare contents of two directories on remote server using unix

You can use rsync with the -n flag to find out if the files are in sync, without actually doing a sync. For example, from server1: rsync -n -avrc /abc/home/sample1/* server2:/abc/home/sample2/ This will print the names of all files (recursive, with the -r flag) that differ between server1:/abc/home/sample1/ and server2:/abc/home/sample2/ rsync used parameters explanation -n, … Read more

Get the exit code for a command in Bash and KornShell (ksh)

Below is the fixed code: #!/bin/ksh safeRunCommand() { typeset cmnd=”$*” typeset ret_code echo cmnd=$cmnd eval $cmnd ret_code=$? if [ $ret_code != 0 ]; then printf “Error: [%d] when executing command: ‘$cmnd'” $ret_code exit $ret_code fi } command=”ls -l | grep p” safeRunCommand “$command” Now if you look into this code, the few things that I … Read more