Mourning the loss of our friend, WhitPhil.
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
 
Linux and Unix
Tag Cloud
access audio black screen blue screen boot bsod connection crash dell desktop drivers dvd email error excel excel 2003 firefox hard drive hardware hdmi hijackthis internet keyboard laptop malware monitor motherboard network networking outlook problem recovery router safe mode screen slow sound spyware tdlwsp.dll trojan vba video virus vista vundo windows windows 7 windows vista windows xp wireless
Search
Search for:
Tech Support Guy Forums > Operating Systems > Linux and Unix >
Running a script only under a certain user

Tip: Click here to scan for System Errors and Optimize PC performance
[ Sponsored Link ]

Closed Thread
 
Thread Tools
Regicide's Avatar
Senior Member with 307 posts.
 
Join Date: Aug 2003
Experience: Advanced
02-Aug-2004, 02:59 AM #1
Running a script only under a certain user
I'm running Koppix 3.4 (2.4.x kernel) on my laptop. Is there a way to have a script run only under a certain user? I'm trying to have a simple script execute the command: "pump -i ath0" only under a certain user. How would I go about doing this; if possible?
__________________
When you give everything and the feeling is gone
All the giving is fake, did you fake enough?
When there's nothing left, did you take enough?
tsunam's Avatar
Senior Member with 1,246 posts.
 
Join Date: Sep 2003
Experience: Linux~su
02-Aug-2004, 07:12 AM #2
the simpilist would be to change the permissions of the file to 700. That will make it so only the owner will be able to run it, others can't even read the file.

#chmod 700 (file)

edit: at least this should work, not sure about it working with the root account...not being able to run it though. It probably still can since root is just that powerful.
__________________
Gentoo Developer, and 64bit os user

"In feeding Mother Nature, you are fed in return" - Tsunam (2005). Concerning water conservation, and raising water tables.
Regicide's Avatar
Senior Member with 307 posts.
 
Join Date: Aug 2003
Experience: Advanced
02-Aug-2004, 12:07 PM #3
Thanks for the info. Now, two more questions: how would I go about making a script run for every user except for one? Also, where should I put the script to have it run?
Squashman's Avatar
Distinguished Member with 14,983 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: IIAHYAYCESA,YAADA!
02-Aug-2004, 12:15 PM #4
Create a group with the users you want to run the script.
Create a folder and chown the folder with that group name. Put the script in their.

Now I am not sure if you can run the script based on what group they are in. You could try adding some checks in /etc/profile to see what group they are in and then run the script if they are. Otherwise you could just edit each users .bash_profile if that is what shell you are using.
__________________
I hate asking the same question twice!
How to ask questions the smart way!
Microsoft MVP - User Desktop Experience
Regicide's Avatar
Senior Member with 307 posts.
 
Join Date: Aug 2003
Experience: Advanced
02-Aug-2004, 12:23 PM #5
Ok, I'll try that later, thanks a lot!
codejockey's Avatar
Senior Member with 1,410 posts.
 
Join Date: Feb 2002
07-Aug-2004, 07:51 PM #6
You might also consider using the id command in your script to identify the user attempting to run the script, and then either allow or deny execution. For example:
Code:
USERID=`id -ru`
if [ "$USERID" -eq 501 ]                        # allow only user with ID 501 to run script
then
    echo allowed to run script
else
    echo cannot run script
fi

if [ "$USERID" -ne 501 ]                        # allow any user other than 501
then
    echo allowed to run script
else
    echo cannot run script
fi
This has the advantage that you can change it easily (without creating/modifying groups and file permissions) and will also detect attempts to run the script with an effective ID that is different from the real ID.

Hope this helps.
__________________
The slowest component still sits at the keyboard.
Squashman's Avatar
Distinguished Member with 14,983 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: IIAHYAYCESA,YAADA!
09-Aug-2004, 11:00 AM #7
Another lesson learned from CodeJockey! Thanks.
codejockey's Avatar
Senior Member with 1,410 posts.
 
Join Date: Feb 2002
09-Aug-2004, 09:00 PM #8
Lightbulb Aw, shucks ...
Subject line says it all. Glad I could contribute -- and for the record, I've gotten plenty of good advice/info from lots of folks here, including LwdSquashman ()
tsunam's Avatar
Senior Member with 1,246 posts.
 
Join Date: Sep 2003
Experience: Linux~su
09-Aug-2004, 09:06 PM #9
have to admit codejockey has helped me out with coding stuff more then he knows.

I think my next project will be to create a screenshot program that uses a secure ftp/encrypted something.

Since the one I made now has the pass and user just in the script....course someone would have to steal my laptop and know my logins to find it but still...
__________________
Gentoo Developer, and 64bit os user

"In feeding Mother Nature, you are fed in return" - Tsunam (2005). Concerning water conservation, and raising water tables.
Closed Thread Bookmark and Share

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Smart Search

Find your solution!



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.

Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -5. The time now is 10:24 PM.
Copyright © 1996 - 2009 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.
Powered by Cermak Technologies, Inc.