I should add the line to /var/spool/cron/crontabs/root on my ESXi: /bin/echo "0 3 * * 6 /ghettoVCB-master/ghettoVCB.sh -g /ghettoVCB-master/text.conf -f /ghettoVCB-master/text.list > /var/log/ghettoVCB-month-$(date +%m)-week-$((($(date +\%d)-1)/7+1)).log" >> /var/spool/cron/crontabs/root.

But this comandline adds a reasult of $(date +%m) and $((($(date +\%d)-1)/7+1)).

How to add this line as a formula? Thanks in advance.

1 Answer 1


There are a few things to improve here:

  • cron will not notice changes made directly to the files in /var/spool/cron. Use crontab -e instead.
    There's also /etc/crontab, which might be preferred for system-wide maintenance tasks like this.
    (The crontabs in /etc (also /etc/cron.*) are the only ones you can edit directly. They also have a different format than the ones exposed via the crontab command.)

  • % is a special character in crontabs. Escape it with a backslash when using it in arguments, e.g. date +\%m.

  • date should understand the format string %W as "week number of year, with Monday as first day of week (00..53)" -- no need to calculate it yourself.

  • Your cron might not run the crontab commands in a shell that supports process substitution ($()). You can explicitly run your command in a shell like sh -c 'echo $(date) > /tmp/foo' to be sure.

  • Thanks for your cron-related advices. As I got, start.sh with all expressions is my way. As I found, all my settings will be removed at ESXi system restart If I put start.sh directly to cron file. Adding the command that changes the cron file at /etc/rc.local.d/local.sh should help.
    – A_buddy
    Apr 1, 2016 at 5:22

Not the answer you're looking for? Browse other questions tagged or ask your own question.