How to run command on remote server?

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers How to run command on remote server?
# 1  
Old 11-14-2016
How to run command on remote server?

Hi

I am trying to write a script which when I run from server A it execute few command on another server say B and show me the output.

below is the script but it is not showing me the o/p of B machine but instead showing me A machine o/p every time.


Code:
#!/bin/bash
for i in `cat IP`
do
ssh root@$i
hostname
mt -t /dev/nst0 status
echo done
done

Regards,
Scriptor

Last edited by joeyg; 11-17-2016 at 04:53 PM..
# 2  
Old 11-14-2016
try this..

Code:
#!/bin/bash
for i in `cat IP`
do
ssh root@$i "hostname;mt -t /dev/nst0 status;echo done" < /dev/null
done

# 3  
Old 11-14-2016
Or perhaps:-
Code:
while read i
do
   ssh root@$i "hostname;mt -t /dev/nst0 status;echo done" < /dev/null
done < IP


Robin
This User Gave Thanks to rbatte1 For This Post:
# 4  
Old 11-14-2016
Quote:
Originally Posted by itkamaraj
try this..

Code:
#!/bin/bash
for i in `cat IP`
do
ssh root@$i "hostname;mt -t /dev/nst0 status;echo done" < /dev/null
done

Dangerous Backticks
# 5  
Old 11-15-2016
i tried below script but it is not working.

Code:
 
 #!/bin/bash 
        for i in `cat O_IP`
        do
        ssh oww@$i ' 
        hostname
        USER='root'
        PASSWORD='abcd1234'
        su - $USER
        $PASSWORD
        mt -f /dev/nst0 status
        echo done
        '
        done

# 6  
Old 11-15-2016
Understandable, as nested single quotes usually don't.
Did you try rbatte1's proposal? To what avail?
# 7  
Old 11-16-2016
the problem in this code is it is not accepting the password.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Ubuntu

Run a script at remote server without ssh password

Hello, What I want to do is to run a file on remote server by running a script at localhost but script should not ask ssh password of my remote server when script is executed. Scenario1: To copy files from server2 to data server:$ scp -r root@server2_ip:/var/www/html/*.* /var/ When I enter... (6 Replies)
Discussion started by: baris35
6 Replies

2. Shell Programming and Scripting

How to run commands on remote server using ssh password less authentication?

Hi, I need to run a script located in a directory on remote server by using ssh authentication from my local unix server. Can anyone help me in this. I have tried the below command. It worked for echo command but when i tried to open a file using cat command it is showing "cat: cannot open... (6 Replies)
Discussion started by: ssk250
6 Replies

3. Shell Programming and Scripting

Run scripts on remote server

I have a sql script in my parent server - host1 i can do a passwordless ssh to remote server - host1a and host1b Can i run the sql script which is present in host1 by connecting to host1a and host1b. Should i place the sql script in host1a and host1b ? Is there a way i can run without placing... (2 Replies)
Discussion started by: Nagesh_1985
2 Replies

4. Shell Programming and Scripting

To run a shell script in remote server from windows batch file

Hi all, i need to run a shell script on remote server. I have created file .bat file in windows server with following code, c:\Users\Desktop\putty.exe -ssh -pw password user@server ./script.sh i need to run the script.sh in my remote server Above command is not working, any... (4 Replies)
Discussion started by: rammm
4 Replies

5. Shell Programming and Scripting

Until string from remote command equals value run remote command

I solved my issue by using the following code #!/bin/bash function GET_STATUS { #values Active Passive Failed ssh -a localhost '/home/user/fakecommand.sh' } STATE="unknown" until ] do echo $STATE sleep 5 STATUS=`GET_STATUS` echo $STATUS | grep Active &&... (1 Reply)
Discussion started by: $scipt_Kid
1 Replies

6. Shell Programming and Scripting

Need script to run the command in remote server

hi, I need script to perform below task. 1. Read the IP address 2. copy the script from origin server to destination. 3. get root access on destination server 4. run the script on destination server 5. return to the origin server Code: #!/bin/bash echo "Enter Server IP... (5 Replies)
Discussion started by: bapu1981
5 Replies

7. Shell Programming and Scripting

Copy and run that script in Remote server

Hi All, I need script to perform below task. 1. I have a script in one server and need to copy this script to remote server 2. login in to remote server 3. run the script which i copied to this server. #!/bin/bash read a scp /tmp/script.sh user@hostname:/tmp ssh user@$a ./scirpt.sh ... (2 Replies)
Discussion started by: bapu1981
2 Replies

8. Shell Programming and Scripting

Need help on how to exit a script run on a server from a remote server

hi, I am using the below line to run a script from remote server(say server A) to another server(say server B). ssh username@servername ksh script name. The issue is the script logs into server B, executes the script on server B, transfers the file to server A but does not exit from... (4 Replies)
Discussion started by: yohasini
4 Replies

9. Shell Programming and Scripting

Ability to run sas prog on remote server using SSH

Hi, I am trying to run a sas prog on a remote server using ssh. I have got the command that I am using in the below paragraph. With it, I was able to run shell scripts but when I tried 'sas' it errored out. I have got my keys exchanged so when I say ssh serverA I automatically connect to my... (4 Replies)
Discussion started by: coolavi
4 Replies

10. Shell Programming and Scripting

run a application from a remote server via script?

I have a ksh script that does a bunch of things, then runs telnet server_b I then manually login, manually run one command (which launches an application with display back to my workstation), then logout at which point the main script takes back over, runs something else, then ends. Is... (4 Replies)
Discussion started by: yankee428
4 Replies
Login or Register to Ask a Question