How to Add Items to CronTab

advertisement

Application Note

How to Add Items to CronTab

© 2010 Cisco Systems, Inc. All rights reserved.

The crontab can be used to execute tasks (scripts) based on a reoccurring schedule; by default the crontab is used to restart the webserver (for example).

 Editing crontab entries requires advanced skillsets. You should be comfortable with command lines, vi editor, and telnet/SSH.

.

Contents

Before You Begin 2

View Content of the Crontab 2

Edit Crontab 2

Save Changes So After Restart, Changes Are Still There 2

How to Run Your Own Application at Startup/Autorun Script 3

For More Information 4

Page 1 of 4

How to Add Items to crontab

Before You Begin

This application note describes advanced features for Linux administrators.

All command line changes are only for advanced users. Beware that improper configuration using the command line may disable your Smart Storage device and could possibly result in lost data.

Command line configuration is an unsupported feature intended for advanced administrators only.

Cisco Small Business Support Center will not be able to help debug command line configuration issues.

For assistance, utilize the resources listed in the For More Information section.

View Content of the Crontab

Login to your NAS using telnet.

Type crontab –l

You will see a small list of crontab entries.

Edit Crontab

Type crontab

–e

The crontab will be shown inside a vi session. Edit the crontab as you wish.

Once you have edited the crontab, execute the following command to activate it. o /etc/init.d/crond.sh restart

Save Changes So After Restart, Changes Are Still There

If you restart your NAS without following the steps below, you will find that all your custom entries will not exist on the crontab.

To prevent loss of your work, use autorun.sh or autorunmaster and a custom script for changing the crontab.

© 2010 Cisco Systems, Inc. All rights reserved. Page 2 of 4

How to Add Items to crontab

Autorun Script

© 2010 Cisco Systems, Inc. All rights reserved.

How to Run Your Own Application at Startup/Autorun Script

Method 1

1. Login to your NAS using SSH or telnet.

2. Mount the config ramblock /dev/mtdblock4:

# mount

–t ext2 /dev/sdx6 /tmp/config

3. Create/Edit /tmp/config/autorun.sh:

# vi /tmp/config/autorun.sh

4. Ensure /tmp/config/autorun.sh is executable:

# chmod +x /tmp/config/autorun.sh

5. IMPORTANT: Unmount the mounted flash partition:

# unmount /tmp/config

Method 2 o If you edit this file regularly you can save time by creating a shell script (e.g. editautorun.sh) to automate the process. You can call the script by either putting it in the environment path, or add its folder to the path or call it by an alias. o The script contents are:

Edit Autorun Script

Page 3 of 4

How to Add Items to crontab

IMPORTANT Notes o Never put any larger files on your flashboot device and ramdisk. Instead create a symbolic link to whatever you want to put there.

 Create a link from /usr (which is in the ramdisk) to

/share/MD0_DATA/jre1.6.0_10 (which is on a hard disk) at the mountpoint /usr/java

 # ln

–sf /share/MD0_DATA/jre1.6.0_10 /usr/java o Always use the full system path because locations like /opt/bin or /opt/sbin might not have been exported yet when the autorun.sh is executed. o Always mounting and editing the autorun.sh on the flash could be an annoying task. More important, it may reduce the lifetime of some flash blocks. Flash blocks have limited write/erase cycles, and mtdblock device driver does little to prevent their wear. To avoid this, you could configure autorun.sh to launch another script located in the inner drive: in this way there no need to always mount and modify the file inside the flash. But only edit the script file located on your drive.

Create the directory /share/HDA_DATA/ .pkg/autorun

The autorun.sh located on the flash could be something like

/share/HDA_DATA/ .pkg/autorun/autorun.sh

 Edit the file /share/HDA_DATA/.pkg/autorun/autorun.sh to be used to launch all your start scripts.

.

© 2010 Cisco Systems, Inc. All rights reserved.

For More Information

For more information about Cisco Smart Storage Applications, visit the Cisco Small Business

Community forum https://www.myciscocommunity.com/community/smallbizsupport/networkstorage

Wikipedia: http://en.wikipedia.org/wiki/Cron

Memory Technology Device (MTD) http://www.linuxmtd.infradead.org/faq/general.html#L_ext2_mtd

OL-22896-01

Page 4 of 4

Download