ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Can anyone pls help me in understanding the following command:
Code:
perl -ne 'next if !/GET \/server_busy\.php/; $|=1; chomp(); print $_ x 10; print "\n"' > /tmp/busy_count
This line is taking input from a file..possibly log file and printing 10x every line that is not a get request for server_busy.php...so everything else into a /tmp/busy_count....i think....
any perl guru feel free to correct me if i am wrong
ok..correction....
the oneliner checks through an input file and prints every instance of a get request to /server_busy.php and prints on one line 10 times to the /tmp/busy_count file
Yes You are right its taking from logs but the file seems to be empty.
any idea why?
/tmp/busy_count is empty because no instances of GET server_busy.php had been found.
the perl one liner says skip lines that do NOT contain GET server_busy.php
either the one liner is incorrectly written or it is not finding what it is trying to match.
best thing to do is test the one liner out by passing an input file to it
ssh user@<ip address of server> "perl ./monitor-my-system.pl countmybusypages" | /home/rick/graphs/mailme.pl
I am executing this command which will execute the perl script at remote machine./home/rick/graphs/mailme.pl is a directory in local machine.
Its throwing error like:
Code:
ERROR: expected 18 data source readings (got 19) from 1258370768:1.04:0.90:0.78
ssh user@<ip address of server> "perl ./monitor-my-system.pl countmybusypages" | /home/rick/graphs/mailme.pl
I am executing this command which will execute the perl script at remote machine./home/rick/graphs/mailme.pl is a directory in local machine.
Its throwing error like:
Code:
ERROR: expected 18 data source readings (got 19) from 1258370768:1.04:0.90:0.78
Any Idea what may go wrong?
not unless i see the content of monitor-my-system.pl and mailme.pl
Let me explain you what issue I am facing.
I have some scripts to monitor the Web and DB Servers remotely.How it works is We have 5 web servers and 7 DB Servers.
There is a command like:
tail -f /var/logs/expo.txt | perl -ne 'next if !/GET \/server_busy\.php/; $|=1; chomp(); print $_ x 10; print "\n"' > /tmp/busy_count
Now That should be running on the server all the time.
I checked in the midnight and it does collect some 10-20 entry repeatedly.
Next, I have been provided with some script to run from one of centralized server(MontoringServer) which will ssh to the Machine. Th Script is monitor-my-system.pl.
It is run as:
What I understand it collects data from remote web server and create .rrd file through rrdtool.
Now it should redirect to DOCROOT of apache.
what the issue is I m unable to see the Graph and also DOCROOT is not able to get update.
Its all on RHEL Machine and that too with PHP4.
Is there anything to do with PHP4 and RRDtool.
What packages do we need with RRDtool to function properly.
Let me explain you what issue I am facing.
I have some scripts to monitor the Web and DB Servers remotely.How it works is We have 5 web servers and 7 DB Servers.
There is a command like:
tail -f /var/logs/expo.txt | perl -ne 'next if !/GET \/server_busy\.php/; $|=1; chomp(); print $_ x 10; print "\n"' > /tmp/busy_count
Now That should be running on the server all the time.
I checked in the midnight and it does collect some 10-20 entry repeatedly.
Next, I have been provided with some script to run from one of centralized server(MontoringServer) which will ssh to the Machine. Th Script is monitor-my-system.pl.
It is run as:
What I understand it collects data from remote web server and create .rrd file through rrdtool.
Now it should redirect to DOCROOT of apache.
what the issue is I m unable to see the Graph and also DOCROOT is not able to get update.
Its all on RHEL Machine and that too with PHP4.
Is there anything to do with PHP4 and RRDtool.
What packages do we need with RRDtool to function properly.
Again, the clue to why this is not working properly lies in the content or location of the scripts.
You can find out more about rrdtool on their homepage.
Why dont you try running the script on the remote machine, and not piping to the mailme.pl script, just to see what kind of output is generated
ERROR: expected 18 data source readings (got 19) from 1258370768...
The Mailme.pl File:
Code:
$| = 1;
while(<STDIN>){
last if /^\s*$/;
chomp();
s/^\s*subject\s*:\s*//i;
$subject = $_;
}
open( LOG, ">>$subject.log" );
$subject.='.rrd' if !/\.rrd$/;
my $filename = $subject;
print STDERR "$subject\n";
$last_reading = `rrdtool last $filename`;
chomp($last_reading);
while ($line = <>) {
$orig = $line;
chomp($line);
$line =~ s/^.+?://;
print LOG $line."\n";
@data = split /:/, $line;
next if(!$data[0]);
next if($data[0]<=$last_reading);
$cmd = "rrdtool update $filename $line";
#print $cmd;
print `$cmd`;
print "$orig"
}
Now The issue is it somehow adding this to DOCROOT and graph and statistic with RRDtool is getting prepared.
Can yu find out what this error all about?
Can anyone pls help me in understanding the following command:
Code:
perl -ne 'next if !/GET \/server_busy\.php/; $|=1; chomp(); print $_ x 10; print "\n"' > /tmp/busy_count
I think you are addressing your problem from a wrong side. One-liners are quick to write but hard to debug - because they are one liners.
So, whenever I can't get a one-liner working in 60 seconds of my time, I write a normal Perl script instead.
I.e. your question about unexpected data at output is answered by checking data at input and at every processing step afterwards.
For starters:
'if' is a Perl keyword;
'/ .... /' is match operator;
'!' is logical negation;
'$|' is a Perl predefined variable;
'$_' - ditto;
'chomp' is a Perl built-in function;
'print' - ditto.
Now you have clues what to look for in the documentation:
I tried couldnt understand. anyone who can make me understand the mailme perl script.
Sorry, but it looks more like intellectual laziness.
You were given explanations what is what, i.e. which items are keywords, which items are built-in functions, which items are built-in variables.
You were also given pointer to online Perl documentation
For every kind of the above items there is good documentation.
Had you tried to read the documentation and had you posted here pieces of text from the documentation which you don't understand, I would have believed you.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.