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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.