LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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, 05: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 08:54 AM.
 
Old 03-26-2013, 05:43 AM   #2
goumba
Senior Member
 
Registered: Dec 2009
Location: New Jersey, USA
Distribution: Fedora, OpenSUSE, FreeBSD, OpenBSD, macOS (hack). Past: Debian, Arch, RedHat (pre-RHEL).
Posts: 1,335
Blog Entries: 7

Rep: Reputation: 402Reputation: 402Reputation: 402Reputation: 402Reputation: 402
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 06:26 AM. Reason: Added clarification at bottom
 
1 members found this post helpful.
Old 03-26-2013, 06:51 AM   #3
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

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, 08: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, 04:39 PM   #5
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
No worries, I enjoyed the challenge.
 
Old 03-27-2013, 07: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, 06:51 PM   #7
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

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


Reply



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
Find out the number of files currently opened closet geek Linux - Kernel 5 05-19-2015 08:19 AM
How to know the number of files opened by a specific user. RaviTezu Linux - Newbie 5 12-03-2012 07:43 AM
Ping for a specific number of times grob115 Programming 4 08-15-2009 09:52 PM
File Opened by some application gaurav84 Linux - General 3 04-18-2008 01:29 AM
how to check number of opened handles ruj.sabya Linux - General 2 08-06-2007 08:37 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop

All times are GMT -5. The time now is 01:16 PM.

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
Open Source Consulting | Domain Registration