Shamsul Kamal
asked on
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.
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.
can you redirect the output to a file and then do a wc -l filename to get the number of lines.
ASKER
If possible i would like to have this on the fly (without writing to a file) as to avoid high CPU consumption.
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.
You could put the output into an array and the number of lines will be the size of the array.
ASKER
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.
I have root access to the server.
The ps aux is actully run directly from the system shell.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
#!/usr/bin/perl
if( (()=`ps aux`) > 300 ){
email to root
}else{
do something else
}
if( (()=`ps aux`) > 300 ){
email to root
}else{
do something else
}