LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-02-2004, 06:15 AM   #1
sanjith11
Member
 
Registered: Oct 2003
Distribution: redhat
Posts: 63

Rep: Reputation: 15
extracting line by line from a file


hello

i have a file containing a set of PID's line by line. how can i extract each PID and check the status of the PID in a script.

reg
SAN
 
Old 07-02-2004, 06:30 AM   #2
linuxxed
Member
 
Registered: Feb 2004
Posts: 273

Rep: Reputation: 30
Re: extracting line by line from a file

Quote:
Originally posted by sanjith11
hello

i have a file containing a set of PID's line by line. how can i extract each PID and check the status of the PID in a script.

reg
SAN

cat filename | while read PID
do
# check each pid's status by sending a signull
kill -0 $PID
if [ $? -ne 0 ]; then
echo "$PID is down"
else
echo "$PID is up"
fi
done
 
Old 07-02-2004, 06:34 AM   #3
rshinoy
LQ Newbie
 
Registered: May 2004
Posts: 10

Rep: Reputation: 0
You can do it using a shell script like this
Code is :
-----------------------------
for ProcId in `cat $procFile`
do
< do the stuff to check the status of PID here >
done
----------------------------
I hope it is what you needed ?
 
Old 07-02-2004, 07:38 PM   #4
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
This one-liner will give you a table with header. You can change what you want displayed by changing the -o output format fields, or do without a header with the --noheader option.

ps -o pid,stat --pid `cat pidlist`

Last edited by jschiwal; 07-02-2004 at 07:39 PM.
 
  


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
bash shell script read file line by line. Darren[UoW] Programming 57 04-17-2016 06:07 PM
C: fread to read a file line by line until the end Blue_muppet Programming 2 09-19-2008 09:42 AM
C++ text file line by line/each line to string/array Dimitris Programming 15 03-11-2008 08:22 AM
Extracting a specific line from an ASCII file heyyou Programming 7 03-21-2005 04:19 PM
linux scripting help needed read from file line by line exc commands each line read atokad Programming 4 12-26-2003 10:24 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:49 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