McIDAS User's Guide
Version 2014.1

[Search Manual] [Table of Contents] [Go to Previous] [Go to Next]


Running mcenv From cron

You can run mcenv from cron, the Unix scheduler. However, you must set the shell environment for mcenv. It is not started automatically when mcenv is run in cron. You can specify the environment as part of the mcenv script, or set it up before starting the script.

Setting the environment before starting the script

To set the shell environment before starting the script, follow the steps below.

1. Create a file that specifies the environment in which your script will run. In the example below, the file containing the PATH and MCPATH environment variables is named $HOME/.cronprofile.

#This file is named .cronprofile

PATH=$HOME/bin:
PATH=$PATH:/usr/sww/bin:/usr/local/bin:$HOME/mcidas/bin
PATH=$PATH:/home/mcidas/bin:/bin:/usr/bin:/etc:/usr/ucb
PATH=$PATH:/usr/bin/X11:/common/tool/bin:.

export PATH

MCPATH=$HOME/mcidas/data
MCPATH=$MCPATH:/home/mcidas/data

export MCPATH

2. Add a crontab entry to cron similar to one of the two examples below. Add the top entry if the script contains mcenv and the second entry if the mcenv is external to the script. Enter the entries below as single lines.

10 * * * * ( . /home/user/.cronprofile && 
   /home/user/mcidas/data/mcenvscript )

 

10 * * * * ( . /home/user/.cronprofile &&
   /home/mcidas/bin/mcenv -f 300x600 /home/user/ 
   mcidas/data/mcenvscript)

Setting the environment in the script

To set the environment in the script, follow the steps below.

1. Add lines to the script that specify the environment. In the sample script below, the lines that set the environment appear in bold.

#!/bin/sh
# Sample script

#set up environment


PATH=$HOME/bin:
PATH=$PATH:/usr/sww/bin:/usr/local/bin:$HOME/mcidas/bin
PATH=$PATH:/home/mcidas/bin:/bin:/usr/bin:/etc:/usr/ucb
PATH=$PATH:/usr/bin/X11:/common/tool/bin:.

export PATH

MCPATH=$HOME/mcidas/data
MCPATH=$MCPATH:/home/mcidas/data

export MCPATH

mcenv -f 520x690 << 'EOF'
logon.k USER 1234
imgcopy.k EAST/VIS MYDATA/VIS
imgdisp.k MYDATA/VIS 1
frmsave.k 1 MYPICT.GIF
exit
EOF
exit 0

2. Add an entry to crontab similar to the example below.

10 * * * * /home/user/mcidas/data/mcenvscript 

3. It may be useful to redirect output from a cron job to a log file. Add lines similar to the example below to crontab to prevent output from being mailed by cron to the owner of the crontab. The entry below directs the standard error and output to a file.

10 * * * * /home/user/mcidas/data/mcenvscript >>/home/user/logs/mclog 2>&1

[Search Manual] [Table of Contents] [Go to Previous] [Go to Next]