Run multiple commands in ssh


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Run multiple commands in ssh
# 1  
Old 05-06-2014
Run multiple commands in ssh

Hi All,

I have the below requirement.
I want to copy the local file to remote after that i need to run the local script on a remote machine.When i use two ssh commnds i can achieve this. But i want to achieve this using one ssh command.

Below command to copy the local file to remote
Code:
ssh -q user@host cat < $datadir/test.txt ">" /home_dir/test.txt

below command i used to run local script on remote.
Code:
ssh -q user@host "ksh -s" < $scriptdir/test.sh "$omsDir"

But when i try to combine the two commads its not working properly.
I tried the below code

Code:
ssh -q user@host  cat < $datadir/test.txt ">" /home_dir/test.txt ; `ksh -s` < $scriptdir/test.sh "$omsDir"

when i tried with the above code i guess script is not working in local i.e it tries to search for for the file test.txt to copy in remote instead of local same way test.sh is also searching in remote.
Please help me in this.
# 2  
Old 05-06-2014
Code:
ssh -q user@host << ! > /home_dir/test.txt
cat < $datadir/test.txt
ksh -s
$scriptdir/test.sh "$omsDir"
exit
!

This User Gave Thanks to SriniShoo For This Post:
# 3  
Old 05-07-2014
The problem is that ssh/sshd take only one stdin channel (unless they provide special options that I haven't discovered yet).
I cannot see that the previous post solves it.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Ssh to multiple hosts and then run multiple for loops under remote session

Hello, I am trying to login to multiple servers and i have to run multiple loops to gather some details..Could you please help me out. I am specifically facing issues while running for loops. I have to run multiple for loops in else condition. but the below code is giving errors in for... (2 Replies)
Discussion started by: mohit_vardhani
2 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

How to automatically run commands after SSH and SUDO not working?

I'm working on a script to SSH and SUDO as (sap user sidadm) then automatically run commands that the sidadm user can run such as R3trans -v, tp, etc.. I can SSH without password and SUDO.. but the commands don't run after I SSH and SUDO to the sidadm user...here is the commands that I've... (2 Replies)
Discussion started by: icemanj
2 Replies

4. UNIX for Dummies Questions & Answers

Run multiple commands

Hi All, Is it possible to run second/multiple commands at a time in script before the completion/return of first command? Pls reply. (5 Replies)
Discussion started by: cns1710
5 Replies

5. Shell Programming and Scripting

SSH + multiple commands

Sorry for the basic question here, but I can't seem to find an answer anywhere. I want to alias a command that will ssh and then open up bbedit all in 1 command. alias bbb 'ssh NAME@SERVER bbedit' returns: bash: bbedit: command not found It returns this same thing for anything except... (1 Reply)
Discussion started by: busdriver
1 Replies

6. SuSE

Allow multiple users to run several root commands

I am using SUSE Linux Enterprise Server 10 SP2 (i586) and I had earlier ammended my sudoers file to allow users to become root user with "sudo su - " command Now I am trying to add multiple users to the sudoers file to run several commands such as restarting the server, restarting the nagios... (9 Replies)
Discussion started by: hedkandi
9 Replies

7. Shell Programming and Scripting

Create a list of commands in a central location, and then run them all remotely through a ssh here

I'm trying to write a script that in the end will from one central location hop to a bunch of servers and then run a series of ping tests. The thing is, the list of devices that needs to be pinged is going to be different for each server. So what I want to do is be able to do is read through the... (0 Replies)
Discussion started by: DeCoTwc
0 Replies

8. Shell Programming and Scripting

Run multiple commands in $() without opening a new shell

The code below works, but takes too many lines and looks awkward: db2 "export to $filename of del select * from $table with ur"|tee -a $LOGFILE|awk '/Number of rows exported:/ {print $5}' > numrows.tmp numrows=$(cat numrows.tmp) rm numrows.tmp When I try the... (2 Replies)
Discussion started by: akar_naveen
2 Replies

9. UNIX for Dummies Questions & Answers

Command to run multiple commands from a file.

I need a command, which could run mutliple commands from a file. Let's say, I have mv fileA1 fileB1 mv fileA2 fileB2 ..... mv fileA20 fileB20 I put these commands in a file, then I need a command to run the file as a whole so that I don't need to type 20 times... Anyone tell me how to... (8 Replies)
Discussion started by: kaixinsjtu
8 Replies

10. Shell Programming and Scripting

How to run a set of commands through ssh

I need to run a set of commands on a remote machine using ssh. it should also collect output and return status of each command. Can someone help me how to do this? (1 Reply)
Discussion started by: vickylife
1 Replies
Login or Register to Ask a Question