Linux shell script question

Brian K. White brian at aljex.com
Mon Jan 17 11:33:02 PST 2005


----- Original Message ----- 
From: "Richard D. Williams" <richard at appgrp.net>
To: "filePro Mailing List" <filepro-list at lists.celestial.com>
Sent: Monday, January 17, 2005 1:12 PM
Subject: OT: Linux shell script question


>I have a client who wants to control which menu a user has access to upon 
>login.
> I have created a filepro file that contains the user name and menu.
> When he updates any of these records I call a script to write out a text 
> file of all user names and their menu name to a text file in a universally 
> accessible directory.
>
> What I want to do is place a script in each users .bashrc to look into 
> this file for that user's name and get the menu name one the sam line.
> i.e.
>
> johnw   main1
> richardw   main2
> suer      main1
>
> This seems very simple but I do not use awk or sed very much and I do not 
> know the syntax to accomplish this task.
>
> Any suggestions?

change the export so that the seperator between fields is : with no spaces

johnw:main1
richardw:main2
suer:main1

make a script "plogin"

at the end of everyones .profile put "exec plogin"

---plogin---
ID=`id -un`
M=`grep "^${ID}:" /u/appl/userdefs.txt |cut -d: -f2`
exec p $M
------------

why the : ?
with the spaces you'd have to use awk to grab the 2nd field instead of cut. 
cut is a smaller lighter faster program.

OTOH It could be done almost as well with one awk command instead of a grep 
|something
but this way allows for easy adding of more fields to the file, consider:

johnw:main1:acctlaser2:444-555-1212:jw at company.com:
richardw:main2:fct_rich:444-555-1110:rw at compny.com:
suer:main1:sue:444-555-1000:sales at company.com:

---plogin---
ID=`id -un`
DEFS=`grep "^${ID}:" /u/appl/userefs.txt`

menu=`echo "$DEFS" |cut -d: -f2`
PFPRINTER=`echo "$DEFS" |cut -d: -f3`
MYPHONE=`echo "$DEFS" |cut -d: -f4`
MYEMAIL=`echo "$DEFS" |cut -d: -f5`

export PFPRINTER MYPHONE MYMAIL

exec p $menu
------------

Those seperate echo|cut commands are not the most efficient, but they make 
lines that are easy to understand at a glance someone later can add/remove 
lines probably not mess it up, and the use of cut vs something bigger makes 
a bigger difference now that it's being called 4 or more times so that 
"cuts" down on the inefficiency some. It's really nothing anyways. We've 
been using a script that started out like this but now has 10 or 12 fields 
and many other features and we have a lot of users always logging in and out 
and it's nothing, so the above is _really_ nothing.

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