Stop end user loading prog more than 2 times

June 1, 2011 at 09:26:26
Specs: Unix
We need to stop the Mac user from loading an application after the second time and echo they have exceeded maximum number of loads. Not sure how to count this and stop/quit the program execution.

See More: Stop end user loading prog more than 2 times

Report •

#1
June 1, 2011 at 12:08:08
If the user is calling an executable binary from the command line, there is not much you can do to prevent them from executing the program a second time.

If they are calling a shell script which executes a binary, maybe there is something you can do. Suppose user nails executes a program called application; the output of the process status command, ps -ef for this process might look like this:

nails 24751 24728 0 Jun 01 pts/3 0:02 application

With this information, we might modify the shell script calling application, so that if the application already exists in the prcess table, we don't execute the application again:

#!/bin/ksh

# UNTESTED!
uid=$(id|cut -d \( -f 2|cut -d \) -f 1) # get the user id

counter=0
ps -ef| grep -v grep|grep application|while read line
do
   set -- `echo $line`
   if [ $1 == $uid ]
   then
      ((counter+=1))
   fi
   if [ $counter -gt 0 ]
   then
      echo "you have exceeded the number of application loads"
      exit  # quit
   fi   
done
# end script

I choose to use a loop and check for the existence of user (first field) is because other users might be calling application. Unfortunately, the ps command is one of the least portable of *nix commands, so you might need to tweak it for your environment.

Let me know if you have any questions.


Report •
Related Solutions


Ask Question