agaream has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w use strict; use warnings; use Getopt::Long; #variable declaration my $exec_mode; my $param; my $paramfile; my $log_loc= "/logs/default_log.txt"; my $interv =2; GetOptions( "e=s" => \$exec_mode, "p=s" => \$param, "pf=s" => \$paramf +ile, "l=s" => \log_loc, "i=i" => \$interv); if($exec_mode eq 'start') { if( $paramfile eq NULL) { &startsar ($param, $interv); } else { &startsar ($paramfile, $interv); } elsif($exec_mode eq 'stop') { &stopsar ( $log_loc); } else { print " usage sarexec -arguemrnts are-\n -e <start>/<stop>\n -p <p +arams> \n -pf <param_file> \n -l <location> (by default location is ' +/logs/default_log.txt')\n -i <interval> ( by default interval is 2)\n + " } sub startsar { if (substr($_[0],0,1) eq "-") { my $pid = fork(); if($pid>0) { #parent } else { system("sar -o logfile $_[0] $interval 0 + > /dev/null&"); # this utility must run in background and able to cl +ose the script exit 0; } } else { chomp $_[0]; my $param; open FH,"< $_[0]" or die"cant open the fil +e"; $param = <FH>; close FH or die "cant close the file"; chomp($param); my $pid = fork(); if($pid>0) { #parent } else { system("sar -o logfile $param $interval + 0 > /dev/null&"); # this utility must run in background and able to +close the script exit 0; } } } sub stopsar { system("kill \$(pidof sadc)"); system("sar -f logfile>>$_[0]"); }
Edited by planetscape - added link to previous question, to which this is a followup
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Running Perl Script on ssh from remote machine
by UnderMine (Friar) on May 12, 2006 at 11:29 UTC | |
|
Re: Running Perl Script on ssh from remote machine
by graff (Chancellor) on May 13, 2006 at 05:19 UTC | |
|
Re: Running Perl Script on ssh from remote machine
by jesuashok (Curate) on May 12, 2006 at 11:30 UTC |