The direcrory structure that i am creating is thus:
my $startTime = `date +%s`;
my $startTime2 = $startTime + 10;
chomp($startTime2);
print "startTime2: " . "$startTime2";
my $pwd = getcwd();
#my $PWD=system("pwd");
print "Current Working Directory: " . "$pwd\n";
my $logdir = "$pwd" . "/load-logs";
print "Log Directory: " . "$logdir\n";
#chmod( 755, $logdir ) or die "Couldn't chmod $logdir: $!";
mkdir("$logdir/$startTime2", 777) || print $!;
#print "start Time in epoc : "."$startTime";
#mkdir("$startTime3", 777) || print $!;
#system("mkdir \$logdir/$startTime");
my $reqlogfile = "$logdir/$startTime2/req.log";
print "reqlogfile: " . "$reqlogfile\n";
my $resplogfile = "$logdir/$startTime2/resp.log";
print "resplogfile: " . "$resplogfile\n";
now, mkdir(“$logdir/$startTime2”, 777) || print $!;
does not create a directory which has the current value of $startTime2 under $logdir
A problem may be that your
$logdirwasn’t created, so it’s best to ensure it is created.Also, it’s best to make sure the
umaskis reset so that if youchmodto0777, the parent shell’sumaskdoesn’t interfere with theumaskin the script.Perl’s
mkdirdoesn’t work as the shell’smkdir -p(which creates intermediate directories if they do not exist). One could usemkpathfrom File::Path, or simply ensure the intermediate path is created, as I show below:The above (with strict, warnings, etc) works for me:
Launching it multiple times doesn’t die, and creates the directories (and chmods them) if needed. You can check that via
ls -la load-logs/.