The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 03-30-2006
Registered User
 

Join Date: Feb 2006
Posts: 4
SSH and SCP

The following ksh script is trying to get a file's cksum then, scp it over to a remote machine - get the cksum there and then compare the two cksums to make sure they match. I am having problems setting a variable on the remote host where it can be read locally. Is this even possible - reading a shell variable from a remote host? I have the ssh and scp file transfer working properly. The two problems I am having are logging to the remote host's syslog.log and exporting $REMOTECKSUM for comparison. Any help or guidance is appreciated.

Thanks,
berrean


Code:
#!/usr/bin/ksh

MACHINE=$1
FILENAME=$2
DESTFILENAME=$3

#DEBUG echo "connecting to: $MACHINE"

# Get the local cksum and write it to a local log
cksum $FILENAME >> local.log
LOCALCKSUM=$(cksum $FILENAME)

# write an entry to the local syslog
logger -t TESTLOCALCKSUM -f local.log

# do scp here
#DEBUG echo "connecting to: $MACHINE"
#DEBUG echo "filename is: $FILENAME"
#DEBUG echo "destfilename is: $DESTFILENAME"
#DEBUG echo "command is /usr/local/bin/scp2 $FILENAME $MACHINE:$DESTFILENAME"

 /usr/local/bin/scp2 $FILENAME $MACHINE:$DESTFILENAME

# Write the remote cksum to a remote log and VARIABLE then log this in remote syslog
/usr/local/bin/ssh2 $MACHINE "cksum $DESTFILENAME >> remote.log; export REMOTECKSUM='$(cksum $DESTFILENAME)'; logger -t TESTREMOTECKSUM -f remote.log"

if [[ "$LOCALCKSUM" = "$REMOTECKSUM" ]]; then
	print -- "CHECKSUMS MATCH --- SUCCESS!!"
	print -- "local cksum: $LOCALCKSUM"
	print -- "remote cksum $REMOTECKSUM"
else
	print -- "CHCEKSUMS DO NOT MATCH --- FAILURE!!"
	print -- "local cksum: $LOCALCKSUM"
	print -- "remote cksum $REMOTECKSUM"
fi

Last edited by berrean; 03-30-2006 at 11:22 AM.
Reply With Quote
Forum Sponsor
  #2  
Old 04-02-2006
RTM's Avatar
RTM RTM is offline
Hog Hunter
 
Join Date: Apr 2002
Location: On my motorcycle
Posts: 3,039
If you want the checksum value in your local script - try this:
chsum="`/usr/local/bin/ssh2 $MACHINE cksum $DESTFILENAME`"
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 03:45 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0