Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cloudinit how to schedule a periodic task while bootstrapping a vm

Tags:

cloud-init

While creating vm using Nova boot I am supplying it a user-data script (cloud-init script).

what I am wondering is, how can I specify in that cloud init script( or any other way to do it) :- to schedule a cron job to run every 2 hours

lets say I want to run "du -s njain/ " to find the size of my directory every 2 hours

I know "runcmd" can be used to do it once..but how do i make it run periodically ? du -s ../njain/

like image 914
user2574872 Avatar asked Feb 17 '15 21:02

user2574872


1 Answers

it might be too late now, but the right way to do it through cloud-init is just to use the cloud-config write_files module and create a cron entry file in /etc/cron.d

for your example, the cloud-init userdata would look something like:

#cloud-config 

write_files:
  - owner: root:root
    path: /etc/cron.d/your_cronjob
    content: * */2 * * * [USER] du -s njain/

Note: you must replace [USER] with the user you'd like to run the cronjob as.

like image 178
cjdcordeiro Avatar answered Nov 24 '22 09:11

cjdcordeiro