LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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-06-2012, 01:48 PM   #1
brian00
Member
 
Registered: Aug 2011
Posts: 33

Rep: Reputation: Disabled
scripting


when I run the below command, it ran fine:

ssh SERVER_NAME "ps -ef |grep oam_server1" > ../Logs/oam_status.txt


however, when I put the exact command into the korn shell, it complain:

grep: unknown devices method


I believed I missed some quote or something.

Please advise.....
thanks,
 
Old 09-06-2012, 02:13 PM   #2
Snark1994
Senior Member
 
Registered: Sep 2010
Distribution: Debian
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
You need a space between the '|' and 'grep', I'm guessing
 
Old 09-06-2012, 02:15 PM   #3
brian00
Member
 
Registered: Aug 2011
Posts: 33

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Snark1994 View Post
You need a space between the '|' and 'grep', I'm guessing
I did but still doesn't work.


any other thoughts?
 
Old 09-06-2012, 02:21 PM   #4
Snark1994
Senior Member
 
Registered: Sep 2010
Distribution: Debian
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
Perhaps try ssh-ing into the box:

Code:
ssh SERVER_NAME
and then running the command:

Code:
ps -ef | grep oam_server1
so we can see which bit of it is causing the problem...
 
Old 09-06-2012, 02:22 PM   #5
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Code:
ssh SERVER_NAME "ps -ef \|grep oam_server1" > ../Logs/oam_status.txt
?
 
Old 09-06-2012, 02:39 PM   #6
brian00
Member
 
Registered: Aug 2011
Posts: 33

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Snark1994 View Post
Perhaps try ssh-ing into the box:

Code:
ssh SERVER_NAME
and then running the command:

Code:
ps -ef | grep oam_server1
so we can see which bit of it is causing the problem...


If I run ps -ef on another line, it will think I am looking for the process on server I am issuing the command. I need to look for the process on the remote server (which I used ssh), don't know why the command itself worked but it's not happy when I put it in ksh.
 
Old 09-06-2012, 02:40 PM   #7
brian00
Member
 
Registered: Aug 2011
Posts: 33

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Habitual View Post
Code:
ssh SERVER_NAME "ps -ef \|grep oam_server1" > ../Logs/oam_status.txt
?
made the changes and no luck, below is the error:

ERROR: Garbage option.
********* simple selection ********* ********* selection by list *********
-A all processes -C by command name
-N negate selection -G by real group ID (supports names)
-a all w/ tty except session leaders -U by real user ID (supports names)
-d all except session leaders -g by session OR by effec....
...............
 
Old 09-06-2012, 02:54 PM   #8
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
The remote host is complaining about the format of the arguments to the ps command. Is the remote host a Solaris or other non-GNU/Linux host, perhaps? On some architectures, ps is a bit of an odd dog. I forget the whole story, but there are two versions of ps, and one or the other is run depending on something or other, like the shell (C-shell vs. Bourne shell) since each are configured with different $PATHs. To complicate matters, one of them tries to emulate the other if it senses that it is being launched by some other shell.
The upshot is that I think you can disambiguate which ps is being run by specifying the full filespec of the program that works properly for you. Still, your script may be sensitive to the user who runs it, since that will dictate which shell is being used to launch ps.
--- rod.
 
Old 09-06-2012, 03:08 PM   #9
brian00
Member
 
Registered: Aug 2011
Posts: 33

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by theNbomr View Post
The remote host is complaining about the format of the arguments to the ps command. Is the remote host a Solaris or other non-GNU/Linux host, perhaps? On some architectures, ps is a bit of an odd dog. I forget the whole story, but there are two versions of ps, and one or the other is run depending on something or other, like the shell (C-shell vs. Bourne shell) since each are configured with different $PATHs. To complicate matters, one of them tries to emulate the other if it senses that it is being launched by some other shell.
The upshot is that I think you can disambiguate which ps is being run by specifying the full filespec of the program that works properly for you. Still, your script may be sensitive to the user who runs it, since that will dictate which shell is being used to launch ps.
--- rod.
As I said, if I run the command not within .ksh then it worked
 
Old 09-06-2012, 03:41 PM   #10
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Quote:
Originally Posted by brian00 View Post
As I said, if I run the command not within .ksh then it worked
This is quite ambiguous. 'the command' is actually a script or command that runs another command on a different host. Or is 'the command' the one you are running on the remote host? How are you controlling which shell is being used?

What you are saying sounds consistent with my suggestion that different versions of ps are being launched. Each of them takes arguments of different formats. Try your two (or more) scenarios with the command 'which ps', rather than actually lauching ps. Try running 'ps --help' and or 'ps --version' to see if there is any difference or consistency.

--- rod.
 
Old 09-07-2012, 05:39 AM   #11
Snark1994
Senior Member
 
Registered: Sep 2010
Distribution: Debian
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
Quote:
If I run ps -ef on another line, it will think I am looking for the process on server I am issuing the command. I need to look for the process on the remote server (which I used ssh), don't know why the command itself worked but it's not happy when I put it in ksh.
Not unless you close the session. For example:

Code:
[joshua@joshua-desktop:~]$ ssh a_user@othercomputer 
[a_user@othercomputer:~]$ ls
# output from othercomputer (remote server)
[a_user@othercomputer:~]$ exit
Connection to othercomputer closed.
[joshua@joshua-desktop:~]$ ls
# output from joshua-desktop (local machine)
In addition to rod's suggestions, when you're talking about shells, are you talking about your local host or your remote host? i.e. is ksh the shell on the computer on the desktop sitting in front of you, or the server you're ssh-ing into?
 
Old 09-07-2012, 07:28 AM   #12
brian00
Member
 
Registered: Aug 2011
Posts: 33

Original Poster
Rep: Reputation: Disabled
Here is what I want to do in my code, maybe it's wrong so it gave me issue:


..........
ssh SERVER_NAME "ps -ef | grep oam_server1" > ../Logs/oam_status.txt
if [[ -n `ls $LogDir/oam_status.txt 2>&1 |grep "blah"` ]] ; then
do something............

basic I want to ssh to remote server to find whether the process running then write the output to the log file (log file reside on the local machine) and I think that's the problem.......
 
Old 09-08-2012, 03:43 AM   #13
Cooper618
LQ Newbie
 
Registered: Sep 2012
Location: Canada
Posts: 8

Rep: Reputation: 1
Since Scripting News has a deep technical focus, I wanted to point out that there is some deep tech that connects the pieces here.
 
Old 09-08-2012, 05:01 AM   #14
Mr. Alex
Senior Member
 
Registered: May 2010
Distribution: No more Linux. Done with it.
Posts: 1,238

Rep: Reputation: Disabled
Quote:
Originally Posted by Snark1994 View Post
You need a space between the '|' and 'grep', I'm guessing
It's not necessary in any way.
 
Old 09-08-2012, 05:59 AM   #15
Snark1994
Senior Member
 
Registered: Sep 2010
Distribution: Debian
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
Quote:
Originally Posted by brian00 View Post
ssh SERVER_NAME "ps -ef | grep oam_server1" > ../Logs/oam_status.txt
But it's this line which isn't working, giving the error, yes? It runs fine on my computer

Did you try the things which Nbomr suggested? What about my questions about shells?

And if it is the shell that's the problem, and this is in a script (as your code snippet suggests) could you not just change '#!/usr/bin/env ksh' (or whatever you have) to '#!/usr/bin/env bash'?
 
  


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
LXer: Scripting the Linux desktop, Part 2: Scripting Nautilus LXer Syndicated Linux News 0 02-17-2011 04:02 AM
Firefox Scripting Add-on (Scripting HTML / Javascript inside Firefox) linuxbeatswindows Programming 1 09-18-2009 10:09 PM
Scripting mickeyd531 Linux - Newbie 1 05-10-2009 08:05 PM
teaching shell scripting: cool scripting examples? fax8 Linux - General 1 04-20-2006 04:29 AM
scripting bforest Linux - Newbie 4 05-11-2004 02:45 AM

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

All times are GMT -5. The time now is 08:04 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
Open Source Consulting | Domain Registration