Execute script located on a remote machine


 
Thread Tools Search this Thread
Special Forums IP Networking Execute script located on a remote machine
# 15  
Old 07-05-2012
Lightbulb

Quote:
Originally Posted by spynappels
Ok, first things first.

Can you describe in as much detail as you can what the network topology of your systems is?

Also, can you confirm which flavour of Unix you are running on each server?

Lastly, can you check if home directories are mounted via nfs or use some other distributed file system?

I'll take this as far as I can and hopefully get enough info to point to the right place to solve this.
We have a setup whereby we cannot login to ServerB directly by using putty.
We have to first login to ServerA by providing username and password and it somehow takes us to serverB and prompts for the password for my login id for ServerB. Providing the password again logs me onto ServerB where I have a script test.sh which I need to execute.
I wanted to automate the execution of script test.sh on ServerB from my local windows machine hence I wrote the below command.
Code:
C:\Program Files\PuTTY>plink -agent user1@ServerA "chmod +x /export/home/user1/test.sh; sh /export/home/user1/test.sh" -v

This command logs me onto ServerA but does not take me to ServerB hence test.sh script is not found.
I cannot logon to serverB due to this hopping concept in place.
Kindly help me with some work around.
Note: ServerA and ServerB both are unix servers

This was basically done inorder to disable VPN connectivity from remote locations.

Quote:
Also, can you confirm which flavour of Unix you are running on each server?
Linux ServerA 2.6.18-164.11.1.el5PAE #1 SMP Wed Jan 6 13:43:57 EST 2010 i686 i6
86 i386 GNU/Linux

and

SunOS ServerB 5.10 Generic_147440-13 sun4u sparc SUNW,Ultra-80

These are basically output of uname -a

Quote:
Lastly, can you check if home directories are mounted via nfs or use some other distributed file system?
How can I find this ? any command ?
# 16  
Old 07-05-2012
Quote:
Originally Posted by mohtashims
How can I find this ? any command ?
Don't worry, I think that's enough info for now. Let me have a think about this.


Just two clarifications required...

Do you need to scp the file to ServerB every time or is it only once and it will live on ServerB forever after that?
Can you copy keys from one server to another to set up key-based (passwordless) logins?

I think the answer will involve essentially running a command or script on ServerA to run a command on ServerB.
# 17  
Old 07-05-2012
The file on serverB has to be executable, when you scp the script file to serverB, even if it started out with the executable permission bits set, they will likely be gone on the remote box. Depends on your umask setting on the remote box.

The simple way to handle all this. Use sftp to move the file:
Code:
sftp snappels@serverB
Password> farkle
put myscript.sh
chmod 775 myscript.sh
exit

Do not use scp. Now the file is over on serverB and anytime you run it via ssh from serverA it will work for you.
# 18  
Old 07-05-2012
Quote:
Originally Posted by jim mcnamara
The file on serverB has to be executable, when you scp the script file to serverB, even if it started out with the executable permission bits set, they will likely be gone on the remote box. Depends on your umask setting on the remote box.

The simple way to handle all this. Use sftp to move the file:
Code:
sftp snappels@serverB
Password> farkle
put myscript.sh
chmod 775 myscript.sh
exit

Do not use scp. Now the file is over on serverB and anytime you run it via ssh from serverA it will work for you.
The problem is that there is no diect access to ServerB as per the OPs previous post, if this was not the case my first solution would have worked fine.
# 19  
Old 07-06-2012
Question

Quote:
Originally Posted by spynappels
The problem is that there is no diect access to ServerB as per the OPs previous post, if this was not the case my first solution would have worked fine.
There is 0 work on ServerA. I dont need the scripts or any file on serverA. Its just a HOP server that we are given access to. Login to this server helps auto jump to the actual client machine which is ServerB.

There is no network connection between our windows workstation and serverB. Network Timesout if we try to connect to.

I did not get the quoted workaround?

Quote:
sftp snappels@serverBPassword> farkleput myscript.shchmod 775 myscript.shexit
What would I need to run at windows inorder to get the script running on serverB by hopping to it via serverA.

I have a simple straight forward question.

If login to ServerA by putty helps auto jump to serverB with the need of the password to be entered the second time why doesn't or why couldn't plink or any alternate tool do the same ?
# 20  
Old 07-06-2012
When you connect using PuTTY, are you just putting the details in and connecting, or are you using some saved session?

It could be that the saved session has the hop saved in as a command to execute on login to serverA. If it is a saved session, load it but don't initiate the connection, and go to the SSH Tab/Category. There is an entry there where you can specify a remote command such as that required to ssh from ServerA to ServerB, so you automatically get forwarded from ServerA to ServerB when you login to ServerA using the saved PuTTY profile.

I think you can direct Plink to use the same profiles, but I'm not 100% certain of that. You could look at the PuTTY documentation to see the details. PuTTY User Manual

If this is the case, we just need to figure out how to get the script from the Windows box to ServerB, this could probably be done using 2 separate scp commands within a single script.

---------- Post updated at 09:20 AM ---------- Previous update was at 08:50 AM ----------

Quote:
Originally Posted by spynappels
I think you can direct Plink to use the same profiles, but I'm not 100% certain of that. You could look at the PuTTY documentation to see the details. PuTTY User Manual
I just tested this and if you have a saved session in PuTTY, you can use the same session in plink
Code:
plink -load <<session-name>>

If the session name has a space in it, you can put it into double quotes.

I also checked if a saved session has a "ssh user@anotherhost" command saved in the SSH category, it will lok like it directly logs into anotherhost without an internediate shell, and you should just be asked for the password for 'server' first, and then for 'anotherserver'. The good news is this works exactly the same if this session is then used for a plink connection.
# 21  
Old 07-06-2012
Question

Quote:
Originally Posted by spynappels
When you connect using PuTTY, are you just putting the details in and connecting, or are you using some saved session?

It could be that the saved session has the hop saved in as a command to execute on login to serverA. If it is a saved session, load it but don't initiate the connection, and go to the SSH Tab/Category. There is an entry there where you can specify a remote command such as that required to ssh from ServerA to ServerB, so you automatically get forwarded from ServerA to ServerB when you login to ServerA using the saved PuTTY profile.

I think you can direct Plink to use the same profiles, but I'm not 100% certain of that. You could look at the PuTTY documentation to see the details. PuTTY User Manual

If this is the case, we just need to figure out how to get the script from the Windows box to ServerB, this could probably be done using 2 separate scp commands within a single script.

---------- Post updated at 09:20 AM ---------- Previous update was at 08:50 AM ----------



I just tested this and if you have a saved session in PuTTY, you can use the same session in plink
Code:
plink -load <<session-name>>

If the session name has a space in it, you can put it into double quotes.

I also checked if a saved session has a "ssh user@anotherhost" command saved in the SSH category, it will lok like it directly logs into anotherhost without an internediate shell, and you should just be asked for the password for 'server' first, and then for 'anotherserver'. The good news is this works exactly the same if this session is then used for a plink connection.
Please see if the below helps.

I tried this...

C:\Program Files\PuTTY>plink -v -ssh ms104u@144.160.112.17 ssh ms104u@132.201.72.229
Looking up host "144.160.112.17"
Connecting to 144.160.112.17 port 22
Server version: SSH-2.0-OpenSSH_4.3
We claim version: SSH-2.0-PuTTY_Release_0.60
Using SSH protocol version 2
Doing Diffie-Hellman group exchange
Doing Diffie-Hellman key exchange with hash SHA-1
Host key fingerprint is:
ssh-rsa 1024 07:ce:4c:e5:dd:57:49:d7:a7:c2:b7:0b:be:f7:0d:f4
Initialised AES-256 SDCTR client->server encryption
Initialised HMAC-SHA1 client->server MAC algorithm
Initialised AES-256 SDCTR server->client encryption
Initialised HMAC-SHA1 server->client MAC algorithm
Using username "ms104u".
Using keyboard-interactive authentication.
Password:
Access granted
Opened channel for session
Started a shell/command
Pseudo-terminal will not be allocated because stdin is not a terminal.
This system is restricted solely to authorized users for legitimate
business purposes only. The actual or attempted unauthorized access, use, or
modification of this system is strictly prohibited by . Unauthorized
users are subject to Company disciplinary proceedings and/or criminal and
civil penalties under state, federal, or other applicable domestic and
foreign laws. The use of this system may be monitored and recorded for
administrative and security reasons. Anyone accessing this system expressly
consents to such monitoring and is advised that if monitoring reveals
possible evidence of criminal activity, may provide the evidence of
such activity to law enforcement officials. All users must comply with AT&T
company policies regarding the protection of information assets.
IMPORTANT NOTICE: See here for authentication requirements to be enforced:
Permission denied, please try again.
Server sent command exit status 255
Disconnected: All channels closed
Permission denied, please try again.
Received disconnect from 132.201.72.229: 2: Too many authentication failures for
ms104u


where ms104u=user1, 144.160.112.17=ServerA and 132.201.72.229
=ServerB
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How can I execute local script on remote machine and include arguments?

I have a script in local server cd /home/dell/work/BOP/testdir ./processchk po (here processchk is a script & po is passed as an argument) Now I want to execute this script from remote server ssh $username@$hostname "cd /home/dell/work/BOP/testdir; ./processchk po" But Its getting error... (9 Replies)
Discussion started by: manohar2013
9 Replies

2. Shell Programming and Scripting

Execute shell script on remote machine

I want to execute a shell script(set of commands) on remote machine and that script takes input from text file(local machine). Please refer below: ssh user@hostname 'bash -s'< ./test.sh file.txt But i got the error file.txt doesn't exist. Can anyone help me on this. Content of test.sh: ... (2 Replies)
Discussion started by: manishtri88
2 Replies

3. UNIX for Dummies Questions & Answers

Execute shell script in remote machine

Hi All, We have 2 servers A and B. B is having a sctipt called b.sh in path /home/dev/scripts. Now my requirement is i want to execute b.sh from server A. Kindly help me. (3 Replies)
Discussion started by: Girish19
3 Replies

4. Shell Programming and Scripting

How to execute the same script on another machine

Recently, I need to generate a lot of files from a few master files. In fact, if I relogin to the server machine, my operating would be much faster. My question is this: Can I write a script in which the current path can be automatically saved and relogin to the server to execute my command in the... (0 Replies)
Discussion started by: jiao
0 Replies

5. Shell Programming and Scripting

To execute the same script in another machine

We have a few machines which share the same directory. How can I execute the same script under that directory in different machine while I am using mine? (1 Reply)
Discussion started by: jiao
1 Replies

6. Shell Programming and Scripting

unix shell script which inserts some records into a file located in remote servers...

All, I need to write an unix shell script which inserts some records into a file located in remote servers. * Get the input from the user and insert according the first row. It should be in ascending order. 123451,XA,ABA 123452,XB,ABB 123453,XC,ABC 123455,XE,ABE 123456,XF,ABF 123458,XG,ABG... (2 Replies)
Discussion started by: techychap
2 Replies

7. Shell Programming and Scripting

Change user on remote machine and execute script!

Hi, I need to login into remote server and execute a shell script over there. As of now i am making use of ssh command ssh primUser@135.254.242.2 sh /poll.sh I am logging in as primUser but unless i change the user to root the script execution on the remote machine is not possible. ... (5 Replies)
Discussion started by: goutham4u
5 Replies

8. Shell Programming and Scripting

How to execute a script hosted on a machine from a different machine

Hi everyone I intend to trigger a script from one machine say mc1 that actually excutes on different machine say mc2 and redirect the logs to that machine mc2. I tried to use nohup <nfs location of machine >/script.sh > <nfs location of machine >/script.log 2>&1 & nfs location of... (2 Replies)
Discussion started by: harneetmakol
2 Replies

9. Shell Programming and Scripting

Execute command from terminal on remote machine

Hi All, I want to execute some commands on unix machine from the mac machne. I have two options for doing so, I am confused which is the best way of doing. Here are two options. Requirement: Execute command on the remote server machine. Commands to be executed itself contain arguments to be... (0 Replies)
Discussion started by: Ranu
0 Replies

10. Shell Programming and Scripting

how to execute a script on remote machine

hi unix guru's i am new to unix shell programming. i found a trouble in executing a script(bali.ksh) which is available on serverA with username xyza, this script contains sqlplus command to retrive the data from the database available on other serverC. Now i need to run the above script... (4 Replies)
Discussion started by: balireddy_77
4 Replies
Login or Register to Ask a Question