Everyday a perl script is run by crontab .The script runs a query and dumps results in the file results.txt and hence everyday results.txt changes . I have another script that sends mail with 'results.txt' as attachement.
The problem is when the script is run manually,the results.txt changes .But when the script is run through cronjob,the results.txt does not change.However the mail sent has updated or changed results.txt.But when i see results.txt in the server i do not see changes.BUT CHANGES ARE seen in the mail..
here is my script to dump results in file:
#!usr/bin/perl use DBI; use DBD::mysql; use POSIX; $scripttime=localtime(time); @frequency=("4","10","24","48","168","240"); $user="root"; $password="bnhgfbjf"; $database="kgjthiohjo"; $dsn = "dbi:mysql:$database:localhost:3306"; $dbh= DBI->connect($dsn, $user, $password) or die "Couldn't connect to database: "; open (FILE, ">results.txt" )or die "Can't open results output file: $! +"; print FILE "**************start scripting '$scripttime'*************** +***\n"; foreach $frequency(@frequency) { $timestamp=strftime("%Y-%m-%d %H:%M:%S",localtime(time-3600*$frequency +)); $query="xyz"; print "$timestamp"; print "\n"; print "$frequency"; print "\n"; my $sth = $dbh->prepare($query); my $rv = $sth->execute or die "($DBI::err): $DBI::errstr"; print FILE "***********Fetch not started for the following categories +of frequency'$frequency' hours********************\n"; $sth->dump_results( 80, "\n", "-> ", \*FILE ); sleep(5); } close FILE or die "Error closing result file: $!\n";
In reply to problem in dumping sql results in a file by rajyalakshmi
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |