LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 07-30-2003, 11:44 PM   #1
greenhornet
Member
 
Registered: Mar 2002
Location: Sydney, Australia
Distribution: RHEL, Fedora, Yellow Dog
Posts: 43

Rep: Reputation: 15
Question Limiting access to binary to x number of users?


Hi There,

I have a statistical analysis app and the network license dictates that no more than x number of users can use this concurrently.

In Linux how would I limit the number of times that a certain app (process) can be launched by different users (I assume that one person can have multiple copies of it open at once and that wont violate the license).

Basically I'm going to distribute an app through my workplace by having people tunnel X sessions through ssh (from multiple OS's) to my main Linux server where the app will be run.

I've tried Googling for answers but nothing seems to spring up.

thanks,
 
Old 07-31-2003, 04:02 AM   #2
storm3x
LQ Newbie
 
Registered: Jul 2003
Location: Ontario, Canada
Distribution: SuSE 8.1
Posts: 8

Rep: Reputation: 1
Well I have a partial solution. I wrote a little script that will check running processes for your program's name and count the number of unique users using your program:

#!/bin/bash

ps -aux |
awk '$11 ~ /your_program_name_here/{instances[$1]++}
END {for (username in instances) print username }' |
awk 'END {print FNR}'


***now see if unique user count has been exceeded
***if so, issue message regarding "too many users..."
***else start up the real program for them

This feeds the process list through two iterations of 'awk'. The first iteration groups instances of the program by user name. The second iteration simply counts the number of unique user names resulting from the last step.

I'm guessing that you'll want to intercept calls to your program and instead have the system run this script. Can that be done through an alias in 'bashrc' perhaps?

Hope this helps.
 
Old 07-31-2003, 10:48 AM   #3
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
Another idea is this:

Create a "lock" subdirectory within /var

Create a script to launch the application. When the application is launched, touch a file inside the lock directory. I'd do something like the date, the user, the instance number of the application, and perhaps the application name (for good measure). Something like:
touch username_app_instance_date

When the application ends, have the script delete the appropriate lock file.

Before the application runs, you can ls the directory, do some grep'ing and cut'ing on the filenames, and count how many users have the application open. Then you can allow the application to run, or error out with a "too many users" message.

Adding the date gives you a safeguard against lost processes (abnormal exit or whatever). If you see a lock that's older than, say, a week, then you can probably get rid of it.

To be even more careful, you could write the process ID of the application to the lock file. That way, you can have a cron job check the lock directory's files versus actual running processes. If they don't match up, then you can delete the lock file safely; automated cleanup.

I haven't given much thought to the code, and will repost later if i get some time.

Last edited by Dark_Helmet; 07-31-2003 at 10:50 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Limiting number of responses in MagpieRSS oneandoneis2 Linux - Software 1 06-01-2005 10:25 AM
Apache: limiting the number of processes that start up tarballed Linux - Networking 2 09-02-2003 03:33 PM
limiting users who can gain ftp or ssh access bluefmc427 Linux - Security 1 07-03-2003 04:17 AM
number of process or users that can access the same file infusino Linux - Newbie 6 11-28-2002 10:50 AM
limiting users access iquadri1 Linux - Networking 1 09-04-2001 01:23 PM


All times are GMT -5. The time now is 08:46 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration