shell script to run after ssh logout from another machine


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting shell script to run after ssh logout from another machine
# 1  
Old 06-29-2011
Network shell script to run after ssh logout from another machine

Scenario:
I currently manager a cluster at work which is on a private network and i constantly need to ssh to other clients for diags e.t.c. I created a debain client which i use as my gateway to get to all the clients on the private network and I then created a Shell menu script which will make it easier for me to access all the clients, get diags...e.t.c

I have managed to get the script to work (by putting it in the .bashrc) to run every time the "test" user logs in which is good. I use this machine to ssh to other machines too...

so my problem:
Is it possible to have this script run when i exit a ssh session from another client back into this debian machine? i.e

client a = my machine
client b = gateway machine to private network with menu script
client c,d,e = private network clients

client a will ssh to client b (as test) - menu loads. I select option 1 to ssh to client c, do some stuff and exit client c back to client b. This currently gets me to a bash prompt - I want this to load the menu again so i can easily do other things rather than manually loading the menu again. (hope that makes sense)

is that possible?

Last edited by defamer; 06-29-2011 at 10:49 AM..
# 2  
Old 06-29-2011
Please, show us your script code from .bashrc

Jean-Pierre.
# 3  
Old 06-29-2011
This is the menu i'm using:

.bashrc
Code:
./login.sh

Code:
#!/bin/bash

clear # Clear the screen.

echo "          SSH to a client"
echo "          ------- ----"
echo "Choose one of the following clients:"
echo
echo "[1] management"
echo "[2] Node1 "
echo "[q] Quit  "
echo

read client

case "$client" in
"1" )
echo
echo "You have chosen to ssh to management - Wait..."
echo
ssh user@<ipaddress>
;;

"2" )
echo
echo "You have chosen to ssh to Node1 - Wait..."
echo
ssh user@<ipaddress>
;;

"Q" | "q" )
echo
echo "Exiting to console prompt - Wait..."
echo
exit 0
;;

* )
echo
echo "Invalid option selected - exiting to console...."
echo
;;

esac

exit 0

# 4  
Old 06-29-2011
Something like that ?
Code:
#!/bin/bash

clear # Clear the screen.

while :
do

echo "          SSH to a client"
echo "          ------- ----"
echo "Choose one of the following clients:"
echo
echo "[1] management"
echo "[2] Node1 "
echo "[q] Quit  "
echo

read client

case "$client" in
"1" )
echo
echo "You have chosen to ssh to management - Wait..."
echo
ssh user@<ipaddress>
;;

"2" )
echo
echo "You have chosen to ssh to Node1 - Wait..."
echo
ssh user@<ipaddress>
;;

"Q" | "q" )
echo
echo "Exiting to console prompt - Wait..."
echo
break
;;

* )
echo
echo "Invalid option selected - exiting to console...."
echo
;;

esac

done
exit 0

Jean-Pierre.
# 5  
Old 06-29-2011
perfect that worked great! thank you!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

To run a local shell script in a remote machine by passing arguments to the local shell script

I need to run a local shell script on a remote machine. I am able to achieve that by executing the command > ssh -qtt user@host < test.sh However, when I try to pass arguments to test.sh it fails. Any pointers would be appreciated. (7 Replies)
Discussion started by: Sree10
7 Replies

2. Shell Programming and Scripting

Run shell script on different machine using perl script

I want to execute my shell script on remote machine using SSH in perl script. Please help me with syntax. (2 Replies)
Discussion started by: james1988
2 Replies

3. UNIX for Dummies Questions & Answers

how to use ssh to run shell script on a remote machine?

how to use ssh to run shell script on a remote machine? ssh user@remote sh ./script.unx i ran the above command ./script.unx HAS NOHUP COMMAND IN ITS BODY, I AM GETTING ERROR AS NOHUP NOT FOUND... i tried to run that script from remote server, its working fine do ineed to set... (6 Replies)
Discussion started by: only4satish
6 Replies

4. Shell Programming and Scripting

run query in shell script after ssh

Hi, I need to run sql query in shell script after getting connected to ssh. For that I connected to ssh through shell script using RSA keys done]. Now when I am running sql query, it's not working... but several other commands like 'ls'. 'mkdir', etc are working properly. Here is my code: ... (2 Replies)
Discussion started by: shekhar2010us
2 Replies

5. Shell Programming and Scripting

ssh - run shell script - Error

Hi Team, I am trying to run shell script from one server to another server with below command. ssh abc@pqr.america.com /tmp/test.ksh But, it gives below error. Can someone help me what is the issue? exec(): 0509-036 Cannot load program ssh because of the following errors: ... (3 Replies)
Discussion started by: ace_friends22
3 Replies

6. Shell Programming and Scripting

executing command in a remote machine through ssh - shell script

Hi All, i have two machines like x and y . my requirement is i should connect to machine Y from x through ssh connection . and do some operation such as copy and move and delete files in Y machine . i tried with this code but it is doing in machine x only . and i need to exit from Y when... (1 Reply)
Discussion started by: rateeshkumar
1 Replies

7. Shell Programming and Scripting

How to run script on logout ?

Hi Everybody, I want to run my own script on logout , i can use .bash_logout file... problem is this will work only for that particular user... i want to know the common file... so that script wil run for all the user... 2. How to run script on Shutdown ? Thanks in advance Anitha (4 Replies)
Discussion started by: anisn2002
4 Replies

8. Shell Programming and Scripting

Run shell script on another server using ssh

Hi, I have 2 servers and i installed ssh2 on both boxes .. so they they can communicate with each other with our password auth .. now i want to write a scrip on box 1 for running commands and getting out put from the second box can some one help me out Thank you in advance (1 Reply)
Discussion started by: anwesh
1 Replies

9. UNIX for Dummies Questions & Answers

run a script at logout

hi all , Need to a run a program on user logout (using GNOME log screen). Tried using .bash_logout for this purpose but that doesnt seem to work. Similar to .bash_logout is there any script /program which a normal user (other than root ) can edit and run it on their logout? can anybody... (0 Replies)
Discussion started by: harsha10
0 Replies

10. Shell Programming and Scripting

how to run a command in different machine using SSH

how to run a command in different machie in my case script will runs in solaries machine.. in one instance it has to run a command in different machine with different operating system ( linux ) using SSH command i tried ssh -l (login_name) (machine name/host ) " command " but it is... (3 Replies)
Discussion started by: mail2sant
3 Replies
Login or Register to Ask a Question