{"id":51,"date":"2025-04-25T11:05:46","date_gmt":"2025-04-25T09:05:46","guid":{"rendered":"https:\/\/paessens.org\/blog\/?p=51"},"modified":"2026-01-21T08:43:44","modified_gmt":"2026-01-21T07:43:44","slug":"esxi-add-cron-job","status":"publish","type":"post","link":"https:\/\/paessens.org\/blog\/index.php\/2025\/04\/25\/esxi-add-cron-job\/","title":{"rendered":"ESXi &#8211; Add cron Job"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">This explains how to add a cron job to ESXi host. And later make it reboot persistent.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Firstly, add the cron job to the root crontab:<br>Edit \/var\/spool\/cron\/crontabs\/root<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code># vi&nbsp;\/var\/spool\/cron\/crontabs\/root<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Add the line (all on one line) <\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>5 0 * * * \/full\/path\/to\/script arguments\/with\/full\/path &gt; \/full\/path\/to\/logfile 2&gt;&amp;1<\/code><br><br>Run the following command to detect the process number under which crond is running.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code># cat \/var\/run\/crond.pid<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Once we know the process number of the running crond, such as 12345. Run following command:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code># kill -HUP 1234<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&#8220;12345&#8221; should be replaced with the number output by the previous command<br>In order to restart the crond process use this command:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code># \/usr\/lib\/vmware\/busybox\/bin\/busybox crond<\/code><br><br>This allow us now to test the correct working of the cronjob. Now we must make it persistent.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now, add a command to \/etc\/rc.local.d\/local.sh to re-generate the cron job when ESX\/ESXi reboots<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Edit \/etc\/rc.local.d\/local.sh, using a command such as <\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code># vi \/etc\/rc.local.d\/local.sh<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">At the end of the file, add 3 lines (using &#8220;G&#8221; then &#8220;O&#8221; in vi). <br>The first kills crond, the second adds the new cron job to the root crontab file, ad the third restarts crond:<br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>\/bin\/kill $(cat \/var\/run\/crond.pid)<br>\/bin\/echo '5 0 * * * \/full\/path\/to\/script arguments\/with\/full\/path &gt; \/full\/path\/to\/logfile 2&gt;&amp;1' &gt;&gt; \/var\/spool\/cron\/crontabs\/root<br>\/usr\/lib\/vmware\/busybox\/bin\/busybox crond<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><br>Save and exit the editor (Press the &#8220;Esc&#8221; key then &#8220;:wq&#8221; then press &#8220;Return&#8221; in vi)<br>Run the command &#8220;auto-backup.sh&#8221; so that the change to \/etc\/rc.local survives a reboot.<br>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\n\n\n<p class=\"wp-block-paragraph\"><code># autobackup.sh<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Warning:<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>As you can see in the local.sh file, this script will not be executed if the host has <em>Secure Boot enable<\/em><\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">References:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/knowledge.broadcom.com\/external\/article?legacyId=1033346\">Gathering esxtop performance data using cronjobs<\/a><br><a href=\"https:\/\/wiki.tinkernet.ca\/index.php\/ESXi_-_Add_cron_Job\">ESXi &#8211; Add cron Job<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This explains how to add a cron job to ESXi host. And later make it reboot persistent. Firstly, add the cron job to the root crontab:Edit \/var\/spool\/cron\/crontabs\/root # vi&nbsp;\/var\/spool\/cron\/crontabs\/root Add the line (all on one line) 5 0 * *<\/p>\n<p><a href=\"https:\/\/paessens.org\/blog\/index.php\/2025\/04\/25\/esxi-add-cron-job\/\" class=\"awp-btn awp-btn-secondary awp-btn-bubble\">Continue Reading<span class=\"screen-reader-text\">ESXi &#8211; Add cron Job<\/span><i class=\"fa fa-arrow-right\"><\/i><span class=\"bubble_effect\"><span class=\"circle top-left\"><\/span><span class=\"circle top-left\"><\/span><span class=\"circle top-left\"><\/span>\t<span class=\"button effect-button\"><\/span><span class=\"circle bottom-right\"><\/span>\t<span class=\"circle bottom-right\"><\/span><span class=\"circle bottom-right\"><\/span><\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[16,15],"class_list":["post-51","post","type-post","status-publish","format-standard","hentry","category-esxi","tag-cronjob","tag-esxi"],"_links":{"self":[{"href":"https:\/\/paessens.org\/blog\/index.php\/wp-json\/wp\/v2\/posts\/51","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/paessens.org\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/paessens.org\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/paessens.org\/blog\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/paessens.org\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=51"}],"version-history":[{"count":3,"href":"https:\/\/paessens.org\/blog\/index.php\/wp-json\/wp\/v2\/posts\/51\/revisions"}],"predecessor-version":[{"id":54,"href":"https:\/\/paessens.org\/blog\/index.php\/wp-json\/wp\/v2\/posts\/51\/revisions\/54"}],"wp:attachment":[{"href":"https:\/\/paessens.org\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=51"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/paessens.org\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=51"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/paessens.org\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=51"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}