The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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



SUN Solaris The Solaris Operating System, usually known simply as Solaris, is a free Unix-based operating system introduced by Sun Microsystems .

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-07-2007
PabloCruise77 PabloCruise77 is offline
Registered User
  
 

Join Date: Feb 2007
Location: Loomis, CA
Posts: 5
SSH/SCP Question

Thanks to this forum, I was able to get a program running that uses SSH to control programs running on other hosts. Now I'd like to enhance it.

The control program on the target hosts occassionally needs to be updated. Updating the menu program on the source host is easy as it is on one host. The control program runs on several dozen.

Since I have the SSH connection and a config file containing a list of target hosts and login Ids, I figured I could modify my menu program to automate the sending of the updated control program out to the target servers.

Tried two ways:

1. First, I tried to perform an SCP in the menu program to one of the target hosts. When I do that the SSH takes over. Since my control program is listed in the key in the authorized_keys files on the target hosts, it tries to run my control program. It fails, since it checks for a valid command and other parameters that are sent over in the SSH_ORIGINAL_COMMAND. A similiar condition occurs when I attempt to SCP from the command line.

2. Then I tried to create a new command in my menu program, UPD, that it would send to the control program on the target hosts. Once there, the target host would run new code that would do an SCP of the new code from the source host to the target host. When I did that it exited on the SCP saying "Connection refused".

For my first attempt, does setting up a command in the SSH key, disable the use of SCP from the source to target host?

For my second attempt, is the failure the result of no SSH key? I have keys set up to allow SSH access from the source to the targets. On the target, if I perform an SCP to copy code from the source to the target, do I need to set up keys again?
  #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.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:06 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0