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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Garbage in output file when using cron. 2

Status
Not open for further replies.

ejaggers

Programmer
Feb 26, 2005
148
US
I run this code in cron using open(OFH,">$logFH"), and got the first line in the output file with no garbage. But open(OFH,">>$logFH"), gives me garbage at the beginning of the line. However it does NOT give garbage when running it from the command line. Can anybody help???

tt.pl
Code:
#!/usr/bin/perl
      system('clear');
      use strict;
      use lib '/home/ejaggers/Perl/Lib';
      use  UtilityLibrary;

      my $dir      =  '/home/informix/Primero';
      my $logFH    =  $dir . "/ecj";

      open(OFH,">>$logFH");
      my $today  = `date`;
      print OFH "SQL Start: $today";

tt.sh
Code:
#!/usr/bin/ksh
. /etc/profile.d/set_informix.sh
. /etc/profile.d/perl5lib.sh

DIR=/home/informix/Primero
perl $DIR/tt.pl $LOG

cron
Code:
18 16 * * 1-5 ./Primero/tt.sh ecj >> ./Primero/ecj 2>&1


output file
Code:
SQL Start: Mon Aug 24 16:15:01 CDT 2009
^[[H^[[JSQL Start: Mon Aug 24 16:18:01 CDT 2009
 
First some suggestions, doing things with ./ is going to cause problems, hard code the full paths in. Why have .sh script calling a perl script? Why not just do it all in perl?


I'm assuming you are having problems with your ecj file because your printing into it twice.. once within in the script, and also your sending any printable output to it from this part >> ./Primero/ecj 2>&1

Try changing that to /dev/null or another log file and see what's up.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
That "garbage" is from the clear command trying to clear a screen, which makes no sense when the output is a file.

Annihilannic.
 
Annihilannic, you're right about the 'clear' not making sense running in cron. It was left in because I can also run the job manually. BUT you're also right about it being the culprit, I thought it would just be ignored.
 
If you want your perl script to clear the screen *only* when run by hand you need to test to see if it's being run "interactively".
The simple way to do that is like this:
Code:
if (-t STDIN && -t STDOUT) {
    # Do whatever you need here to clear the screen
}
Or, you could look at the IO::Interactive module.

HTH.


Trojan.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top