There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
Linux and Unix
Tag Cloud
access acer asus bios bsod computer crash drive driver drivers error ethernet excel freeze games gaming hard drive hardware hdmi internet java laptop malware memory monitor motherboard music network obp printer problem ram random registry router slow software sound trojan usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless
Search
Search for:
Tech Support Guy Forums > Operating Systems > Linux and Unix >
Solved: ksh how to show ps -ef ?

Reply  
Thread Tools
surfnschultz's Avatar
Member with 191 posts.
 
Join Date: Nov 2003
25-May-2005, 03:21 PM #1
Solved: ksh how to show ps -ef ?
I want to list the processes I am about to kill and ask the user for confirmation.

So my questions is how to make this command show on the screen

echo ps -ef | grep $portnum


this doesn't work as is in my script
tsunam's Avatar
Senior Member with 1,246 posts.
 
Join Date: Sep 2003
Experience: Linux~su
25-May-2005, 05:56 PM #2
well the echo is going to echo "ps -ef" ....as in the letters

you should be able to do a la="ps -ef | grep $portnum"
echo la
surfnschultz's Avatar
Member with 191 posts.
 
Join Date: Nov 2003
25-May-2005, 08:14 PM #3
cool let me try that out asap.
surfnschultz's Avatar
Member with 191 posts.
 
Join Date: Nov 2003
25-May-2005, 08:19 PM #4
Nope did work says varible la not fuound? weirdness....
surfnschultz's Avatar
Member with 191 posts.
 
Join Date: Nov 2003
25-May-2005, 08:24 PM #5
now no error BUT no output to screen

la="ps -ef | grep $portnum"
echo la
Squashman's Avatar
Trusted Advisor with 18,705 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: Bocks of Rox
25-May-2005, 08:47 PM #6
Back Ticks.
surfnschultz's Avatar
Member with 191 posts.
 
Join Date: Nov 2003
26-May-2005, 12:10 PM #7
ps -ef | grep $portnum > $2

this worked, it is funny how you can be in the bathroom and think OH **** I figured it out. hahaha
Squashman's Avatar
Trusted Advisor with 18,705 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: Bocks of Rox
26-May-2005, 07:00 PM #8
The Back Ticks would have worked as well. Anytime you want to echo the output of a command or assign it to a variable, you need to enclose the command in `Back Ticks`. Otherwise your echo command or your variable will just equal the characters you typed.
codejockey's Avatar
Senior Member with 1,410 posts.
 
Join Date: Feb 2002
29-May-2005, 01:02 AM #9
A few thoughts:

surfnschultz:
now no error BUT no output to screen
la="ps -ef | grep $portnum"
echo la

You have echoed just "la" to the screen, not the contents of the la variable. Try echo $la instead.

squashman:
The Back Ticks would have worked as well. Anytime you want to echo the output of a command or assign it to a variable, you need to enclose the command in `Back Ticks`. Otherwise your echo command or your variable will just equal the characters you typed.

Pretty much right. You can also simply execute the command to display the output to the screen; as you point out, back ticks are especially useful when you want to capture the result of a command, but you can display the result without using back ticks.

surfnschultz:
Not sure what you are doing here, but suspect a typo. You can certainly execute the ps -ef command in your script, and without any additional magic, the output will be displayed on the screen. The redirection to $2 (which I suspect is either a typo or superstitious behavior ) is not needed. My guess is that $2 is NULL (i.e., there is no second argument to your script, and your redirection to $2 resolves to a redirection to (NULL string) which is effectively stdout -- what the command would have done anyway. I may have misunderstood what was going on, however, so please let me know what I've missed.

Hope this helps.
__________________
The slowest component still sits at the keyboard.
Squashman's Avatar
Trusted Advisor with 18,705 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: Bocks of Rox
29-May-2005, 08:21 PM #10
Glad you come around once in a while CodeJockey.
Reply

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
Thread Tools



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 07:42 AM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.