1

I got a script which runs in a cronjob as root. The problem is that the addgroup command would output "Command not found" when it gets executed by the script.

#!/usr/bin/perl

$datei = `ls /var/www/cron/`;
@datei = split(/\n/, $datei);

foreach ( @datei ) {
    $datei = $_;
    open(bfh,"</var/www/cron/$datei") or die $!;
    while ( <bfh> ) {
        chomp($_);
        print "$_\n";
        system("$_\n");
    }
    #unlink("/var/www/cron/$datei") or die $!;
}

Crontab

  * * * * * /usr/bin/perl /home/hermes/cron.pl >> /home/hermes/cronlog
  2>> /home/hermes/cronerr

1 Answer 1

1

Simply use absolute paths. Cronjobs run in a very minimal environment. The PATH variable may not contain what you expect.

Other than that: Set up sudo. Your current approach is hardly ideal.

4
  • I'm already using absolute paths in the crontab. I would like to use sudo, but it isnt preinstalled in Debian and i'm not allowed to install it.
    – ProfGhost
    Commented May 21, 2014 at 6:49
  • I’m of course referring to your „sub-jobs“ that are collected from /var/www/cron/*. Perl has its own logic for that, by the way.
    – Daniel B
    Commented May 21, 2014 at 7:02
  • I've copied the content of the PATH variable into the script. The problem is that is now outputting nothing.
    – ProfGhost
    Commented May 21, 2014 at 9:38
  • You’re not checking the return value of system(). You’re also not doing what I told you: Put the absolute path(s) in your “job files”! Other than that, I must, again, really advise against this approach. Please talk to your superior or whatever.
    – Daniel B
    Commented May 21, 2014 at 21:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .