Operating System - HP-UX
1834156 Members
2848 Online
110064 Solutions
New Discussion

Re: Unix Script to limit # of Baan users

 
Bob Ferro
Regular Advisor

Unix Script to limit # of Baan users

The script is attached and the following is the results of the "ps -ef | grep rroth":

rroth 25266 623 0 14:29:50 ? 0:00 /bin/ksh /baan/bse/bin/script6.2 -1 545 0 1
rroth 25275 25266 0 14:29:51 ? 0:06 /baan/bse/bin/bshell -1 545 0 1
rroth 25276 25275 0 14:29:53 ? 0:00 oracle8 (rroth:25275/PIPE) 25275 321 10 11
rroth 25278 1 0 14:29:53 ? 0:00 oraclebaanIV (DESCRIPTION=(LOCAL=YES)(SDU=8192)(TDU=8192)(AD
2 REPLIES 2
Todd McDaniel_1
Honored Contributor

Re: Unix Script to limit # of Baan users

Are you trying to limit a certain user or limit oracle?

Need a bit more from you.... why are you doing it and what is your goal.
Unix, the other white meat.
Bill Hassell
Honored Contributor

Re: Unix Script to limit # of Baan users

Using grep and ps ALWAYS leads to trouble. Since all you are looking for is the current user (I assume that $USER is the user's login), let ps do all the work:

ps -f -u$USER

This shows every process that $USER is running. Note that there will be a header to ignore.

Your script will fail in many ways. If USER=bill then it will capture user billy, hillbilly and even processes named billing...grep matches anything on the ps line. ps -u$USER matches EXACTLY the user name.

The same warning applies to the second ps grepping for bshell. It will find bombshell and other variants, whether login names, argument to scripts or user processes. Again, ps can search for an EXACT match, in this case, the program name. But you need to turn on XPG4 behavior with the UNIX95 variable. Try this:

UNIX95= ps -C bshell -o pid,args

This construct introduces two special options, -C for an exact process_name match, and -o for do-it-yourself items. The man page for ps tells all about the new options. Now your messaging command simplifies to this:

UNIX95= ps -C bshell -o pid,args | while read MYPID,ARGS
do
if [ $MYPID != "PID" ]
then
bshcmd6.1 -w1 -u1 -M "Warning: you are only allowed to login ${ALLOWED_LOGINS} time(s)! Please close this window" ${MYPID}
fi
done

Note that ps always puts out a header so you have to skip $MYPID when it is "PID".


Bill Hassell, sysadmin