5

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

Ankur Verma
  • 5,793
  • 12
  • 57
  • 93

2 Answers2

8

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']
}
........
Sirex
  • 219
  • 4
  • 22
Ben Whaley
  • 32,811
  • 7
  • 87
  • 85
  • The `cron` type built into puppet doesn't support system crontabs in /etc/cron.d: http://www.puppetcookbook.com/posts/managing-crond-entries.html – Brandon Galbraith Jan 13 '15 at 16:43
4

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.