Operating System - HP-UX
1832181 Members
2815 Online
110038 Solutions
New Discussion

Re: Script to automaticly log on remote server HP-UX 9000

 
SOLVED
Go to solution
Mark_541
Frequent Advisor

Script to automaticly log on remote server HP-UX 9000

Hi,

I am looking to set a script to automaticly login via SSH to an HP9000 server and excecute some commands on the remote server.

I tried with: echo password | ssh user@server1 but no way, the script hangs on the SSH password prompt :-(.

Any help ?
15 REPLIES 15
Rodney Hills
Honored Contributor

Re: Script to automaticly log on remote server HP-UX 9000

If you are using "ssh", then you can configure both systems to have allow non-password required access.

Do a man on "ssh-keygen"

HTH

-- Rod Hills
There be dragons...
Rodney Hills
Honored Contributor

Re: Script to automaticly log on remote server HP-UX 9000

If you need further help with configuring ssh, checkout this HP document-

http://docs.hp.com/en/T1471-90015/ch01s13.html

Rod Hills
There be dragons...
Mark_541
Frequent Advisor

Re: Script to automaticly log on remote server HP-UX 9000

- user is defined only on server1 (remote) and does not exist on the local machine.

- don't you have a good link to this ssh-keygen cause I do not have access to the server now.

- If I do this, may I then run a script such way:

script.sh | ssh user@server1

Thanks in advance
Mark_541
Frequent Advisor

Re: Script to automaticly log on remote server HP-UX 9000

Hi Rodney,

To tell you the truth, I have read the doc but did not find out how to enable my existing user to log on the remote host without password.

Rodney Hills
Honored Contributor
Solution

Re: Script to automaticly log on remote server HP-UX 9000

The only way to feed in a password would be to use "expect" or a module of "perl". Either one requires learning to program in the associated language.

I would really consider setting up the proper ssh keys. In the long run it will make administration a lot easier.

I'm including a word document that also describes configuring SSH on hpux. Hope you find it useful.

Rod Hills
There be dragons...
Mark_541
Frequent Advisor

Re: Script to automaticly log on remote server HP-UX 9000

Rodney,

Is it possible to use SSH with non-password with local-machine/user1 and remote-server/user2 .. cat id_rsa.pub (user1) >> ~/.ssh/authorized_keys (user2)

then ssh user2@remote-machine 'commands'
Jannik
Honored Contributor

Re: Script to automaticly log on remote server HP-UX 9000

It works perfectly with localhost.

Another smart tool is cfengine. You have to configure and program it, but if you make it work it is realy a time saver.

cd .ssh
cat id_dsa.pub >> authorized_keys
ssh localhost
or
ssh localhost "command;command;command"

as you will se it works. If it should by change not work, you will have to make changes in you sshd_config.
jaton
Jannik
Honored Contributor

Re: Script to automaticly log on remote server HP-UX 9000

ups and to change user:

host1 -> localhost (user1):
ssh localhost "command"
ssh -l user2 localhost "command"
or
ssh user2@localhost "command"

from host1 to host2 (remote - user1)
ssh host2 "command"
ssh -l user2 host2 "command"
or
ssh user2@host2 "command"

You just have to have all the keys in place.
You could alsow use the local machine name instead of the localhost. That would make it nice from a scripting point of view.

#!/usr/bin/ksh
SERVERS="s1 s2 s3 s4"
for i in $SERVERS
do
ssh -l root $i "command"
if [ $i = "s1" ]
then
ssh -l user1 $i "command"
fi
done
jaton
Mark_541
Frequent Advisor

Re: Script to automaticly log on remote server HP-UX 9000

Hi Jannik,

My question is about using two different users : user1 on localhost and user2 on remote machine.

BR
Jannik
Honored Contributor

Re: Script to automaticly log on remote server HP-UX 9000

That is no problem.
The thing is that the pub file authenticate with user specified in the pub file to a given remote server and user.

if you are userlocal...

cd ~/.ssh
cat id_dsa.pub >> authorized_keys

and to copy to remote.
cd ~/.ssh
scp ./id_dsa.pub remoteserver:/tmp
ssh -l userremote remoteserver "cat /tmp/id_dsa.pub >> ~/.ssh/authorized_keys; rm
/tmp/id_dsa.pub"
YOU HAVE TO TYPE PASSWORD 2 TIMES...

Now you are ready for the script:

#!/usr/bin/ksh
# filename : /usr/local/bin/ssh_script.ksh
# this will work without password

SERVERS="localserver remoteserver1 remoteserver2"

for i in $SERVERS
do
if [ $i = "localserver" ]
then
ssh -l localuser $i "command"
else
ssh -l remoteuser $i "command"
fi
done

jaton
rmueller58
Valued Contributor

Re: Script to automaticly log on remote server HP-UX 9000

I use expect> to do exactly that. the SSH portion doesn't fly well when trying to use SSH with an expect script.. the best method would be to exchange key set with ssh-keygen.

Then with a script you would be required to interact with the shell.. If you want to automate some type of file activity expect will give you the best results.
Mark_541
Frequent Advisor

Re: Script to automaticly log on remote server HP-UX 9000

Does any one know where I can download BINARY Expect for HP-UX 11.0 (Server K Familiy) ?

BR
Pete Randall
Outstanding Contributor

Re: Script to automaticly log on remote server HP-UX 9000

Mark_541
Frequent Advisor

Re: Script to automaticly log on remote server HP-UX 9000

Any TCLTK Binary ready for HP 11.0 ?
Mark_541
Frequent Advisor

Re: Script to automaticly log on remote server HP-UX 9000

Where can I found any TCLTK Binary ready for HP 11.0 ?