How to setup Cron jobs in ESXi host.

 Hi Everyone,

This post covers, how to run or schedule a Cron job in ESXi hosts. 

However, ESXi does not need to run a cron job, i never seen the cron job uses on ESXi platform as it is heavily use on Linux and Unix systems to automate the scripts.

But, few days back, i was getting struggled to one of my ESXi 6.5 host which is getting disconnected from vcenter in every 4-5 hours. It is also stopped to pinging as well. I have to restart the management agents to take back on the network via DCUI.

I tried to get the logs but didn't find the actual root cause of this issue. I didn't spend too much time to find the issue as well since it is a developement host running as a standalone.

I was thinking to rebuild it as well but several VMs running on this host and since it is development host, so we have a single logical volume which consists ESX footprint as well as VMs footprint.

So, i can't rebuild it anymore.

Now, I don't want to leave it as it is as well because the Development team was chasing me when VMs got unreachable so it will be a pain for me to do a restart of Management agent on the hosts daily basis.

I want a solution for this issue. So, i thought lets schedule a powershell script (As I am from Windows Background so powershell comes in mind first) to restart the management agent in every 2-3 hours and it can save my time to manually to do this.

But, later i thought to check shell script or anything which can be run locally from ESXi host. So, i found the cron job thing and i decide to schedule a cron job to restart the management agent on the host.

Let's do it now.

Login to ESXi via SSH or DCUI shell.

Run command 

# Cat /var/spool/cron/crontabs/root  >>>> this command will display you the all cron job list.

As you can see above, ESXi already uses some cron jobs to schedule several script for internal purpose.

Before changing the file, be sure to back it up just in case any issues.

Run below command to back the file.

#cp /var/spool/cron/crontabs/root /var/spool/cron/crontabs/root.old

Then, you can edit this file via below command.

#vi /var/spool/cron/crontabs/root

I have added the below parameter to restart the hostd and vpxa service in every 3 hours.

 

Our changes will not take effect until the crond services restart on the host.                                          

 Let's find out the crond service PID via below command.

 

Now, kill the crond PID via below command.

#kill 66612

Now, start the crond service and make sure PID number gets changed as well.

And, PID number gets change as well.

Hopefully, your command will execute as per the interval you set on the cron job.

Hope, this is informative, thanks. Cheers !!!

Comments

Popular posts from this blog

How to migrate the N-VDS as the host switch to VDS 7.0 in NSX-T 3.x

vROPS appliances password remediation tasks failed from SDDC manager

How to Import/Register a VM into vRA portal