• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 313
  • Last Modified:

How to count output lines in PERL ?

Hi,

I would like to request an assistant.

May i know how to count how many line for output ?

I would like to accomplish the following :

if output from "ps aux" run from shell having MORE than 300 lines
{
email to root
}
if output from "ps aux" run from shell having LESS than 300 lines
{
do something else
}

Thank you.
0
smksa
Asked:
smksa
1 Solution
 
vikas_madhusudanaCommented:
can you redirect the output to a file and then do a  wc -l filename to get the number of lines.
0
 
smksaAuthor Commented:
If possible i would like to have this on the fly (without writing to a file) as to avoid high CPU consumption.
0
 
FishMongerCommented:
How are you executing "ps aux"; via system(), or backticks, or a piped open?

You could put the output into an array and the number of lines will be the size of the array.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
smksaAuthor Commented:
I actually wanted to create a perl script and trigger it using crond from shell .

I have root access to the server.

The ps aux is actully run directly from the system shell.

0
 
vikas_madhusudanaCommented:
you can put into a pipe and then do a wc -l on that
0
 
ozoCommented:
#!/usr/bin/perl
if( (()=`ps aux`) > 300 ){
email to root
}else{
do something else
}
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now