Scheduling tasks in ESX using cron
Log in as root to the ESX host console directly or using SSH.
Run this command to open the crontab configuration file in the vi text editor:
crontab -e
Note: To use a different editor, modify theEDITOR
environment variable. For example, to use nano:EDITOR=nano crontab -e
To start
esxtop
at the desired time, append this line to the file:minute hour day month dayofweek commandline
For example, to startesxtop
once a day at 00:01 to collect samples every 60 seconds for 1440 intervals, append the line:1 0 * * * /usr/bin/esxtop -b -d 60 -n 1440 > /tmp/esxtop-output-`hostname`-`date +%Y-%m-%dT%H-%M-%SZ`.csv &
Save the file. The changes take effect immediately and
esxtop
starts at the next scheduled time.
Note: The configuration changes on ESX persist across reboots. To revert the change, remove the esxtop
line from the crontab configuration file.
Scheduling tasks in ESXi using cron
Note: nano is not available in ESXi and, therefore, you must use the vi editor.
Open a console to the ESXi host using the Tech Support Mode.
Open the crontab file located in
/var/spool/cron/crontabs
as the root user using the vi editor.To start
esxtop
at the desired time, append this line to the file:minute hour day month dayofweek commandline
For example, to startesxtop
once a day at 00:01 and collect samples every 60 seconds for 1440 intervals, append the line:1 0 * * * /sbin/esxtop -b -d 60 -n 1440 > /scratch/esxtop-output-`hostname`-`date +%Y-%m-%dT%H-%M-%SZ`.csv &
Save the file.
Note: By default, this file is readonly. However, you can write changes to the file using the wq! key combination in the vi editor.Run this command to determine the process ID of the
crond
process:cat /var/run/crond.pid
You see output similar to:1234
Where1234
is the Process ID of thecrond
process.Run this command to restart the
crond
process:kill -HUP 1234
Note: On some ESXi versions, a manual restart is required. Run the appropriate command:
In ESXi 4.x and ESXi 5.0:
kill 1234或者kill $(cat /var/run/crond.pid)
/bin/busybox crond 或者kill $(cat /var/run/crond.pid)
In ESXi 5.1 and ESXi 5.5:
kill 1234或者kill $(cat /var/run/crond.pid)
/usr/lib/vmware/busybox/bin/busybox crond或者直接输入crond
The changes take effect immediately andesxtop
starts at the next scheduled time.
Note: The configuration changes on ESXi do not persist across reboots. To revert the change without rebooting, remove the esxtop
line from the crontab
file and kill the crond
process.
转载于:https://blog.51cto.com/hezhang/1357011