简体   繁体   中英

Cron job not running created by 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 ie * * * * /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

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']
}
........

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM