LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-28-2016, 12:24 AM   #1
shazgaurav
LQ Newbie
 
Registered: Apr 2013
Posts: 29

Rep: Reputation: Disabled
Prevent shell script from being run directly using sh command


There is a shell script used to stop/start appserver appserver.sh.I need to run this script using service file only(service appserver start/stop/status) and prevent direct execution of shell script(./appserver start/stop/status).Is there any utility in linux which can help me out.

Thanks in advance...!!!
 
Old 06-28-2016, 01:56 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
If the script file is
Code:
appserver.sh
then
Code:
./appserver
will fail because its the wrong name.

If you ensure that there are no 'x' perms set, then even ./appserver.sh will fail, BUT if its valid bash code, then 'bash ./appserver.sh' will run and you can't stop it even if there are no 'x' perms.

It would help if you explained why you want to do this.
You can certainly make it root owner/grp accessible only, in which case only root can run it (which is what happens with the service cmd..)

HTH
 
Old 06-28-2016, 02:17 AM   #3
shazgaurav
LQ Newbie
 
Registered: Apr 2013
Posts: 29

Original Poster
Rep: Reputation: Disabled
Here is some more context.Sorry my question had few voids.

The script should not be executeable as ./appserver.sh or "sh appserver.sh" directly by user(tomcat) who is owner of the script but it should be executable by service file(service appserver start/stop/status) as owner of that script(tomcat).I am fairly comfortable with how I can execute script using (service appserver start/stop/status) where I can give User=tomcat in RHEL7 service file.What I am looking disable execution of appserver.sh directly using ./appserver.sh or "sh appserver.sh"
 
Old 06-28-2016, 03:46 AM   #4
ondoho
Senior Member
 
Registered: Dec 2013
Posts: 4,176

Rep: Reputation: 835Reputation: 835Reputation: 835Reputation: 835Reputation: 835Reputation: 835Reputation: 835
make it be owned by tomcat, and remove all other permissions?

like: chmod 600 ./appserver.sh; chown tomcat:tomcat ./appserver.sh
 
Old 06-28-2016, 03:56 AM   #5
Jjanel
Member
 
Registered: Jun 2016
Posts: 377

Rep: Reputation: 66
Maybe you could put code IN the script (IF modifying it is a possibility)
to check that the env/parent/arg $0/...(I'm not sure how)
is the service manager [systemd?] and not just a parent shell.

Conceptually, I'm thinking that: IF a userid could see/COPY! a file,
that userid can "perform" whatever the script does!
I think a file/directory can be unreadable by owner (if that might help).

I'm guessing what you want is the script to *immediately exit*
IF the [?]parent="runER"[?] is NOT the [?]system[?] ...

(excuse my blindly trying to help clarify, even tho I don't know specifics)
 
  


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
Bash script - command works directly in command line but not in script raoulcousins Linux - Newbie 6 08-21-2013 08:43 PM
Unable to run another command from within shell script, when run from home directory blackray1 Linux - Newbie 7 07-01-2013 10:42 AM
How to use ssh and run command in the remote machine using shell script salmanmanekia Linux - Newbie 8 04-28-2011 08:41 AM
gnome launcher won't run a sudo command directly or via a script gnreeke Linux - Desktop 1 06-23-2009 11:44 AM
How to run shell script directly without inquiring running mode? Piero Linux - Software 3 09-03-2003 03:28 AM


All times are GMT -5. The time now is 11:07 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration