Moxa Technologies UC-7420/7410 user manual Cron-daemon to Execute Scheduled Commands

Page 51

UC-7420/7410 User’s Manual

Managing Embedded Linux

Save the shell script using any file name. E.g., fixtime

How to run the shell script automatically when the kernel boots up

Copy the example shell script fixtime to directory /etc/init.d, and then use chmod 755 fixtime to change the shell script mode. Next, use vi editor to edit the file /etc/inittab. Add the following line to the bottom of the file:

ntp : 2345 : respawn : /etc/init.d/fixtime

Use the command #init q to re-init the kernel.

Cron—daemon to Execute Scheduled Commands

This function is only available for firmware version V1.5 (and later versions). Start Cron from the directory /etc/rc.d/rc.local. It will return immediately, so you don’t need to start it with ‘&’ to run the background.

The Cron daemon will search /etc/cron.d/crontab for crontab files, which are named after accounts in /etc/passwd.

Cron wakes up every minute, and checks each command to see if it should be run in the current minute. When executing commands, output is 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/cron.d/crontab to set up your scheduled applications. Crontab files have the following format:

mm

h

dom

mon

dow

user

command

month

hour

date

month

week

user

command

0-59

0-23

1-31

1-12

0-6 (0 is Sunday)

 

 

The following example demonstrates how to use Cron.

How to use cron to update the system time and RTC time every day at 8:00.

STEP1: Write a shell script named fixtime.sh and save it to /home/.

#!/bin/sh

ntpdate time.nist.gov hwclock –systohc exit 0

STEP2: Change mode of fixtime.sh

#chmod 755 fixtime.sh

STEP3: Modify /etc/cron.d/crontab file to run fixtime.sh at 8:00 every day.

Add the following line to the end of crontab:

* 8 * * *root /home/fixtime.sh

STEP4: Enable the cron daemon manually.

#/etc/init.d/cron start

STEP5: Enable cron when the system boots up.

Add the following line in the file /etc/init.d/rc.local

#/etc/init.d/cron start

3-11

Image 51
Contents Third Edition, June UC-7420/7410 User’s ManualCopyright Notice TrademarksDisclaimer Table of Contents Chapter UC Finder Appendix B Windows Tool Chain Introduction ‰ Hardware Introduction IntroductionUC-7410-LX Package ChecklistProduct Features OverviewProduct Hardware Specifications Appearance and Dimensions Hardware IntroductionAppearance Dimensions Hardware Block Diagram LED IndicatorsLED Name Color Meaning Real Time Clock Reset-type ButtonsReset Button Reset to default ButtonWall or Cabinet Placement OptionsWiring Requirements Hardware Connection DescriptionDIN-Rail Mounting Grounding UC-7420/7410 Connecting the PowerConnecting to the Network Pin SignalPin RS-232 RS-422 RS-485 Connecting to a Serial DeviceConnecting to the Console Port CompactFlashSoftware Architecture Software IntroductionSoftware Package Journaling Flash File System JFFS2Software Version Comparison Table Directory Change Protocol stacks and utilitiesGetting Started ‰ Configuring the Ethernet InterfacePowering on UC-7420/7410 Connecting UC-7420/7410 to a PCSerial Console 192.168.4.127 255.255.255.0 Default IP Address NetmaskTelnet Console 192.168.3.127 255.255.255.0Windows Users SSH ConsoleStatic IP addresses Configuring the Ethernet InterfaceModifying Network Settings with the Serial Console Linux UsersDynamic IP addresses IEEE802.11b Configuring the Wlan via the Pcmcia InterfaceModifying Network Settings over the Network Default IP address is 192.168.5.127, netmask#vi /etc/wlan/wlancfg-any IEEE802.11g Setting Setting ExplanationKey1Str, Key2Str, Key3Str, Key4Str-Sets strings Key1 to Key4 TurboRate-Enables or disables TurboRate Step Installing the Tool Chain LinuxTest Program-Developing Hello.c Checking the Flash Memory SpaceYou should receive the following response Compiling Hello.cTesting Environment Developing Your First ApplicationUploading Hello to UC-7420/7410 and Running the Program #mount -t iso9660 /dev/cdrom /mnt/cdrom Compiling tcps2.cPuTTY Uploading tcps2-release and Running the Program#jobs // use this command to check if the program is running UC-7420/7410 User’s Manual Testing Procedure SummaryUC-7420/7410 User’s Manual Managing Embedded Linux ‰ System Version Information ‰ System Image BackupUpgrading the firmware will erase all data on the Flash ROM System Image BackupSystem Version Information Upgrading the Firmware#upramdisk #cd /mnt/ramdisk Loading Factory Defaults Backing Up the User File System Firmware versions earlier than V1.5 not includingFirmware version V1.5 and later versions Enabling and Disabling Daemons UC-7420/7410 User’s Manual Managing Embedded Linux Setting the Run-Level Setting the Time Manually Adjusting the System TimeExample shell script to update the system time periodically NTP ClientUpdating the Time Automatically Enable cron when the system boots up Cron-daemon to Execute Scheduled CommandsChange mode of fixtime.sh Enable the cron daemon manuallyConnecting Peripherals USB Mass StorageCF Mass Storage ‰ Iptables ‰ NAT Managing CommunicationsDisabling the Telnet/ftp server Web Service-ApacheTelnet / FTP Enabling the Telnet/ftp serverUsr/www/cgi-bin Saving a Web Page to the CF Card Use the following commands to restart the Apache web server Iptables Local Host Packets Examples Observe and erase chain rulesDefine policy for chain rules UsageIptmac Append or delete rulesNAT Example Enabling NAT at BootupDial-up Service-PPP Example 2 Connecting to a PPP server over a hard-wired link UP Loopback Running How to check the connection#vi /etc/exports Setting up UC-7420/7410 as an NFS ServerSetting up a Machine for Incoming PPP Connections NFS Network File SystemSetting up UC-7420/7410 as an NFS Client Steps 2 MailOpen VPN Internet IFS=‘ Create link symbols to enable this script at boot time Destination Gateway Genmsk Flags Metric Use Iface Now ping Host B from Host a by typing Setup 3 Routed IP Destination Gateway Genmsk Flags Metric Use Iface Programmer’s Guide Address Size Contents Flash Memory MapLinux Tool Chain Introduction Tools Available in the Host Environment Debugging with GDBObtaining help Cross Compiling Applications and LibrariesDevice API RTC Real Time ClockBuzzer WDT Watch Dog Timer Input Int fd File handle from swtdopen return value Output User application example Example Special NoteSwtddisableswtdfd Int mainint argc, char *argv Pidt sonpid Example to get the baud rate Example to set the baud rateExamples KeyPadBaud rate inaccuracy Special NoteMake File Example UC Finder Windows UC Finder Installing the SoftwareUC-7420/7410 User’s Manual UC Finder Broadcast Search Linux ucfinder Editor System CommandsBusybox V0.60.4 Linux normal command utility collection File managerProcess OtherMoxa special utilities Windows Tool Chain Introduction Introduction Select the Root Directory Installation ProcedureUC-7420/7410 User’s Manual Windows Tool Chain Introduction UC-7420/7410 User’s Manual Windows Tool Chain Introduction Using the Bash Shell UC-7420/7410 User’s Manual Windows Tool Chain Introduction GDB debug tool-InsightUC-7420/7410 User’s Manual Windows Tool Chain Introduction Service Information Following services are provided Moxa Internet ServicesMoxa Product † UC-7410-LX † UC-7420-LX Serial Number Problem Report FormProduct Return Procedure