Puppet: couldn't run a cron job

0 votes

I need to run a cron job every 5 mins, and to accomplish this I have a 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";
    }
}

This manifest creates a file /puupet/pls.sh with the content specific, that is actually running the command ls-ltr /etc/puppet and  * * * * /puppet/pls.sh\n, specifies to run it after every 1 minute.

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

What is the glitch here? Can Somebody help?

Aug 8 in Puppet by Karan
• 1,170 points
8 views

1 answer to this question.

0 votes

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']
}
answered Aug 8 by Sirajul
• 16,920 points

Related Questions In Puppet

0 votes
1 answer

Docker with Puppet: Run a conatiner using a native volume

When using the volumes array with docker::run, the command on ...READ MORE

answered 2 days ago in Puppet by Sirajul
• 16,920 points
6 views
0 votes
0 answers
0 votes
1 answer

How do I start a puppet server?

Hey if you're using Ubuntu, you can ...READ MORE

answered Feb 21 in Puppet by Kavyashri
23 views
0 votes
1 answer

How is puppet used as a Configuration Management tool?

System Administrators usually perform repetitive tasks such ...READ MORE

answered Mar 4 in Puppet by Saurab
50 views
+13 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 26, 2018 in DevOps & Agile by DragonLord999
• 8,380 points
111 views
0 votes
1 answer
0 votes
1 answer

Creating a cron job in puppet

Running a Puppet agent with cron can ...READ MORE

answered Jul 29 in Puppet by Sirajul
• 16,920 points
23 views
0 votes
1 answer