LinuxQuestions.org
Help answer threads with 0 replies.
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 04-22-2010, 11:49 PM   #1
changusee2k
LQ Newbie
 
Registered: Apr 2010
Location: Hyderabad
Distribution: Suse Linux
Posts: 1

Rep: Reputation: 0
Unhappy Executing a Shell script with 654 permissions inside another shell script.


Hi All,

I have this scenario, where in I'm calling a shell script inside another shell script. The only criteria here is that the embedded script will have 654 permissions and the master script should be able to execute this embedded script. Please advise as to how this can be done? The sample code is given below:

#!/usr/bin/ksh

maindir=/usr/home01/temp/dir
bindir=${maindir}/batch/bin

${bindir}/test.ksh -d ${dblogin} -i ${datadir} -r ${filedt} > ${tmp_log}

The test.ksh which has 654 permissions is called by the main.ksh script and when i try to run it using ./main.ksh, it fails with the error "Execute permissions denied."

A quick response as to how this can be resolved will be greatly appreciated.

Thanks in advance,
Chandrasekhar.
 
Old 04-23-2010, 12:20 AM   #2
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Ubuntu, Debian, OS X
Posts: 1,305

Rep: Reputation: 107Reputation: 107
Lightbulb

you can execute any script with giving the name of the shell before it.

For. e.g.
bash vikas.sh
ksh vikas.sh

Now, even if your script has 644 (or 654), it can be run smoothly

Hope this helps.
 
Old 06-07-2011, 07:58 PM   #3
A.Thyssen
Member
 
Registered: May 2006
Location: Brisbane, Australia
Distribution: linux
Posts: 158

Rep: Reputation: 44
The only reason you may not execute the script directly due to permissions is that it does not have execute for the current running UID and GID of the user/process.
With permissions 654 that means only someone in the same group as the script BUT is not the owner of the script can 'execute' it.

A script however also requires you have read access, so the running 'interpreter' regardless of if that is a shell, perl, or other program, can also read the file to execute it.

In older UNIX's a unreadable shell script was possible by using permissions 4711.
That is it is executable by anyone, but Set-UID's to the owner of the script, which provides read permission. However I believe Set-UID scripts are not permitted under Linux.

--

Okay. NONE of this however matters if you run the interpreter yourself! Just as forum user "vikas027" pointed out. That is you run the script using a command like

bash script_filename
awk -f script_filename

In this case the script is being treated a just a plain file that is read by the interpretor command. Only read permission is required in this case, as such the script could have permissions of just 444 (read only to everyone, including owner) for it to work (unless the script modifies itself! Weird, but I have see it done!)

--

There is however one other situation for things like shell script. Source scripts.
that is you don't want the shell to run the script as a sub-process, by launching a new interpretor, but by having the currently running shell interpret it. In some languages this is also known as an 'include'.

A source shell is typically requires if you want that script to modify the current environment (and not a sub-shells environment that then gets deleted). For example to change the current directory (working directory), or set environment variables (like PATH), or local shell variables (like the prompt).

In such a case teh script is typically not made executable, and it is also a good idea to give the script a fake interpretor, that just generates an appropriate error. For example

Code:
#!/bin/echo "Source Script Only -- Do not execute -- ABORTING"
# Setup software package to working environment
PATH="/opt/software/bin:${PATH}"
MANPATH="/opt/software/man:${MANPATH}"
LD_LIBRARY_PATH="/opt/software/lib:${LD_LIBRARY_PATH}"
 
  


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
Problem executing mv command inside shell script pablogosse Linux - General 7 12-16-2009 12:21 PM
Runs Multiple shell script inside a main script using crontab srimal Linux - Newbie 4 10-22-2009 06:19 PM
Shell script inside shell script treotan Linux - General 4 02-19-2009 06:34 AM
Executing a shell script command!! vishamr2000 Programming 4 08-15-2005 12:33 AM
executing a shell script from C llama_meme Programming 2 04-01-2002 09:10 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:56 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