Help with date

M

mikev

I have the following Perl code that displays the results of a call to
sar with parameters. This one calls from a specific file. I would
like to automate the file called by appending the 2 digit day of the
month to the end (ie. /var/adm/sa/sa05) I can get the date using a
unix command `date +%d` but it does not work in the script. Thanks in
advance

###################################################
#!/usr/bin/perl -w
use strict;
use CGI;
my $query = CGI->new();
print $query->header( "text/html" ),
$query->start_html(-title => "My First CGI Script",
-bgcolor => "#ffffcc" ),
$query->h1( "AIX System System Activity Report" ),
$query->p( `date` ),
$query->p("<pre>"),
$query->p( `sar -ubcwyaqvmf /var/adm/sa/sa05`),
$query->p("</pre>"),
$query->end_html;
 
T

Tad McClellan

I would
like to automate the file called by appending the 2 digit day of the
month to the end (ie. /var/adm/sa/sa05)


my $fname = sprintf '/var/adm/sa/sa%02d', (localtime)[3];
 
M

mikev

This is the final code. Thanks for your help.
#!/usr/bin/perl -w
use strict;
use CGI;
my $fname = sprintf '/var/adm/sa/sa%02d', (localtime)[3]-1;
my $query = CGI->new();
print $query->header( "text/html" ),
$query->start_html(-title => "System Activity Report",
-bgcolor => "#ffffcc" ),
$query->h1( "AIX System System Activity Report for ".`uname -n` ),
$query->p( `date` ),
$query->p( "System Activity Report for the Current Day." ),
$query->p("<a href=/SAR/>Home</a><br>"),
$query->p("<a href=/SAR/>Home</a><br>"),
$query->p("<pre>"),
$query->p( `sar -s 00:01 -e 23:50 -i 3600 -ubcwyaqvmf $fname`),
$query->p("<a href=/SAR/>Home</a><br>"),
$query->p("</pre>"),
$query->end_html;
 
A

A. Sinan Unur

This is the final code. Thanks for your help.
#!/usr/bin/perl -w
use strict;
use CGI;
my $fname = sprintf '/var/adm/sa/sa%02d', (localtime)[3]-1;
my $query = CGI->new();
print $query->header( "text/html" ),
$query->start_html(-title => "System Activity Report",
-bgcolor => "#ffffcc" ),
$query->h1( "AIX System System Activity Report for ".`uname -n` ),
$query->p( `date` ),

There is not that much of a point to shelling out twice for tasks easily
accomplished using Perl.

perldoc Sys::Hostname

Sys::Hostname::hostname only invokes uname if other methods fail.
$query->p( "System Activity Report for the Current Day." ),
$query->p("<a href=/SAR/>Home</a><br>"),
$query->p("<a href=/SAR/>Home</a><br>"),

Decide whether you want to use CGI.pm to generate HTML, or not. Then
stick with one style. It is easy to lose track and make errors when you
use this kind of mish-mash.
$query->p("<pre>"),

What was I saying?

D:\Dload> perl -MCGI -e "print CGI::p('<pre>')"
$query->p( `sar -s 00:01 -e 23:50 -i 3600 -ubcwyaqvmf $fname`),
$query->p("<a href=/SAR/>Home</a><br>"),
$query->p("</pre>"),

Again:

D:\Dload> perl -MCGI -e "print CGI::p('</pre>')"
<p></pre></p>

Sinan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,170
Messages
2,570,925
Members
47,468
Latest member
Fannie44U3

Latest Threads

Top