Moxa DA-682A-C7-W7E [14/112] Cron for executing scheduled commands

Moxa DA-682A-C7-W7E [14/112] Cron for executing scheduled commands
DA-682A Linux Softrware Software Configuration
2-8
start)
start-stop-daemon --start --quiet --oknodo --pidfile /var/run/tcps2.pid
--exec /usr/sbin/tcps2
;;
stop)
start-stop-daemon --stop --quiet --oknodo --pidfile /var/run/tcps2.pid
;;
esac
exit 0
After creating the script, you will now add it as a scheduled service using insserv.
To add tcps2 as a service that will start at boot time and run at every runlevel, use the following syntax:
moxa@MOXA:~#sudo insserv -v -d tcps2
Check to see that the script has been added to each run level:
moxa@MOXA:~#ls -l /etc/rc?.d/*tcps*
lrwxrwxrwx 1 root root 15 Jul 6 09:40 /etc/rc2.d/S18tcps2 -> ../init.d/tcps2
lrwxrwxrwx 1 root root 15 Jul 6 09:40 /etc/rc3.d/S18tcps2 -> ../init.d/tcps2
lrwxrwxrwx 1 root root 15 Jul 6 09:40 /etc/rc4.d/S18tcps2 -> ../init.d/tcps2
lrwxrwxrwx 1 root root 15 Jul 6 09:40 /etc/rc5.d/S18tcps2 -> ../init.d/tcps2
To remove a service from inittab, use this command:
moxa@MOXA:~#insserv -r tcps2
Check to make sure the script has been removed.
moxa@MOXA:~#ls -l /etc/rc?.d/*tcps*
ls: cannot access /etc/rc?.d/*tcps*: No such file or directory
Cron for Executing Scheduled Commands
The cron daemon reads /etc/crontab to retrieve scripts and other commands to be run at regularly
scheduled times.
Cron wakes up every minute and checks each command listed in the crontab file to see if it should be run at
that time. Whenever cron executes a command, a report is automatically mailed to the owner of the crontab
(or to the user named in the MAILTO environment variable in the crontab, if such a user exists).
Modify the file
/etc/crontab to schedule an application. Crontab entries follow the format below:
mm h dom mon dow user command
minute hour day of month month day of week user Command to be run
0-59 0-23 1-31 1-12 0-6 (0 is Sunday)
For example, to synchronize the RTC at 8 AM every day, use the following cron entry:
#minute hour dom date month dow user command
00 8 * * * * root hwclock -w
Every column in a crontab entry must be marked with a character. The asterisk indicates every possible unit,
so that setting an asterisk in the day-of-week column will configure cron to run the command on every day of
the week. If you wish to run a command every X minutesor every X hours, then use the format
*/X.
So, using the example above, the hwclock command will be run under root ownership at the 0 minute (i.e.
top of the hour) of 8 AM on every day of the month, for every date, during every month, and on every day of
the week. The following example shows another way of using cron to update the system time and RTC.
1. Write a shell script named
fixtime.sh and save it to the /home directory.

Содержание

Похожие устройства