Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ps command

Status
Not open for further replies.

Yarka

Technical User
Jan 14, 2007
192
ES
hi,
i run a script that it read a file and extract data:

eafs:~/root #./script.sh input.txt

When I want to see if my script is started I do:

eafs:~/root #ps -ef | grep script.sh
and my output is:
root 10805 1 2 16:35 ? 00:01:42 /bin/sh ./script.sh input.txt
root 3629 1 0 16:52 ? 00:00:00 /bin/sh ./script.sh input.txt
root 3644 3629 2 16:52 ? 00:01:25 /bin/sh ./script.sh input.txt
root 22149 27917 0 17:14 pts/8 00:00:00 /bin/sh ./script.sh input.txt
root 22157 22149 2 17:14 pts/8 00:00:46 /bin/sh ./script.sh input.txt
root 5546 10805 0 17:43 ? 00:00:00 /bin/sh ./script.sh input.txt
root 5548 5546 0 17:43 ? 00:00:00 /bin/sh ./script.sh input.txt
root 5549 5546 0 17:43 ? 00:00:00 /bin/sh ./script.sh input.txt
root 5553 3644 0 17:43 ? 00:00:00 /bin/sh ./script.sh input.txt

thanks.
 
We know what your input looks like. if you can tell us what checks you want, and what the output should look like, we can help you.

Personally, I'd use perl for it, only because I find that awk is a bit cryptic. Run a perl -v and let us know what version you're running.

How big is your input file? It would help so we can estimate how long it ought to run...

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
stevexff said:
I'd use perl for it, only because I find that awk is a bit cryptic

[3eyes] You cannot be serious... what could be more cryptic than PERL? :) PERL is often described as a "write-only" language, even by Larry Wall himself unless I'm much mistaken, due to it being so difficult to read and understand when you come back to your code a year later...

Annihilannic.
 
What, so this nasty mixture of bash and shelling out to assorted utilities
Code:
do
    m=`echo "$LINE" | awk -F'\t' '{ print $5 }'`
    l=${m:1:1}
    if [ $l == ":" ]; then
        m=${m:2:2}
    else m=${m:3:2}
    fi
done < /root/$1
is supposed to be intuitive and easy to read? Perl can be cryptic, but a lot depends on how you write it.

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
For example, the 'little piece of the script that worked bad' seems to be attempting to extract the minute from the time portion. In perl:
Code:
#!/usr/bin/perl
use strict;
use warnings;

while (<>) {
   my $time = (split /\s+/)[4];   
   my ($hours, $mins, $secs, $nanoseconds) = split(/[:,]/, $time);
   print $mins, "\n";
}

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
stevexff said:
What, so this nasty mixture of bash and shelling out to assorted utilities... is supposed to be intuitive and easy to read?

No, did I say it was?

The equivalent in awk:

Code:
#!/usr/bin/awk -f
{ split($5,a,":"); print a[2] }

I have nothing against perl, I use it myself, however I find awk is much more readable language, that's all. No trolling intended. :) If the task is complex and doesn't fit awk's input/output processing paradigm very well then perl is much more suited.

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top