LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   ssh on ksh (https://www.linuxquestions.org/questions/linux-newbie-8/ssh-on-ksh-4175426789/)

brian00 09-11-2012 10:23 PM

ssh on ksh
 
Code:

#!/bin/ksh

###ssh to remote server
ssh SERVERNAME

#####check to see if the process running on the remote server
#####write the output to the file from source server

ps -ef |grep smon > output.txt

####I want to exit out from the remote server
exit

the exit doesn't seem to work. Basically, I want to get out the remote sesssion and continue to process thru my script on the source server.

any thoughts?

evo2 09-11-2012 10:46 PM

Hi,

there are various ways to do this. The simplest is probably to put the shell script on SERVERNAME and then run it over ssh. For example:
Code:

scp myscript.sh SERVERNAME:
ssh -t SERVERNAME ./myscript.sh

Where in your case mysript.sh would contain something like
Code:

#!/bin/sh
ps -ef |grep smon > output.txt

This would leave output.txt on the machine SERVERNAME. If you want it on the localhost, you could do something like
Code:

ssh SERVERNAME 'ps -ed | grep smon' > output.txt
There are many variations, depending on what it is you actually want to do.
Evo2.

brian00 09-12-2012 08:15 AM

more questions please:

1. Once I get the output generated on the remote server, how can I list to make sure the file is existed?
$ ls

2. then if the file existed, there is a string I am interested so I am thinking of grep.....


basically, I want to be on the source server, look for the file if it existed on the remote server and search for the string.......

thanks,

brian00 09-12-2012 10:37 AM

great, thanks


I have another question, below is what I have in my code:
Code:


if [[ -n `ls $log/output.tst | grep "MYDB"` ]] ; then
.........


when I run my script, I got the error:

grep: unknown devices method

evo2 09-12-2012 06:04 PM

Hi,

hmm, I don't know about the error message, but I guess there is something wrong in your logic. Perhaps what you actually want is something like

Code:

if grep --silent MYDB $log/output.tst ; then
  echo "Found it"
else
  echo "No match"
fi

This will check for the string "MYDB" in the file $log/output.tst. This syntax will check the exit status instead of what is returned by grep (which will be nothing since the --silent flag is used).

Evo2.

leetown 09-13-2012 04:03 AM

ssh [-l login_name] [ hostname | user@hostname] [ com-mand]
Before doing this there are some settings needs to be done, else you can only use interactive mode for entring password. If you need to incorporate the ssh in batch mode you have to have the keys create. See the help for ssh for more details.


All times are GMT -5. The time now is 08:07 PM.