LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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, 10: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, 10:46 PM   #2
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
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, 08: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 08:27 AM.
 
Old 09-12-2012, 10: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, 06:04 PM   #5
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
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, 04: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



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 02:53 AM
Ksh Script Help sharathkv25 Programming 10 02-02-2007 10:28 AM
help w/ksh script ShaqDiesel Programming 2 01-12-2007 02:04 PM
some ksh scripting nabil Programming 1 03-03-2002 10:34 PM
How to configure ksh? OneMrGchaser Linux - General 2 11-10-2001 12:30 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:31 AM.

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
Open Source Consulting | Domain Registration