LinuxQuestions.org
Visit Jeremy's Blog.
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 09-22-2009, 06:36 AM   #1
mamunbabu2001
LQ Newbie
 
Registered: Sep 2009
Posts: 10

Rep: Reputation: 0
"Permission denied " running any .sh file


Dear All,
I am quite new to linux and shell script. I am trying to run a .jar file using a shell script. But when I try to do this it's saying " permission denied " (Even with the "root login"). Then I have tried creating an almost empty shell script file (.sh) and run it in my home directory. Yet again I am getting the same message.

The file starts with the following line
#!/bin/bash

The file is in my "/home/mamun" directory
From the "/home" directory I tried to run the file with the following command:

./mamun/Workflow.sh

Can anybody please help me with any suggestions, what causing this permission denied.

Thanks in advance,
Mamun
 
Old 09-22-2009, 06:37 AM   #2
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
You need to make it executable:
Code:
chmod +x ./mamun/Workflow.sh
Then you can run it as ./mamun/Workflow.sh.

Otherwise you can run it with bash explicitly:
Code:
bash ./mamun/Workflow.sh
Either of these should work.

Last edited by pwc101; 09-22-2009 at 06:39 AM.
 
Old 09-22-2009, 08:16 AM   #3
ilu_nishant
LQ Newbie
 
Registered: Sep 2009
Posts: 11

Rep: Reputation: 1
Check ^M characters in your script before the execution.

Hii

After giving the executable permission to your script , once open your script in the vi editor to confirm that there is no control - M ( ^M ) characters in your script.

If there ,remove them first and try executing your script again.
It will surely work!!

Cheerzz!!
 
Old 09-23-2009, 06:14 AM   #4
mamunbabu2001
LQ Newbie
 
Registered: Sep 2009
Posts: 10

Original Poster
Rep: Reputation: 0
Thumbs up Thanks it works..

Quote:
Originally Posted by pwc101 View Post
You need to make it executable:
Code:
chmod +x ./mamun/Workflow.sh
Then you can run it as ./mamun/Workflow.sh.

Otherwise you can run it with bash explicitly:
Code:
bash ./mamun/Workflow.sh
Either of these should work.

Hi,
Thanks for a quick reply. It worked . thanks a lot. If it's not much can you please give a short explanation what causes this (I mean even the
root can not execute it).


regards,
Mamun.
 
Old 09-23-2009, 06:15 AM   #5
mamunbabu2001
LQ Newbie
 
Registered: Sep 2009
Posts: 10

Original Poster
Rep: Reputation: 0
Hi,
Thanks for your reply. the chmod command solved it. thanks anyway.



Quote:
Originally Posted by ilu_nishant View Post
Hii

After giving the executable permission to your script , once open your script in the vi editor to confirm that there is no control - M ( ^M ) characters in your script.

If there ,remove them first and try executing your script again.
It will surely work!!

Cheerzz!!
 
Old 09-23-2009, 06:18 AM   #6
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
No one can execute it unless the execute flag is added to the file. You can see what file mode bits have been set on a file using ls@
Code:
ls -l ./mamun/Workflow.sh
-rwxr-xr-x  1 mamun users  524 2009-09-18 16:06 ./mamun/Workflow.sh
I've highlighted in red the section which informs you on the currently set file mode bits. r=read, w=write, x=execute. There are three sets because you can set the file mode bits for the owner, a member of the group (users in this example), or anyone at all.
 
Old 09-23-2009, 08:29 PM   #7
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
chmod man page http://linux.die.net/man/1/chmod
 
Old 09-23-2009, 08:31 PM   #8
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
One more thing worth pointing out:

Even if a script is NON-executable, you can still execute it by putting sh in front of it:

shell# sh ./script

and it will run

Sasha
 
Old 09-24-2009, 01:08 PM   #9
mamunbabu2001
LQ Newbie
 
Registered: Sep 2009
Posts: 10

Original Poster
Rep: Reputation: 0
Thumbs up

Thanks.....


Quote:
Originally Posted by GrapefruiTgirl View Post
One more thing worth pointing out:

Even if a script is NON-executable, you can still execute it by putting sh in front of it:

shell# sh ./script

and it will run

Sasha
 
Old 09-24-2009, 01:09 PM   #10
mamunbabu2001
LQ Newbie
 
Registered: Sep 2009
Posts: 10

Original Poster
Rep: Reputation: 0
Thumbs up

Thanks ........


Quote:
Originally Posted by pwc101 View Post
No one can execute it unless the execute flag is added to the file. You can see what file mode bits have been set on a file using ls@
Code:
ls -l ./mamun/Workflow.sh
-rwxr-xr-x  1 mamun users  524 2009-09-18 16:06 ./mamun/Workflow.sh
I've highlighted in red the section which informs you on the currently set file mode bits. r=read, w=write, x=execute. There are three sets because you can set the file mode bits for the owner, a member of the group (users in this example), or anyone at all.
 
  


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
tshark gives "permission denied" writing to (any) file in home dir. kr0m3 Linux - Networking 5 08-16-2016 12:22 PM
can't execute c++ binaries, "permission denied"... even though permission is 777 SerfurJ Programming 14 02-20-2009 05:50 AM
"Permission denied" and "recursive directory loop" when searching for string in files mack1e Linux - Newbie 5 06-12-2008 08:38 AM
Eclipse SDK v3.0 running problem: "Permission denied" AlexDunnCpp Linux - Newbie 1 08-03-2004 12:45 PM
sendmail: "permission denied" when using include:/file sohmc Linux - Software 1 05-22-2003 07:40 AM


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