dreport in script file

Brian K. White brian at aljex.com
Thu Sep 30 09:13:25 PDT 2004


Butch Ammon wrote:
> Good morning....
>
> I have a real short, tiny, script file that will only run dreport on
> Mondays. My problem is that I am missing something, and/or not clear
> on Unix script files.
>
> This /usr/bin/shopreq file is full read/write/execute.  I want to put
> this entry into a users .profile, so when they log in each day in the
> morning, if the day happens to be Monday, it will run the dreport
> output.  If any other day, it will do something basic, like, display
> "Today is:".
>
> This script runs dreport no matter what day it is!!!  What am I doing
> wrong?
>
> -------------------- cut 'n paste --------------------
> #
> day=`date +%a`
> if [ "$day" -eq Mon ]
> then
> /u/appl/fp/dreport purchase -f shopreq -s shopreq -v shopreq.v -u -pt
> else
> echo "Today is:" $day
> fi
> -------------------------------------------------------
>
> How can you get the above script to only run on Monday?  Aaaaaaargh!!

quote "Mon" and use = instead of -eq

or my version would probably use case instead of if/test/then
and shopreq would stay a stand-alone script, probably a menu script that I 
call directly so as to keep the fp development together. ie: there would be 
a menu that other users could run that does the same thing, and developers 
could find and edit the same as any other menu choice, and in here I run 
that menu choice. if the /usr/bin/shopreq is a useful convenience, then I'd 
symlink that name to the menu script or have shopreq be a one-line script 
that runs the menu script.

I'm guessing you really don't care about the date display so it's not here.
(I didn't quote Mon because in this case, pun intended, it isn't required)

So:
make shopreq a fp menu F5script
/u/appl/fp/menus/shopreq.-1:
---
dreport purchase -f shopreq -s shopreq -v shopreq.v -u -pt
---

make /usr/bin/shopreq a symlink to the menu script:
mv /usr/bin/shopreq /usr/bin/shopreq.20040929
ln -s /u/appl/fp/menus/shopreq.-1 /usr/bin/shopreq

case or test statement in .profile to run it, assumes path is set up already 
in /etc/profile:
case version:
---
case `date +%a` in
        Mon) shopreq ;;
esac
---

test version (I hate using the actual words and multiple lines when it can 
be this concise):
---
[ "`date _%a`" = "Mon"] && shopreq
---

but finally, I would *not* do this in .profile!!!
Don't even bother saying "this user always logs in only once a day"
Just forget it and do it right.  :)

If it needs to be run _as this user_ then you can put shopreq in that users 
crontab
If it just needs to be run once every monday and doesn't matter what user, 
put it in root's crontab.

in order for most fp tasks to work in cron you usually just need to set TERM 
and PATH in the environment before hitting the *report command. PFMBTO and 
PFSKIPLOCKED are also good ideas in reports that run from cron.

in linux or freebsd or sco>=5.0.7 or sco<5.0.7 with oss642a installed, you 
can actually edit a config file and have the necessary environment 
permanently part of all cron jobs so you don't have to remember to doctor up 
each thing you want to put in cron.

so, setting aside the question of configuring your cron and assuming the 
script needs to to be self-contained in order to run in cron:

/usr/bin/shopreq:
---
#!/bin/ksh
export TERM=ansi
export PATH=$PATH:/u/appl/fp:/usr/local/bin
export PFMBTO=1
# export PFSKIPLOCKED=1     # optional
/u/appl/fp/menus/shopreq.-1
---

install in cron:
# crontab -l >crontab
# echo '0 8 * * * 1 /usr/bin/shopreq >/dev/null 2>&1' >> crontab
# crontab crontab

if you want the report to show as being run by the user instead of root, 
just log in as that user before doing the same commands

Brian K. White  --  brian at aljex.com  --  http://www.aljex.com/bkw/
+++++[>+++[>+++++>+++++++<<-]<-]>>+.>.+++++.+++++++.-.[>+<---]>++.
filePro BBx  Linux SCO  Prosper/FACTS AutoCAD  #callahans Satriani




More information about the Filepro-list mailing list