Running a cron job on Linux every six hours

LinuxCron

Linux Problem Overview


How can I run command every six hours every day?

I tried the following, but it did not work:

/6 * * * * *  mycommand

Linux Solutions


Solution 1 - Linux

You forgot a *, and you've too many fields. It's the hour you need to care about

0 */6 * * * /path/to/mycommand

This means every sixth hour starting from 0, i.e. at hour 0, 6, 12 and 18 which you could write as

0 0,6,12,18 * * * /path/to/mycommand

Solution 2 - Linux

You should include a path to your command, since cron runs with an extensively cut-down environment. You won't have all the environment variables you have in your interactive shell session.

It's a good idea to specify an absolute path to your script/binary, or define PATH in the crontab itself. To help debug any issues I would also redirect stdout/err to a log file.

Solution 3 - Linux

0 */6 * * * command

This will be the perfect way to say 6 hours a day.

Your command puts in for six minutes!

Solution 4 - Linux

Please keep attention at this syntax:

* */6 * * *

This means 60 times (every minute) every 6 hours,

not

one time every 6 hours.

Solution 5 - Linux

0 */6 * * *

crontab every 6 hours is a commonly used cron schedule.

Solution 6 - Linux

You need to use *

0 */6 * * * /path/to/mycommand

Also you can refer to https://crontab.guru/ which will help you in scheduling better...

Solution 7 - Linux

Try:

0 */6 * * * command

. * has to

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionGandalf StormCrowView Question on Stackoverflow
Solution 1 - LinuxnosView Answer on Stackoverflow
Solution 2 - LinuxBrian AgnewView Answer on Stackoverflow
Solution 3 - LinuxrkootsView Answer on Stackoverflow
Solution 4 - LinuxAndrea BiselloView Answer on Stackoverflow
Solution 5 - LinuxNilesh PatilView Answer on Stackoverflow
Solution 6 - LinuxrkootsView Answer on Stackoverflow
Solution 7 - LinuxrkootsView Answer on Stackoverflow