Script lines execution after SSH


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script lines execution after SSH
# 1  
Old 06-16-2008
Bug Script lines execution after SSH

Hello

Its a simple issue i suppose.I am trying to write a script which first logson to other server via SSH & tries to stop a process ,then returns to its originator & completes a task & finally jumps to that second servers again & starts the (stopped) process.

What i am not able to implement is after logging on to the second server via SSH,it does not execute script logic but waits on command prompt for user input.
If i say 'exit' ,it returns to the originator & resumes script execution.

I am pasting the script here( part of it )

echo "--------------------------------"
echo "Connecting to node controller on <server 2>.....please wait"
ssh <username>@<server 2>
sleep 5
echo "--------------------------------"
b=server2
a=`uname -n`
if [ $a -eq $b ]
then
echo "----------------------------"
echo "Connected to server2 successfully"
echo "----------------------------"
fi
sleep 5
echo "Stopping node controller on <server 2>.....please wait"
cd <install_root>/bin
. ./setupenv.sh
echo "---------------------------------"
sleep 5
#echo "Stopping the node controller...please wait"
./nctrl stop

Here is a problem:
It logson to server 2 correctly but just waits at the command prompt.


Please help me in finding the flaws with the script.

Regards
Abhi
# 2  
Old 06-16-2008
Are you sure that the output of $a and $b are the same ? Add -x flag at the shebang line and debug it. Can you execute all those commands from the prompt, without using the script ?
# 3  
Old 06-18-2008
Here's a hint...

If you use this command, it will execute the command on the remote end:

Quote:
ssh username@server cat filename
However, if you pipe the output through to another command, THAT PART will be processed locally, and the outputfile will also be in the local directory, like this:

Quote:
ssh username@server cat filename | grep blahblah > outputfile
You put the SSH-statement on a single line, which indeed will wait for your input and hold execution of the remaining script, until you exit the SSH-session.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remote script over ssh execution issues.

If I execute below code I am able to get string from column8 and column10 about a process. serverA1$> ps -ef | grep rotate | grep 'config' | awk '{print $8" "$10}' /<Oracle_home>/ohs/bin/odl_rotatelogs -h:/<app_Home>/config/OHS/ohs1/component_events.xml_ohs1... (12 Replies)
Discussion started by: kchinnam
12 Replies

2. UNIX for Advanced & Expert Users

Count no. of lines of execution

Hi all, I have my script to execute number of commands (command line interface) using TCL. the execution and response of the commands get stored in some log file. While the execution is going on i need only the time of execution and the number of line getting executed to be displayed in... (1 Reply)
Discussion started by: Syed Imran
1 Replies

3. HP-UX

Remote ssh execution and .profile issues

Greetings, i'm currently having issues in successfully executing a script from one server to other, and i'm cracking my nut in understanding why. Let's get started with the default info: Server A: briozzo@A:/home/briozzo $ uname -a HP-UX A B.11.31 U ia64 2787251109 unlimited-user license ... (3 Replies)
Discussion started by: nbriozzo
3 Replies

4. Shell Programming and Scripting

Execution problem ---to remove the lines which starts with one type of character

Hi, I have one file, I need to check if file exist or not and then remove the lines which starts with ? My file1.out data is some thing abcabcppp xyzxyzpqr ????????? ????????? Output should be in test.out abcabcppp xyzxyzpqr I am getting the output as below but the File does not exist... (4 Replies)
Discussion started by: Ramyajiguru1
4 Replies

5. Cybersecurity

Log remote execution over SSH

If a user execute commands remotely over ssh : $ ssh USERNAME@SERVER COMMANDSHow the SERVER administrator can log those COMMANDS executed in a "not a tty" session ? I searched for my question and get the following suggestions:Anybody give help how to do this ? what the content of "/bin/bash "... (1 Reply)
Discussion started by: new0h
1 Replies

6. Linux

ssh and passwd scripting execution problems on linux

I'm having a problem here and I was wondering if anyone could help me? I'm putting together a password script. First off, I don't have root access. I have sudo access. Lets say the User ID is Trevor1, the password is H!rry23! and the server name is Linux1234 This is how the script begins ... (5 Replies)
Discussion started by: wdog17
5 Replies

7. UNIX for Advanced & Expert Users

SSH using shell script terminates the script execution

Hello, I am writing a shell script in which i do ssh to remote server and count the number of files there and then exit. After the exit the shell script terminates which i believe is expected behavior. Can some one suggest me a way where even after the exit the script execution resumes. ... (2 Replies)
Discussion started by: manaankit
2 Replies

8. Shell Programming and Scripting

ssh execution help needed.

I m writing a program to execute remote script . (display remote file content) Whenever i execute following statement it gives me an error. $command="cat /root/vm.cfg" ssh -ttq root@10.180.8.236 $command However following script work find. ssh -ttq root@10.180.8.236 cat /root/vm.cfg ... (8 Replies)
Discussion started by: pinga123
8 Replies

9. Shell Programming and Scripting

ssh can't back from remote host during script execution

Hi all I wrote a script to execute a script on several remote hosts, but somehow during the execution of the local script, ssh can't come back from the remote host, so that causes my local script hanging... I use the below command to do the job in the local script, any idea? ssh... (12 Replies)
Discussion started by: bzylg
12 Replies
Login or Register to Ask a Question