Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cron job not running created by puppet

Tags:

linux

cron

puppet

I want to add 1 cron job in to the machine that will run every 5 minutes, for that I am using this manifest:

class cron_job{

    file{"puppet_ls":
            path => "/puppet/pls.sh",
            ensure => present,
            content => "#!/bin/sh\necho \"Hello World\"\nls -ltr /etc/puppet > /puppet/dump.txt"
    }

    file { "my_ls.cron":
        path    => "/etc/cron.d/my_ls.cron",
        ensure  => present,
        owner   => "root",
        group   => "root",
        mode    => 0644,
        require => File["puppet_ls"],
        content => "*/1 * * * *  /puppet/pls.sh\n";
    }
}

So this manifest do 2 things,

  1. It makes a file /puupet/pls.sh with the content specifie, that is actually running the command ls-ltr /etc/puppet
  2. It makes an entry in the form of cron job for inside daily category and if you see the last line i.e * * * * /puppet/pls.sh\n, says that run after every 1 minute(for testing I kept one)

But I am not getting the file dump.txt inside /puppet/ Also if I runs, sh /puppet/pls.sh, it runs perfectly and generates the dump.

I am unable to understand where is the glitch.. :(

Please shed some light..

Thanks Ankur

like image 848
Ankur Verma Avatar asked Mar 21 '14 07:03

Ankur Verma


2 Answers

You should use the cron type that is built in to puppet.

file { '/puppet/pls.sh':
    content => "#!/bin/sh\necho \"Hello World\"\nls -ltr /etc/puppet > /puppet/dump.txt",
    mode    => 0755, 
}

cron { 'helloworld':   
   command => "/puppet/pls.sh",   
   user    => root,
   hour    => '*',   
   minute  => '*/5',
   require => File['/puppet/pls.sh']
}
........
like image 198
Ben Whaley Avatar answered Sep 23 '22 21:09

Ben Whaley


Crontab files placed in /etc/cron.d, or other cron. directories under /etc cannot have periods in their name.

This is a known bug: https://bugs.launchpad.net/ubuntu/+source/debianutils/+bug/38022

Removing the period from your filename (my_ls.cron) should resolve the issue.

like image 31
Brandon Galbraith Avatar answered Sep 21 '22 21:09

Brandon Galbraith