SSHing with multiple hops


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting SSHing with multiple hops
# 1  
Old 06-22-2010
Error SSHing with multiple hops

Hi,
I have got a shell script, which fails to run properly..
I am getting the following error:
"Pseudo-terminal will not be allocated because stdin is not a terminal.

Permission denied (gssapi-keyex,gssapi-with-mic,publickey,keyboard-interactive)."

I SSH to the machine and then run the following Shell script..

Code:
#!/bin/sh
# Configuration vars
ServerMap="/usr/local/scripts/SeverMaps.txt"
Ssh="/usr/bin/ssh"
PATH=/usr/bin:$PATH

##############################################################
#
# Functions
#

ErrorExit() {

    echo $1
    echo "Press \"Enter\" to exit."

    # Wait for user to press "enter", we are not intereseted in anything else
    read SomeThing

    exit

}

PrintHelp() {
    echo
    echo "Version $Version"
    echo
    ErrorExit " "

    return
}

##############################################################
#
# Main Body
#
# $1 is "Location", $2 is "Node"
#

# Make sure both vars are present
if [ "$1" = "-v" ]; then
    echo
    echo "-v switch specified, printing version number:"
    echo "Version $Version"
    echo
    exit
fi

if [ -z "$2" ]; then
    echo ""
    echo "Error: Missing arguments"
    echo "Location = $1, Node = $2."
    PrintHelp
fi

# Make sure the USER env var is present
if [ -z "$USER" ]; then
    ErrorExit "Error: Environment not set correcty (USER not specified)."
fi

# Get a count of lines matching $1, more or less than one is invalid.
Count=`cat $ServerMap | grep -v "#" | grep -c "^$1"`
if [ $Count -ne 1 ]; then
    ErrorExit "Error: Too many or no matches for Location name $1 in map file. ($Count)"
fi

# Get the name of the remote server
Server=`grep "^$1" $ServerMap | grep -v "#" | awk '{print $2}'`
if [ -z "$Server" ]; then
    ErrorExit "Error: Server name for $1 not specifed in map file."
fi


# Get this server FQDN
ThisServer="`hostname | cut -d . -f 1`.`cat /etc/resolv.conf | grep domain | awk '{print $2}'`"

if [ "$ThisServer" = "$Server" ]; then
    # We are launching from the same server, no need to ssh

    # Let the user know what is happening.
    echo "SSH to device $2"

    # Call the command line
    $Ssh -t $USER@$2

else
    # Server is a remote server, we need to ssh       
    # Call the command line
    $Ssh -t $USER@$Server $NcoPipe $SshR -t $USER@$2
fi


Could someone help me figure out, why this error comes up, and how i can resolve this issue??

Thanks In Advance,
BlubSmilie

Last edited by Scott; 06-22-2010 at 07:36 AM.. Reason: Fixed CODE TAGS - [code], not <code>
# 2  
Old 06-24-2010
i have got a similar problem, and people here solved it: https://www.unix.com/shell-programmin...rl-script.html
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

scp over multiple hops

Hi friends, I am trying to scp a file from server A to Server C via Server B (which is jump host) from Server A to Server B i have one pem key. from server B to server C I have different Pem key.. what I tried scp -r -o ProxyCommand="ssh -W %h:%p ec2-user@1.4.5.5 dmu.sh... (7 Replies)
Discussion started by: onenessboy
7 Replies

2. Shell Programming and Scripting

Ssh multiple hops to execute commands with arguments

Hi I need to write a script to ssh through several hops (e.g. HostA-HostB-HostC-HostD), where Host A does not have direct assess to HostC ; HostB cannot access HostD directly. when I ssh 3 hops and run command with arg1, arg2 and redirect the output to a file, e.g. HostA> ssh -t HostB ssh -t... (3 Replies)
Discussion started by: chiensh
3 Replies

3. UNIX for Advanced & Expert Users

SSHing into an IP restricted server via another machine

Hi, Apologies if this belongs in the beginner area. So.. The server I need to log into only allows logins from certain IP addresses. One of those IP's is my home computer, I can easily ssh into my home computer from elsewhere, and would then try to login to my work computer from there, but it... (1 Reply)
Discussion started by: Buckaroo Banzai
1 Replies

4. IP Networking

http over ssh tunnel using multiple hops

Hello, I got an application on a linux server that I would like to access using https and a URL. I would like to create a ssh tunnel. But, let's say the app is on box C, but box C can only be accessed through box B, that can be accessed only through box A. I would like to create the ssh tunnel... (0 Replies)
Discussion started by: Pouchie1
0 Replies

5. IP Networking

ssh tunnel with 2 hops and key

I have situation: - localhost L - server A - server B (currently accessible only from B, but it have key of my localhost - added when L have different location and can access directly to B) problem: how set tunnel from L to B and use key from localhost (I don't remember password to B)? I... (0 Replies)
Discussion started by: lessmore
0 Replies

6. Solaris

Help with executing multiple remote commands after multiple hops

Hi SSHers, I have embedded this below code in my shell script.. /usr/bin/ssh -t $USER@$SERVER1 /usr/bin/ssh $USER2@S$SERVER2 echo uptime:`/opt/OV/bin/snmpget -r 0 -t 60 $nodeName system.3.0 | cut -d: -f3-5` SSH to both these servers are public-key authenticated, so things run... (13 Replies)
Discussion started by: LinuxUser2008
13 Replies

7. Shell Programming and Scripting

Redirecting output to a local file after sshing

ssh $USR@$host /bin/bash <<EOF awk ' BEGIN{f=0} !f { s=$0; sub(/,.+/, "", s); gsub(//, " ", s); t=(systime()-mktime(s)); if(t<=14400) f=1 } f ' /home/error.log >> error.txt EOFWe are trying to connect to a remote server through ssh and read values from error.log within last 4 hours.However, the... (3 Replies)
Discussion started by: Deepthz
3 Replies

8. Shell Programming and Scripting

Problem sshing to multiple servers while in a loop

I have the following block from a script (it's not the entire script, but I'm confident it's all that is pertinent) echo "$SESSIONS"|while read ID;do ASSETID=$(echo "$ERRORS"|grep -i "$ID"|grep FX_Media_Session_Playlist::init_playlist|grep -i asset_id=|awk '{print $11}') BLADE=$(echo... (2 Replies)
Discussion started by: DeCoTwc
2 Replies

9. UNIX for Advanced & Expert Users

Too many hops error in sendmail

I am running SCO openserver 6 with sendmail as my mta I have a customer that sends me mail and occasionally some of them get bounced by my machine with a too many hops error. the header shows that it hops around their servers several times before getting to me and I know this is something that they... (3 Replies)
Discussion started by: garycrow
3 Replies

10. Shell Programming and Scripting

SSHing from a shell script

I want to connect to a remote server which I have a mySQL DB on, and do a mysqldump so I have a backup. I will likely schedule this with CRON to run every night. However, to make any changes to the mySQL server I have to SSH onto it, binding my local mySQL port to the remote one. Is this... (1 Reply)
Discussion started by: eludlow
1 Replies
Login or Register to Ask a Question