LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop
User Name
Password
Linux - Desktop This forum is for the discussion of all Linux Software used in a desktop context.

Notices

Reply
 
Search this Thread
Old 03-26-2013, 06:12 AM   #1
w00dy101
LQ Newbie
 
Registered: Mar 2013
Location: South Africa
Distribution: Debian
Posts: 12

Rep: Reputation: Disabled
Cool Limit the number of times an application can be opened?


Hi Guys

I'm new here and fairly new to Linux as well

anyways... skipping to the point now...

I need to be able to limit a desktop users ability to open Chrome on the desktop!

We run a web application off of chrome, and what our users seem to be doing is opening the chrome application multiple times each time a new user mans the workstation.

This is creating issues for the software and I need to figure out a way to to prevent this from happening...

Any ideas? does something exists built in to limit the number of times programs can be run?

Would some sort of bash script solve the problem?

I would be keen to see what you guys think!

Thanks in advance

Last edited by w00dy101; 03-26-2013 at 09:54 AM.
 
Old 03-26-2013, 06:43 AM   #2
goumba
Member
 
Registered: Dec 2009
Location: New Jersey, USA
Distribution: Debian Wheezy (7.0), Jessie (future 8) and Sid (unstable)
Posts: 572
Blog Entries: 3

Rep: Reputation: 78
A rather simplistic script to ensure a program is not started if it is already running:

Code:
#!/bin/sh

PROCESSNAME="changeme"

if [ ! -z "$PROCESSNAME" ] && [ ! -z "`ps -e | grep $PROCESSNAME`" ]
then
        # Replace the echo statement below with the desired command(s)
        echo $1 is not running
fi
Beware this an be a little tricky. You must know the process name as it shows in the process list, not search for the binary name. For example: under Debian, Firefox is known as Iceweasel, but ps -e lists the process as "firefox-bin". Firefox's process name under Mint is simply "firefox"

Also note that if you only use parts of the process name, it will evaluate as true. Of course this can be taken care of with a little awkery.

Also in my original test script, I used a parameter passed to the script rather than $PROCESSNAME, which would make this more generic, and possibly more useful. Simply delete the line "PROCESSNAME=" and change $PROCESSNAME to $1 in the conditionals.

Last edited by goumba; 03-26-2013 at 07:26 AM. Reason: Added clarification at bottom
 
1 members found this post helpful.
Old 03-26-2013, 07:51 AM   #3
Habitual
Senior Member
 
Registered: Jan 2011
Distribution: Undecided
Posts: 3,618
Blog Entries: 1

Rep: Reputation: Disabled
Code:
if $(pgrep chro > 0) ; then pkill -9 chro ; else echo "False" ; fi
works here.

Have fun!
 
2 members found this post helpful.
Old 03-26-2013, 09:30 AM   #4
w00dy101
LQ Newbie
 
Registered: Mar 2013
Location: South Africa
Distribution: Debian
Posts: 12

Original Poster
Rep: Reputation: Disabled
Thank you both!

I will explore these options and adapt them to my needs.
 
Old 03-26-2013, 05:39 PM   #5
Habitual
Senior Member
 
Registered: Jan 2011
Distribution: Undecided
Posts: 3,618
Blog Entries: 1

Rep: Reputation: Disabled
No worries, I enjoyed the challenge.
 
Old 03-27-2013, 08:56 AM   #6
w00dy101
LQ Newbie
 
Registered: Mar 2013
Location: South Africa
Distribution: Debian
Posts: 12

Original Poster
Rep: Reputation: Disabled
Talking

Thanks again

The script below solved the problem.

Code:
#!/bin/bash

PROCESSNAME="chrome"
PROCID=`pgrep $PROCESSNAME`

	if [ ! -z "$PROCESSNAME" ] && [ ! -z "`ps -e | grep $PROCESSNAME`" ]
		then
		zenity  --warning --text="Chrome is already running (PID: $PROCID)"
			if [ "$?" -eq "0" ]
				then
				zenity --question --text="Do you want to start a new session? This will close all existing Chrome Sessions"
					if [ "$?" -eq "0" ]
						then
						kill -9 $PROCID &&
						google-chrome --Kiosk
					fi
			fi
	else
	google-chrome --Kiosk
        fi
Created a custom menu launcher, used the Chrome Icon for it, now the users cant open tens of thousands of Chrome apps!
 
Old 03-27-2013, 07:51 PM   #7
Habitual
Senior Member
 
Registered: Jan 2011
Distribution: Undecided
Posts: 3,618
Blog Entries: 1

Rep: Reputation: Disabled
Good Job. I love zenity/yad stuff.
 
  


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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to know the number of files opened by a specific user. RaviTezu Linux - Newbie 5 12-03-2012 08:43 AM
Ping for a specific number of times grob115 Programming 4 08-15-2009 10:52 PM
File Opened by some application gaurav84 Linux - General 3 04-18-2008 02:29 AM
how to check number of opened handles ruj.sabya Linux - General 2 08-06-2007 09:37 AM
Find out the number of files currently opened closet geek Linux - Kernel 4 12-22-2006 02:45 PM


All times are GMT -5. The time now is 04:21 AM.

Main Menu
Advertisement
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