Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

connecting via ssh in script

Status
Not open for further replies.

spookie

Programmer
May 30, 2001
655
IN
Hi,

I have come across a command in a perl script which i am not able to understand.
The command is as below
Code:
qq|ssh -p $p $u\@$f abc xyz $v \| grep $UCbs|;
Note:abc and xyz is actually something else.

At first look, it seems that its trying to connect some host via ssh but what is abc and xyz as they don't seem to be any unix related parameters but just strings.

Can someone explain what is it trying to do..I am trying to debug it because the above command is failing.

Any input is welcome.



--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
It appears to be constructing the command line torun the command abc with the parameters xyz and $v (or the contents thereof) on the remote host $f. It is connecting using the username $u to the port number $p.

Note that the line you quoted doesn't appear to be actually running the command, just defining the string containing the command line, which it is probably going to use later?

Annihilannic.
 
Thanks for the explanation Annihilannic.

One doubt though that how is the command connects to host w/o providing a password.

I am still to come to definite conclusion, but it seems that the command is unable to connect to the host $f. The error is 'Connection to host1 closed by remote host'.

The strange thing here is the script was running fine till yestrday. I doubt the username has been changed for the host.

Thanks in advace for any input.

--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
Since it's using SSH, the passwordless authentication must be set up using either a host or user public/private key pair.

If you can figure out the values of $p, $u and $f you should be able to substitute them into the command and run an innocuous test outside the script, e.g.

[tt]ssh -p 1234 username@hostname date[/tt]

The results of that should give you an idea whether the problem is with the authentication or elsewhere.

Annihilannic.
 
Thanks for the valuable input, Annihilannic.

I tried what you suggested :
Code:
ssh -p 1234 username@hostname date

and following is the output i got

Could not create directory '/somedirectory/.ssh'.
The authenticity of host 'host1' can't be established.
RSA key fingerprint is 11:22:33:44
Are you sure you want to continue connecting (yes/no)?

Does this mean authenticity is failed. If so why does it ask again if you want to continue connecting.

Can you please help here.


--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
Check that username has writeable home directory. .ssh is where sshd keeps things like the known_hosts file, authorized_keys file ,etc.

sshd tries to compare the known_hosts (host key) to the actual host to detect if some type of spoofing is happening. It also writes the host key when a valid connect occurs.

Remember that ssh can use different types of authentication, without a homedir and .ssh dir auth will fail but password authentication can be accomplished, hence it asks to continue.

Use the -v option in ssh to see what is actually happening in the negotiation.

eugene
 
Was this working previously? If so, then it appears that the .ssh subdirectory of the user's home directory on the source machine has somehow vanished...?

Annihilannic.
 
Thanks for the info elgrandeperro, Annihilannic.

elgrandeperro,
Can you please elaborate how can I use -v option in ssh.

--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
Also does the .ssh directory gets created with the every connection or it gets created once and updates itself with every connection. I am asking this because if it gets created only once, then it must have got deleted somehow.

Also it is strange that why a user does not have permission to create directiory within his own home directory.
(we are not owner of the remote host and thats why trying to figure out what's wrong).

Sorry for the basic questions but i am dealing with this for the first time.



--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
Hi again,

I tried the command now,
Code:
ssh -p 1234 username@hostname date

and it gives error
Connection to host1 closed by remote host.

and nothing else.

I am unable to find what is going on here.

Can you please help.

--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
just add the -v as an argument, and you will get debug output:

ssh -v -p 1234 username@hostname date

My guess is that your homedir is not there or has the wrong perms and it doesn't appear that simple password authentication is allowed

The .ssh directory must be already created, sshd cannot create it.

eugene
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top