Crontab Demystified

A crontab file has five fields for specifying time intervals, followed by the command to be executed.

*   *   *   *   *      command to be executed
-   -   -   -   -
|   |   |   |   |
|   |   |   |   +----- day of week (0-6 or 1-7) (Sunday = 0 and 7)
|   |   |   +--------- month (1-12)
|   |   +------------- day of month (1-31)
|   +----------------- hour (0-23)
+--------------------- minute (0-59)

In a Linux crontab file, day of week is unique because 0 and 7 both stand for Sunday, where one can use 0-6 or 1-7 to achieve the same result. However, a BusyBox crontab file treats 0 (zero) as Sunday. If you set the day of the week to 7, BusyBox will go nuts and run the command every day.

The character * means "every". For example: A * * * * * line would execute a command every minute, of every hour, of every day, of every week, of every month.

The character combination */ means "every/interval". For example: A */17 * * * * line would execute a command every 17 minutes, and a * * */5 * * line would execute a command every 5 days.

To view the crontab file, execute the following command.

crontab -l

Here is the crontab file from the My Cloud PR4100 NAS in its raw form. Note that several entries have leading zeros (00, 01, etc), which can potentially cause cron jobs to fail.

0 3 * * * /usr/sbin/daily_log_upload.sh &
0 3 * * * /usr/sbin/traceroute_wd.sh &
*/30 * * * * /usr/sbin/quota_monitor &
*/10 * * * * /usr/sbin/rlog -s /usr/local/modules/files/syslog_rotate.conf
01 */8 * * * [ -f /etc/init.d/atop ] && /etc/init.d/atop rotate
30 0 * * * /usr/local/sbin/ssl_cert_job.sh start > /var/log/ssl_cert_cron.out 2>&1
58 2 * * * /usr/local/sbin/PullWdlogConfig.sh
30 0 * * 1 logwdmsg -e &
0 3 * * * logwdmsg -o &
01 3 * * * /usr/local/sbin/LogDataSize.sh
00 3 * * * /usr/sbin/wd_rotate.sh
30 0 * * 1 /usr/sbin/wdappmgr_log_stats.py > /dev/null 2>&1 &
30 2 * * * /usr/sbin/stime&
0 3 * * * wd_crontab.sh&
0 4 * * * auto_fw -a -c&
0 0 * * * auto_clear_recycle_bin.sh &
30 3 * * * /usr/sbin/chk_wfs_download&
0 0 * * * random_check -s &
0 0 * * * expire.sh
7 13 * * * auto_fw -c 1 &
* * * * * sysinfo_update.sh
0 3 * * 1 getHddWhiteList.sh

Here is the crontab file the My Cloud PR4100 NAS, demystified and sorted by time intervals.

Every 1 minute
* * * * * sysinfo_update.sh

Every 10 minutes
*/10 * * * * /usr/sbin/rlog -s /usr/local/modules/files/syslog_rotate.conf

Every 30 minutes
*/30 * * * * /usr/sbin/quota_monitor &

First minute of every 8th hour
1 */8 * * * [ -f /etc/init.d/atop ] && /etc/init.d/atop rotate **(Corrected from: 01 /8 * * )

Every day at 12:00 AM or 00:00 hours.
0 0 * * * auto_clear_recycle_bin.sh &
0 0 * * * random_check -s &
0 0 * * * expire.sh

Every day at 12:30 AM or 00:30 hours.
30 0 * * * /usr/local/sbin/ssl_cert_job.sh start > /var/log/ssl_cert_cron.out 2>&1

Every Day at 2:30 AM or 02:30 hours.
30 2 * * * /usr/sbin/stime&

Every day at 2:58 AM or 02:58 hours.
58 2 * * * /usr/local/sbin/PullWdlogConfig.sh

Every day at 3:00 AM or 03:00 hours.
0 3 * * * /usr/sbin/daily_log_upload.sh &
0 3 * * * /usr/sbin/traceroute_wd.sh &
0 3 * * * logwdmsg -o &
0 3 * * * wd_crontab.sh&
0 3 * * * /usr/sbin/wd_rotate.sh *(Corrected from: 00 3 * * )

Every day at 3:01 AM or 03:01 hours.
1 3 * * * /usr/local/sbin/LogDataSize.sh *(Corrected from: 01 3 * * )

Every day at 3:30 AM or 03:30 hours.
30 3 * * * /usr/sbin/chk_wfs_download&

Every day at 4:00 AM or 04:00 hours.
0 4 * * * auto_fw -a -c&

Every day at 1:07 PM or 13:07 hours.
7 13 * * * auto_fw -c 1 &

Monday at 12:30 AM or 00:30 hours.
30 0 * * 1 logwdmsg -e &
30 0 * * 1 /usr/sbin/wdappmgr_log_stats.py > /dev/null 2>&1 &

Monday at 3:00 AM or 03:00 hours.
0 3 * * 1 getHddWhiteList.sh

Portions of the crontab file originate from a config.xml file. Note that the <crond> section of the config.xml file has malformed XML. In other words, element names can’t start with a number.

<crond>
	<list>
		<count>6</count>
		<name id="1">stime</name>
		<name id="2">wd_crontab</name>
		<name id="3">fw_available</name>
		<name id="4">app_get_info</name>
		<name id="5">recycle_bin_clear</name>
		<name id="6">chk_wfs_download</name>
	</list>
	<stime>
		<count>1</count>
		<item id="1">
			<method>3</method>
			<1>30</1>
			<2>2</2>
			<3>*</3>
			<4>*</4>
			<5>*</5>
			<run>/usr/sbin/stime&amp;</run>
		</item>
	</stime>
	<wd_crontab>
		<count>1</count>
		<item id="1">
			<method>3</method>
			<1>0</1>
			<2>3</2>
			<3>*</3>
			<4>*</4>
			<5>*</5>
			<run>wd_crontab.sh&amp;</run>
		</item>
	</wd_crontab>
	<fw_available>
		<count>1</count>
		<item id="1">
			<method>3</method>
			<1>0</1>
			<2>3</2>
			<3>*</3>
			<4>*</4>
			<5>*</5>
			<run>auto_fw -c 1&amp;</run>
		</item>
	</fw_available>
	<app_get_info>
		<count>1</count>
		<item id="1">
			<method>3</method>
			<1>0</1>
			<2>4</2>
			<3>*</3>
			<4>*</4>
			<5>*</5>
			<run>auto_fw -a -c&amp;</run>
		</item>
	</app_get_info>
	<recycle_bin_clear>
		<count>1</count>
		<item id="1">
			<method>3</method>
			<1>0</1>
			<2>0</2>
			<3>*</3>
			<4>*</4>
			<5>*</5>
			<run>auto_clear_recycle_bin.sh &amp;</run>
		</item>
	</recycle_bin_clear>
	<chk_wfs_download>
		<count>1</count>
		<item id="1">
			<method>3</method>
			<1>30</1>
			<2>3</2>
			<3>*</3>
			<4>*</4>
			<5>*</5>
			<run>/usr/sbin/chk_wfs_download&amp;</run>
		</item>
	</chk_wfs_download>
</crond>

Other portions of the crontab file seem to originate from scripts or executable binary files. In addition, changes to the crontab file are reverted after some time has passed, likely because the entire root filesystem, with the exception of user share files, originates from a ramdisk. Otherwise, much remains unknown about exactly what each scheduled cron job does on the My Cloud series. In time, I hope to change this.

In the mean time, the following guide may be helpful.

1 Like

Thanks for taking the time out to provide this guide.

hello, just found your interesting topic because I’d like to add an entry to the crontab on my ex4100 model. Adapting your infos to my hardware, I found config.xml mounted as an ubi partition on /usr/local/config:

# mount | grep config
ubi0:config on /usr/local/config type ubifs (0)

The strange fact here is that my config.xml file at the crond section contains 12 subsections while the count tag under list reports “6”:

           <crond>                                                    
                    <list>                                       
                            <count>6</count>                         
                            <name id="1">stime</name>
                            <name id="2">wd_crontab</name>
                            <name id="3">app_get_info</name>
                            <name id="4">recycle_bin_clear</name>
                            <name id="5">chk_wfs_download</name>
                            <name id="6">ga_cron_q</name>      
                            <name id="7">ga_cron_d</name>          
                            <name id="8">internal_backup</name>
                            <name id="9">random_check</name>
                            <name id="10">fw_available</name>  
                            <name id="11">user_expire_chk</name>   
                            <name id="12">pull_wdlog_config</name>
                    </list>

stranger is that the crontab -l reports even more tasks:

 # crontab -l
 0 3 * * * /usr/sbin/daily_log_upload.sh &
 0 3 * * * /usr/sbin/traceroute_wd.sh &
 */30 * * * * /usr/sbin/quota_monitor &
 0 */4 * * * /usr/sbin/rlog -s /usr/local/modules/files/syslog_rotate.conf
 01 */8 * * * [ -f /etc/init.d/atop ] && /etc/init.d/atop rotate
 30 0 * * * /usr/local/sbin/ssl_cert_job.sh start > /var/log/ssl_cert_cron.out 2>&1
 0 0 * * * random_chk_central -s &
 30 0 * * 1 logwdmsg -e &
 0 3 * * * logwdmsg -o &
 01 3 * * * /usr/local/sbin/LogDataSize.sh
 00 3 * * * /usr/sbin/wd_rotate.sh
 30 0 * * 1 /usr/sbin/wdappmgr_log_stats.py > /dev/null 2>&1 &
 30 2 * * * /usr/sbin/stime&
 0 3 * * * wd_crontab.sh&
 0 4 * * * auto_fw -a -c&
 0 0 * * * auto_clear_recycle_bin.sh &
 30 3 * * * /usr/sbin/chk_wfs_download&
 */15 * * * * ga_cron.sh quarter &
 51 17 * * * ga_cron.sh daily &
 0 0 * * * random_check -s &
 8 23 * * * auto_fw -c 1 &
 0 0 * * * expire.sh
 29 23 * * * /usr/local/sbin/PullWdlogConfig.sh
 * * * * * sysinfo_update.sh
 0 3 * * 1 getHddWhiteList.sh

Maybe this is related to differences between my model (EX4100) and yours? Is it safe to alter the config.xml anyway?