LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-11-2012, 11:23 PM   #1
brian00
Member
 
Registered: Aug 2011
Posts: 33

Rep: Reputation: Disabled
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?
 
Old 09-11-2012, 11:46 PM   #2
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
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.
 
Old 09-12-2012, 09:15 AM   #3
brian00
Member
 
Registered: Aug 2011
Posts: 33

Original Poster
Rep: Reputation: Disabled
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,

Last edited by brian00; 09-12-2012 at 09:27 AM.
 
Old 09-12-2012, 11:37 AM   #4
brian00
Member
 
Registered: Aug 2011
Posts: 33

Original Poster
Rep: Reputation: Disabled
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
 
Old 09-12-2012, 07:04 PM   #5
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
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.
 
Old 09-13-2012, 05:03 AM   #6
leetown
LQ Newbie
 
Registered: Sep 2012
Posts: 3

Rep: Reputation: 0
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Which ksh ? Vilius Linux - Software 1 05-13-2009 03:53 AM
Ksh Script Help sharathkv25 Programming 10 02-02-2007 11:28 AM
help w/ksh script ShaqDiesel Programming 2 01-12-2007 03:04 PM
some ksh scripting nabil Programming 1 03-03-2002 11:34 PM
How to configure ksh? OneMrGchaser Linux - General 2 11-10-2001 01:30 PM


All times are GMT -5. The time now is 05:00 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration