hi all,
i have a situation where i run ssh command from a unix machine to execute few scripts on 2 other unix machines.
my problem is, the scripts that i run will start few commands on the 2 servers and will quit....i am able to quit from the script but i have to give ctrl+c (on the server from where i am executing ssh) to exit from an ssh session.This situation is gettin worse when i try to run those scripts on 20 machines.i need to give a ctrl+c everytime.
can someone give a suggestion...
thanks in advance...
yes i developed those scripts. i actually run vmstat,iostat on server.i just give "exit" in the script which runs on the destination server.
ssh ${HOST} '/ravi/test/stat_collect.ksh start'
HOST is the variable that has the host on which i execute
where start is a parameter to the script.
This one works to me:
testuser@remotesvr # more test.sh
#!/bin/sh
iostat
exit
[localsrv]fmv:/home/fmv/scripts/tmp>echo "./test.sh" | ssh -T -C -l testuser remotesvr
Sun Microsystems Inc. SunOS 5.10 Generic January 2005
tty md10 md11 md12 md20 cpu
tin tout kps tps serv kps tps serv kps tps serv kps tps serv us sy wt id
0 108 15 2 27 12 2 20 12 2 20 0 0 16 1 2 0 97
I have ssh keys on each server so I don't need to provide a password.
Let me know if it works for you.
no its not working.....
it says "Name or service not known"
client:
ssh ${HOST} '/ravi/test/stat_collect.ksh start'
server:
in stat_collect i run iostat
---------- Post updated at 08:32 AM ---------- Previous update was at 08:29 AM ----------
when i use "-T -C -l" options to my ssh cmd i got that error
Before executing your script, let's create a simple one and try to solve the problem, after we can go on.
On the remote host create this script in the user's home directory:
# cat test.sh
#!/bin/sh
echo "Arguments: [$*]"
iostat
exit
On the local host execute the following command:
# echo "./test.sh start finish" | ssh -T -C -l <RemoteUser> <RemoteServer>
The error you faced: "Name or service not known" is because of the wrong position of the arguments I gave you and you used wrongly.
Let me know the result.
its working....but i want that iostat to continue running on the server and quit from ssh
Why do you want iostat to continue running on the server? You are redirecting its output to a file?
In the script you can try:
#===================================
nohup iostat 1 100 1>> "iostat_output.log" 2> "iostat_output.log"
#===================================
The two arguments for iostat are:
1 number of seconds between each measure
100 number of times to measure
But be careful, if you run it twice and the first time has not yet finished, the log file will be a mess.
Regards.
---------- Post updated at 11:28 ---------- Previous update was at 11:27 ----------
Ops! An error, the line can be:
In the script you can try:
#===================================
nohup iostat 1 100 1>> "iostat_output.log" 2> "iostat_output.log" &
#===================================
no im still having the same problem....i still have to press ctrl c on client server to quit.....or it quits automatically when i kill iostat on server
---------- Post updated at 09:53 AM ---------- Previous update was at 09:45 AM ----------
ssh is waiting for the termination of iostat on the destination server only then ssh exiting on its own on the client machine and comes to prompt
---------- Post updated at 10:52 AM ---------- Previous update was at 09:53 AM ----------
managed to do it by adding this to the ssh
ssh ${HOST} '/ravi/test/stat_collect.ksh start </dev/null >nohup.out 2>&1 &'
---------- Post updated at 10:53 AM ---------- Previous update was at 10:52 AM ----------
but can someone explain what i am doing here....
For me the code below is executed successfully!
No Ctrl+c needed!
# cat test.sh
#!/bin/ksh
echo "Arguments: [$*]"
echo "Starting: [iostat]..."
logFile="/<FullPathToLogFile>/iostat_output.log"
nohup iostat 1 100 1>> "${logFile}" 2>> "${logFile}" &
iostat 1 5
echo "Ending: [iostat]."
exit
Look that you need to change the variable: ${logFile} to point to the path of the log file.
I validated the execution, and after the remote call finished, the "iostat_output.log" continue increasing which means the iostat command was executing still.
---------- Post updated at 13:21 ---------- Previous update was at 13:09 ----------
About the command you asked:
ssh ${HOST} '/ravi/test/stat_collect.ksh start </dev/null >nohup.out 2>&1 &'
It uses Input/Output redirection and you can find further information in the following site: Tips For Linux - Input/Output Redirection in Unix
The trick in the command is the: "&" sign, which means the script can continue to execute without needing to wait for this command finish to execute. It is the same as I sent you!
nohup iostat 1 100 1>> "${logFile}" 2>> "${logFile}" &
thank you so much felipe.vinturin.....the method u suggested is also working....it was very helpful...