Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Not checking Day variable

Status
Not open for further replies.
May 3, 2002
633
US
I am wondering why the following script is not checking the DayOfWeek variable that is set. Korn shell is my preferred method of scripting, but cannot use it in this case. The script is running and doing as needed, with the exception that it runs daily instead of only Monday (should the GetDoW check against DoW be using 'eq' instead of '=='?). Thanks, the script follows:

#!/usr/bin/perl

# load required modules
use strict;
use POSIX qw(setsid);
use POSIX qw(strftime);

# set constants
my $DoW = 'Mon';
my $Hour = '04';

# flush the buffer
$| = 1;

# daemonize the program
&daemonize;

# infinite loop
while(1) {
my $GetDoW = `date +%a`;
my $GetHour = `date +%H`;
if (($GetDoW == $DoW) && ($GetHour == $Hour)) {
system("/syslib/mail_space_report.ksh");
}
sleep(3600);
}

sub daemonize {
chdir '/' or die "Can't chdir to /: $!";
umask 0;
open STDIN, '/dev/null' or die "Can't read /dev/null: $!";
#open STDOUT, '/dev/null' or die "Can't write to /dev/null: $!";
open STDERR, '/dev/null' or die "Can't write to /dev/null: $!";
defined(my $pid = fork) or die "Can't fork: $!";
exit if $pid;
setsid or die "Can't start a new session: $!";
}
 
when you get the output of something using `` you get everything, including the line-feed character on the end of it

get rid of that character like this

chomp($GetDoW);

this will remove the LF char if it's there and do nothing if it isn't

try the comparison with 'Mon' after doing that Mike
________________________________________________________________

"Experience is the comb that Nature gives us, after we are bald."

Is that a haiku?
I never could get the hang
of writing those things.
 
get's me everytime I do some programming in the shell and then come back to Perl.... Perl *never* strips the LF char unless you ask it to with chomp/chop Mike
________________________________________________________________

"Experience is the comb that Nature gives us, after we are bald."

Is that a haiku?
I never could get the hang
of writing those things.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top