Re: Errors in Perl Function



abhi147@xxxxxxxxx wrote:
Hi all ,

I have a shell script which has a small function to find previous
day's date , which is a perl function.
When I run this script on the command line , the script runs
successfully . Whereas when I run it as a cron job , it gives errors .

The perl function in the shell script is :

### To get yesterday's date ###
function get_yesterday {
perl << "EOF"
my ($mday, $mon, $year) = (localtime(time()-86400))[3,4,5];
$mon++;
$year += 1900;
printf("%04d-%02d-%02d\n", $year, $mon, $mday);
EOF
}
yesterday=$(get_yesterday)

The errors encountered were :

$ ./test.sh
./test.sh: function: not found
2006-11-23
./test.sh: syntax error at line 15: `}' unexpected

Can anyone please tell me .. that do I need to do something extra to
run this script through crontab ?


Thanks
Lacking any formal shebang line your script is probably being executed by Bourne Shell which lacks function (and and probably isn't that happy about the $(command) syntax either). Try adding #!/bin/bash as the first line.


--

Andrew DeFaria <http://defaria.com>
If a mime is arrested do they tell him he has the right to talk?


Relevant Pages

  • Re: pop-forum Re: poplog-dev A look at Poplog on the Macintosh
    ... with the poplink command. ... When trying to make pglink produce a 'sh' rather than a 'csh' shell ... script for linking and when trying to make it put unexpanded environment ... using the shell script pglibr, ...
    (comp.lang.pop)
  • Files appear to be cross linked
    ... script requires a number of standard environment variables to be set ... so it calls a second shell script to set these at the session level, ... control should return to the first shell script, ... that the script executes to the last line prior to the displaying of ...
    (comp.unix.solaris)
  • Re: [PHP] Catch STDERR
    ... into your PHP script? ... Or do you just need STDOUT in one variable, and STDERR in another, ... Another option is to try to write a .sh shell script to get what you ...
    (php.general)
  • Re: Converting large bash script to TCL
    ... I know that TCL and shell scripting share a lot of similarities. ... The shell script ... Determine what it (the script) is supposed to do ... echo "WOULD YOU LIKE TO INSTALL NAC DRIVER ...
    (comp.lang.tcl)
  • Re: basic questions
    ... Setting a script that runs at 3:00 ... Set chron to run that shell script. ... Debug the GUI application with the REPL. ... You start up the Web browser, then browse the Web, visit a hundred ...
    (comp.lang.lisp)