LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Trying to find lsof version information (https://www.linuxquestions.org/questions/linux-newbie-8/trying-to-find-lsof-version-information-800525/)

kailash19 04-07-2010 03:25 AM

Trying to find lsof version information
 
Hi ALL,

I am running a script on several hundred boxes and trying to fing the version of lsof they have.
I have created a scipr for that which runs "lsof -v" through ssh on those boxes.
I am taking output as: line=`lsof -v | sed '/^$/d' | grep "revision"`
echo $line.

But $line is not storing anything?? i dont know why, i think the control is not passing to script , after lsof is run.
How can i do that.

Appreciate your help in this regard.

scobiej 04-07-2010 03:52 AM

Redirection
 
You need to redirect stderr for this to work.

line=`lsof -v 2>&1 | sed '/^$/d' | grep "revision"`
echo $line

Example output :-

revision: 4.80 latest revision: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/ compiler version: 4.3.2 [gcc-4_3-branch revision 141291] (SUSE Linux)

kailash19 04-07-2010 04:45 AM

Hi,

Thanks scobiej.Its working :)

Can you explain why we need to do that?

Tinkster 04-07-2010 04:52 AM

Because the version info is "debug" output, it's not lsof's core
business. You would have noticed that when you run your command
w/o assigning it to a variable that the "grep" doesn't seem to
take, and that you get a whole lot of info?



Cheers,
Tink

kailash19 04-07-2010 05:20 AM

Ok. Thanks for the help.


All times are GMT -5. The time now is 10:33 AM.