Run a script on remote host


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Run a script on remote host
# 1  
Old 08-08-2011
Question Run a script on remote host

Hi,

I wish to run a script located on a remote host machineB from machineA.

I am using ssh and running the below on machineA.

However, the ssh does not seem to work and freezes at
Code:
ssh -l wlsadmin machineB -v
Sun_SSH_1.1.2, SSH protocols 1.5/2.0, OpenSSL 0x0090704f
debug1: Reading configuration data /home/wlsadmin/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Rhosts Authentication disabled, originating port will not be trusted.
debug1: ssh_connect: needpriv 0
debug1: Connecting to machineB [129.181.181.72] port 22.

I will provide any inputs required to debug this.

Kindly help.
# 2  
Old 08-08-2011
I think the default timeout for ssh is 30 seconds. Did you wait that long? Maybe add a -o ConnectTimeout=3 to see if there is anything happening after 3 seconds.
Make sure sshd running on machineB, that there is no firewall inbetween etc. If you have nmap, you can also try to do following:
Code:
nmap machineB -p22

# 3  
Old 08-08-2011
It timesout at the desired time. The problem is why does it not work. I do not have nmap. Anything else I can use to test if it can work?

Thanks much.
# 4  
Old 08-08-2011
You did not answer that you made sure, that sshd is running on machineB. There is no firewall between them? Can you reach machineB on any other port than ssh? Start with ping for basic network reachability. Then maybe add ftp or whatever daemons you have up and running on machineB.
# 5  
Old 08-08-2011
Quote:
Originally Posted by zaxxon
You did not answer that you made sure, that sshd is running on machineB. There is no firewall between them? Can you reach machineB on any other port than ssh? Start with ping for basic network reachability. Then maybe add ftp or whatever daemons you have up and running on machineB.
The ping works and so does scp.

How can i check if sshd is running on a machine ?

---------- Post updated at 06:14 AM ---------- Previous update was at 06:04 AM ----------

Ok, It is working one way.

ssh -l wlsadmin machineB
Successful...

However, as i need a script to get executed on machineB, how can i pass that with the 'ssh' command ?

Visa Versa fails with the below.

Code:
ssh -l wlsadmin machineA

wlsadmin@machineB> ssh -l wlsadmin machineA
Permission denied (publickey,keyboard-interactive).
wlsadmin@machineB> ssh -l wlsadmin machineA -v
Sun_SSH_1.1.3, SSH protocols 1.5/2.0, OpenSSL 0x0090704f
debug1: Reading configuration data /home/wlsadmin/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Rhosts Authentication disabled, originating port will not be trusted.
debug1: ssh_connect: needpriv 0
debug1: Connecting to machineA [162.81.181.25] port 22.
debug1: Connection established.
debug1: identity file /home/wlsadmin/.ssh/identity type -1
debug1: identity file /home/wlsadmin/.ssh/id_rsa type -1
debug1: identity file /home/wlsadmin/.ssh/id_dsa type 2
debug1: Logging to host: machineA
debug1: Local user: wlsadmin Remote user: wlsadmin
debug1: Remote protocol version 2.0, remote software version OpenSSH_4.3
debug1: match: OpenSSH_4.3 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-Sun_SSH_1.1.3
debug1: use_engine is 'yes'
debug1: pkcs11 engine initialized, now setting it as default for RSA, DSA, and symmetric ciphers
debug1: pkcs11 engine initialization complete
debug1: Failed to acquire GSS-API credentials for any mechanisms (No credentials were supplied, or the credentials were unavailable or inaccessible
Unknown code 0
)
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: Peer sent proposed langtags, ctos:
debug1: Peer sent proposed langtags, stoc:
debug1: We proposed langtags, ctos: i-default
debug1: We proposed langtags, stoc: i-default
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: dh_gen_key: priv key bits set: 140/256
debug1: bits set: 1037/2048
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host 'machineA' is known and matches the RSA host key.
debug1: Found key in /home/wlsadmin/.ssh/known_hosts:49
debug1: bits set: 1025/2048
debug1: ssh_rsa_verify: signature correct
debug1: newkeys: mode 1
debug1: set_newkeys: setting new keys for 'out' mode
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: newkeys: mode 0
debug1: set_newkeys: setting new keys for 'in' mode
debug1: SSH2_MSG_NEWKEYS received
debug1: done: ssh_kex2.
debug1: send SSH2_MSG_SERVICE_REQUEST
debug1: got SSH2_MSG_SERVICE_ACCEPT
debug1: Authentications that can continue: publickey,keyboard-interactive
debug1: Next authentication method: publickey
debug1: Trying private key: /home/wlsadmin/.ssh/identity
debug1: Trying private key: /home/wlsadmin/.ssh/id_rsa
debug1: Trying public key: /home/wlsadmin/.ssh/id_dsa
debug1: Authentications that can continue: publickey,keyboard-interactive
debug1: No more authentication methods to try.
Permission denied (publickey,keyboard-interactive).
debug1: Calling cleanup 0x34c04(0x0)

# 6  
Old 08-08-2011
I am not sure if I understand completely.
  • Your scp was working but ssh not. That is strange but at least shows, that your sshd is up and working since scp does use the same.
  • Now your ssh works on the command line. Did you supply a password or did you exchange keys? If you exchanged keys and it worked, it should work in a script too without problems. If this is the case, post the script using code tags.
  • If you supplied a password to ssh on the command line, then you have to create a password-less key pair on machineA, add the public key of those to machineB's .ssh/authorized_keys or .ssh/authorized_keys2 to have this way working to connect via ssh/scp/sftp without being asked to provide a password.
# 7  
Old 08-09-2011
Question

Hi,

I am not providing any password to ssh. However, not sure how could I as i do not see any option to provide password.
Code:
ssh
Usage: ssh [options] host [command]
Options:
  -l user     Log in using this user name.
  -n          Redirect input from /dev/null.
  -F config   Config file (default: ~/.ssh/config).
  -A          Enable authentication agent forwarding.
  -a          Disable authentication agent forwarding (default).
  -X          Enable X11 connection forwarding.
  -x          Disable X11 connection forwarding (default).
  -i file     Identity for public key authentication (default: ~/.ssh/identity)
  -t          Tty; allocate a tty even if command is given.
  -T          Do not allocate a tty.
  -v          Verbose; display verbose debugging messages.
              Multiple -v increases verbosity.
  -V          Display version number only.
  -q          Quiet; don't display any warning messages.
  -f          Fork into background after authentication.
  -e char     Set escape character; ``none'' = disable (default: ~).
  -c cipher   Select encryption algorithm
  -m macs     Specify MAC algorithms for protocol version 2.
  -p port     Connect to this port.  Server must be on the same port.
  -L listen-port:host:port   Forward local port to remote address
  -R listen-port:host:port   Forward remote port to local address
              These cause ssh to listen for connections on a port, and
              forward them to the other side by connecting to host:port.
  -D port     Enable dynamic application-level port forwarding.
  -C          Enable compression.
  -N          Do not execute a shell or command.
  -g          Allow remote hosts to connect to forwarded ports.
  -1          Force protocol version 1.
  -2          Force protocol version 2.
  -4          Use IPv4 only.
  -6          Use IPv6 only.
  -o 'option' Process the option as if it was read from a configuration file.
  -s          Invoke command (mandatory) as SSH2 subsystem.
  -b addr     Local IP address.

Can you help me with what option do i use?

Meanwhile, it will be a great help if you could let me know how can i supply the script to be executed on machineB with ssh as I am successful in ssh from machineA to machineB. I will troubleshoot ssh not working other way round post this.

Last edited by Scott; 08-09-2011 at 05:43 AM.. Reason: Added code tags
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Run awk command on remote host

I have below command to check for error logs from last 24 hours from the file : /var/log/messages/ The command is working fine on the local host. sudo awk -F - -vDT="$(date --date="24 hours ago" "+%b %_d %H:%M:%S")" ' DT < $1' /var/log/messages | egrep -i "error|fail" I want to run the... (8 Replies)
Discussion started by: rahul2662
8 Replies

2. Shell Programming and Scripting

Last part of script to remote host not working...

Hi, I got most of the script working, last part which does the ssh to remote and execute the command not working. for SSH in ${HostList}; do echo ${SSH} echo "" SSH2SEND=ssh user@${SSH} curl -v $URL echo $SSH2SEND done error message I am getting ... (5 Replies)
Discussion started by: samnyc
5 Replies

3. Shell Programming and Scripting

Check/get the exit status of a remote command executed on remote host through script

Geeks, Could you please help me out in my script and identify the missing piece. I need to check/get the exit status of a remote command executed on remote host through script and send out an email when process/processes is/are not running on any/all server(s). Here's the complete... (5 Replies)
Discussion started by: lovesaikrishna
5 Replies

4. Shell Programming and Scripting

Run script on remote host

Hi friends, I have two servers. Server A and B. I want to run one script on server A by logging in to server B. Can anyone provide me code for this.? I tried it by using following ssh username@serverA ./script Then it prompt me the password. I give correct password of the server A. but it... (7 Replies)
Discussion started by: Nakul_sh
7 Replies

5. Shell Programming and Scripting

Pause processes in remote host and resume execution in another remote host

Hi, Given addresses of 2 remote machines, using a shell script is it possible to get the state of running processes in "src" stop all the processes in "src" exit out of "src" ssh into "dest" resume the state of executing processes captured in step 1 in "dest" Assumption: "src" is... (3 Replies)
Discussion started by: Saeya Darsan
3 Replies

6. Shell Programming and Scripting

How to run a shell script on a remote host using ftp

Hi, is there a way I can run a shell script through ftp on a remote host? The remote host doesn't have ssh running so I can't use ssh. (7 Replies)
Discussion started by: mrskittles99
7 Replies

7. Shell Programming and Scripting

HTML Code to Run a Script from Remote Unix Host

Hi All, Noticed few posts around this but coudnt get exatcly what i wanted. Thanks for your help again. I have a script running on a remote machine and i normally ssh from putty and run the script manually. Is there anyway that i can write an HTML Code with a button so taht when I Click... (1 Reply)
Discussion started by: robinbannis
1 Replies

8. Shell Programming and Scripting

manage an interactive script on a remote host

OS~AIX 6.1 I'm running an interactive shell script i.e.,waits for a user response a few times while executing, after doing ssh to a AIX server. I'm just wondering what options I have if the ssh connection to the server is lost while executing the script, do I have to run the script again, which in... (2 Replies)
Discussion started by: mbak
2 Replies

9. Shell Programming and Scripting

Plz help me using expect script for remote host

I am newbie in Unix and Expect script, so please help me :( I'm using expect script for remote another host: #!/usr/bin/expect -f set timeout 10 spawn ssh -l root 10.120.18.4 expect "password:" send "password\r" expect "@" interact And now how can i use expect script for access mysql... (2 Replies)
Discussion started by: wormym
2 Replies

10. Shell Programming and Scripting

Run a shell script from one host which connext to remote host and run the commands

I want to write a script which would run from one host say A and connect to other remote host B and then run rest of commands in that host. I tried connecting from A host to B with SSH but after connecting to host B it just getting me inside Host B command prompt. Rest of the script is not running... (6 Replies)
Discussion started by: SN2009
6 Replies
Login or Register to Ask a Question