![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
If you want the checksum value in your local script - try this:
chsum="`/usr/local/bin/ssh2 $MACHINE cksum $DESTFILENAME`" |
||||
| Google The UNIX and Linux Forums |