[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: command substitution in a crontab with SHELL=/bin/bash



On Fri, 23 Feb 2001, Britton wrote:

> 
> I am trying to do approximately this in a crontab:
> 
> SHELL=/bin/bash
> 0 8 * * * prog >/tmp/$(date +%s).extension
> 
> and it doesn't work, the command never gets executed.  Backtick
> substitution doesn't work either.  An identical command with a fixed
> string in place of the $(date +%s) command substitution works perfectly.
> An identical command executed on the command line works perfectly.
> Anyone have any guesses as to what might be going on here?

I guess you were quite reluctant to write a simple script.

My (not-quite-improving) Perl script that could be working:
#!/usr/bin/perl
@lines = `prog`;
$date = `date +%s`;
chomp $date;
$filename = $date.".extension";
open(OUT,">/tmp/$filename");
for (@lines) {
  print OUT $_;
}
close(OUT);
exit 0;

Then replace the "proc" in your crontab with the name of the script.

BTW, I believe that the script can be reduced into about three lines;
unfortunately, I don't know how.

Oki



Reply to: