The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Operating Systems > SUN Solaris
.
google unix.com



View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 06-04-2008
PabloCruise77 PabloCruise77 is offline
Registered User
  
 

Join Date: Feb 2007
Location: Loomis, CA
Posts: 5
Wink Solution to SSH/SCP Problem

Here's what I found after examining a co-worker's source code. Put the
following in the source host script:

#########################################################
# source_host_script
#
#
#########################################################
.
.
.

param="UPDATE"
file_update="${HOME}/${subdir}/${newfile}"

ssh ${userid}@${host} ${param} ${file_update}
retval=$?

if [ ${retval} -ne 1 -a ${retval} -ne 0 ]; then
echo "Source Code Update Failed: ${retval}"
echo "Press any key to continue"
fi

return ${retval}
}


Then put the following code in the script on your target host:

#########################################################
# target_host_script
#

#
#########################################################
.
.
.

#########################################################
# Get the command line arguments for the SSH call
#########################################################
OSSMENU_COMMAND=`echo ${SSH_ORIGINAL_COMMAND} | nawk '{print $1}`
PARAM=`echo ${SSH_ORIGINAL_COMMAND} | nawk 'NF > 1 {print $2}`
NEWFILE=`echo ${SSH_ORIGINAL_COMMAND} | nawk 'NF > 2 {print $3}`

is_scp=`echo ${OSSMENU_COMMAND} | grep "^scp" | wc -l`

########################################################
# If this is an scp then call the update control source
# code subroutine. This will copy over the latest
# version of the specified script.
# WARNING - do not do an echo or any other output to
# standard out - It will kill the scp command!
########################################################
if [ ${is_scp} -gt 0 ]; then
cd ${HOME}/${newdir}
scp -pt ${NEWFILE}
retval=$?

if [ ${retval} -ne 0 ]; then
echo "Source Code Update Failed: ${retval}"
echo "Press any key to continue"
else
chmod 755 ${NEWFILE}
fi

return ${retval}
fi
}

Its a little confusing and it still throws me each time I use it but it works. Its the only way I know how to get SCP to work when you have set up SSH keys that specify a specific script to run in for a given user.