Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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....
...............
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.
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
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.
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?
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.......
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'?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.