Gregory Machin wrote:
Hi
Hello,
I have a script that i'm working on, I want it to write info to a log
file, but I can't get it to write to the file.. I run the script as
root, and I also chmod 0777 the file but still no out put ...
what have it missed ..
___script___
#!/usr/bin/perl
print "hello";
#### use
use strict;
You should also use the pragma:
use warnings;
#package ifwatch;
### global vars
my $primaryif = "/dev/ttyACM0";
my $secondaryif = "/dev/ttyACM1";
my $primaryconfig = "/etc/ifwatch/ACM0";
my $secondayconfig = "/etc/ifwatch/ACM1";
my $currentif;
my $mainloopsleep = 10;
my $LOG_DIR = "/var/log";
&daemonize();
&main();
#### process handeling kill and restart call
$SIG{INT} = sub
{
print STATUS_LOG localtime() . " Exiting...\n";
You should probably print an error message to determine why it isn't printing
to the log file:
print STATUS_LOG localtime() . " Exiting...\n" or warn "Cannot print to the
log file: $!";
close (DEBUG_LOG);
close (ERROR_LOG);
exit;
};
$SIG{HUP} = sub
{
print STATUS_LOG localtime() . " Restarting...\n";
exec ($0, @ARGV) or die "Could not restart: $!\n";
close (STATUS_LOG);
close (STATUS_LOG);
exit;
exec() ends the current process and starts a new one so the two closes and the
exit will never execute.
};
sub ifcheck{
#my $files = "/dev/xtty0";
#Bunless (open(TESTFILE, $files)){
#die ("File does not exist");
#}
}
##### daemonize
sub daemonize {
# use POSIX qw(setsid);
open (STDIN, "/dev/null");
open (STATUS_LOG, ">> /var/log/ifwatch");
You should *ALWAYS* verify that the files opened correctly:
open STDIN, '<', '/dev/null' or die "Cannot open '/dev/null' $!";
open STATUS_LOG, '>>', "$LOG_DIR/ifwatch" or die "Cannot open
'$LOG_DIR/ifwatch' $!";
# defined(my $pid = fork) or die "Can't fork: $!";
# exit if $pid;
}
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/