Executing commands in different server


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Executing commands in different server
# 1  
Old 07-23-2010
Question Executing commands in different server

Hi Friends,

I have a situation here, where I have a script running in one server, namely "SERVER1". Within this script which runs in SERVER1, I have a set of commands which has to connect to a different server (namely "SERVER2") and execute the commands accordingly. I have no experience at all in scripting and will be grateful if somebody could help me sort this out.

Please find below the script which I have developed so far.
The problem is, once the script reaches "ssh SERVER2", it connect to the server and the prompt appears (server2 prompt).
What I need is, the script has to connect to SERVER2 and execute the commands in that server and complete the rest of the commands in the script.

Code:
#! /usr/bin/ksh
echo "Please choose any one of the below options:" 
echo "1)apple" 
echo "2)mango" 
echo "3)grapes" 
echo "4)banana\n" 
read i;
case i in
1)  ssh SERVER2
 cd /home/apple
 FAILED_FILE=`ls apple*`
 if [ -f  ${FAILED_FILE} ]; then
  cp -p ${FAILED_FILE} /home/apple/delivered/
 fi
exit
echo "Copy success"
 ;;
*) echo "Invalid option selected"
esac

# 2  
Old 07-26-2010
Here is the ssh part try.
Code:
(
 echo "cd /home/apple"
 another command..
 .......
 
 echo "~."
) ssh -T SERVER2

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Executing commands sequentially

Hello. I am new in shell script. Could anyone help me? I have un shell script. I need each command in it be sequentielly, when the first command ends the second starts. When the second ends et third starts, and so on Thanks in adavance (1 Reply)
Discussion started by: nurinolo
1 Replies

2. Shell Programming and Scripting

executing commands in remote server using ssh

I have some commands which need to be executed in remote machine. I have Linux Server from where I need to connect to Solaris server using ssh and then declare some variable over there and run some commands. I don't want to call a script which is present in Solaris server from Linux server... (7 Replies)
Discussion started by: maitree
7 Replies

3. Shell Programming and Scripting

Executing two commands in parallel

Hi, I am stuck into a situation where i want to execute a command in my shell script well along with a previous command in order to achieve something but i am not figuring out a way. here is a snippet: service management restart rm -rf lock.file in the above, if you see, i am trying to... (5 Replies)
Discussion started by: sunrexstar
5 Replies

4. Shell Programming and Scripting

Executing commands

I need to execute a command to run my script several times with varying parameters perl ex.pl -b 130198 -e 130884 -c plot plot.txt 1_plot.txt perl ex.pl -b 1345 -e 1308 -c plot plot.txt 2_plot.txt perl ex.pl -b 1345567 -e 130898 -c plot plot.txt 3_plot.txt . . . 100's of excutions ... (2 Replies)
Discussion started by: Lucky Ali
2 Replies

5. Shell Programming and Scripting

Executing many commands at once

Hi, I want to run these two commands one after the other. awk 'BEGIN {OFS="\t"} {print $2}' sort -u rather than typing awk 'BEGIN {OFS="\t"} {print $2}' file1 > file2, then sort -u file2 > file3. Is it possible to run both commands on file1 then get output file3? Its kinda hard for... (5 Replies)
Discussion started by: kylle345
5 Replies

6. Red Hat

How commands are executing ?

Hi Folks, I have a small doubt, the binary commands under /bin and /sbin as well as other path binary files, if you peek deep into that, you can find the difference in the way of normal perl programming and some commands will be like binary files. how are the commands executing like the... (3 Replies)
Discussion started by: gsiva
3 Replies

7. Shell Programming and Scripting

Executing certain commands on different servers from one server only

hi I wish to fire certain set of commands on different servers using single script on one of the server. The problem is that these servers only allow ssh session. telnet to these systems is blocked. Is there any way i can do this as rsh does not works. Regards Rochit (7 Replies)
Discussion started by: rochitsharma
7 Replies

8. UNIX for Advanced & Expert Users

executing applications/commands on a unix server from a windows PC

i have a network drive (samba) mounted on to my PC and also i have SSH client on my machine. however i need to run applications/commands on a unix server from the middle of a different executable(windows compatable one). so i need to connect to the unix server from SSH through the... (1 Reply)
Discussion started by: megastar
1 Replies

9. UNIX for Dummies Questions & Answers

Executing commands after I log off

Hi, guys ! I have at home a simple network. I have a server that shares the internet connection to my computer and another another computer which is located in another room. When I want to download something, I'd like to download directly on the server, without letting my computer on. The server... (2 Replies)
Discussion started by: Sergiu-IT
2 Replies

10. Shell Programming and Scripting

Executing mpirun commands

Basically, I would like to run an mpirun query on my web server to query your databases via yours when using the BLAST program, however the server seems not able to execute even basic mpirun programs such as cpi (to calculate pi). Are there any settings I should take note of? I am running Perl... (0 Replies)
Discussion started by: tesswulf
0 Replies
Login or Register to Ask a Question