{"id":174,"date":"2013-04-26T07:14:05","date_gmt":"2013-04-26T07:14:05","guid":{"rendered":"http:\/\/test.bleuanus.nl\/index.php\/esx\/add-cronjob-to-vmware\/"},"modified":"2018-12-11T16:09:08","modified_gmt":"2018-12-11T15:09:08","slug":"add-cronjob-to-vmware","status":"publish","type":"post","link":"https:\/\/www.bleuanus.nl\/index.php\/2013\/04\/26\/add-cronjob-to-vmware\/","title":{"rendered":"Add Cronjob to VMware"},"content":{"rendered":"<p class=\"last-modified\">This post was most recently updated on December 11th, 2018<\/p><h1>Add cron Job to VMware ESX\/ESXi<\/h1>\n<p>\u00a0<\/p>\n<p>This explains how to add a cron job to VMware in such a way that it will still be there after reboots.<\/p>\n<p>\u00a0<\/p>\n<p>Having enabled ssh access to your ESX\/ESXi server, ssh in as root.<\/p>\n<p>\u00a0<\/p>\n<p>Firstly, add the cron job to the root crontab:<\/p>\n<ol>\n<li>Edit \/var\/spool\/cron\/crontabs\/root<\/li>\n<li>Add the line (all on one line) 5 0 * * * \/full\/path\/to\/script arguments\/with\/full\/path > \/full\/path\/to\/logfile 2>&#038;1<\/li>\n<li>Run the command &#8220;cat \/var\/run\/crond.pid&#8221;\u00a0That will print the process number of the running crond, such as 12345<\/li>\n<li>Run the command &#8220;kill 12345&#8221;\u00a0where &#8220;12345&#8221; should be replaced with the number output by the previous command<\/li>\n<\/ol>\n<p>\u00a0<\/p>\n<p>For details of the meaning of &#8220;5 0 * * *&#8221; (5 minutes past midnight every day) read the man page for crontab(5) on any Unix\/Linux server, or else on the web.<\/p>\n<p>\u00a0<\/p>\n<p>Now, add a command to \/etc\/rc.local to re-generate the cron job when ESX\/ESXi reboots<\/p>\n<ol>\n<li>Edit \/etc\/rc.local, using a command such as &#8220;vi \/etc\/rc.local&#8221;.<\/li>\n<li>At the end of the file, add 3 lines (using &#8220;G&#8221; then &#8220;O&#8221; in vi). The first kills crond, the second adds the new cron job to the root crontab file, ad the third restarts crond:\n<ul>\n<li>\/bin\/kill $(cat \/var\/run\/crond.pid)<\/li>\n<li>\/bin\/echo &#8216;5 0 * * * \/full\/path\/to\/script arguments\/with\/full\/path > \/full\/path\/to\/logfile 2>&#038;1&#8217; >> \/var\/spool\/cron\/crontabs\/root<\/li>\n<li>\/bin\/busybox crond<\/li>\n<\/ul>\n<\/li>\n<li>Save and exit the editor (Press the &#8220;Esc&#8221; key then &#8220;:wq&#8221; then press &#8220;Return&#8221; in vi)<\/li>\n<li>Run the command &#8220;auto-backup.sh&#8221; so that the change to \/etc\/rc.local survives a reboot.<\/li>\n<\/ol>\n<p>\u00a0<\/p>\n<p>Every time you change the cron job, remember to update \/etc\/rc.local as well and run the &#8220;auto-backup.sh&#8221; command to backup the new \/etc\/rc.local file.<\/p>\n<p>\u00a0<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This post was most recently updated on December 11th, 2018Add cron Job to VMware ESX\/ESXi \u00a0 This explains how to add a cron job to VMware in such a way that it will still be there after reboots. \u00a0 Having enabled ssh access to your ESX\/ESXi server, ssh in as root. \u00a0 Firstly, add the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-174","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.bleuanus.nl\/index.php\/wp-json\/wp\/v2\/posts\/174","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bleuanus.nl\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bleuanus.nl\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bleuanus.nl\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bleuanus.nl\/index.php\/wp-json\/wp\/v2\/comments?post=174"}],"version-history":[{"count":1,"href":"https:\/\/www.bleuanus.nl\/index.php\/wp-json\/wp\/v2\/posts\/174\/revisions"}],"predecessor-version":[{"id":228,"href":"https:\/\/www.bleuanus.nl\/index.php\/wp-json\/wp\/v2\/posts\/174\/revisions\/228"}],"wp:attachment":[{"href":"https:\/\/www.bleuanus.nl\/index.php\/wp-json\/wp\/v2\/media?parent=174"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bleuanus.nl\/index.php\/wp-json\/wp\/v2\/categories?post=174"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bleuanus.nl\/index.php\/wp-json\/wp\/v2\/tags?post=174"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}