[CentOS] Unable to execute a script , Permission denied

Dale Dellutri daledellutri at gmail.com
Wed May 26 14:24:55 UTC 2010


On Tue, May 25, 2010 at 8:27 AM, Jatin Davey <jashokda at cisco.com> wrote:

> On 5/25/2010 6:44 PM, Bowie Bailey wrote:
> > Jatin Davey wrote:
> >
> >> Here is the script that i am trying to execute as a non-root user:
> >>
> >> #!/bin/sh
> >> ps -C java -o thcount>  /home/proc_threads/tempfile
> >> awk ' { total += $1 } END { print total } ' /home/proc_threads/tempfile
> >>
> >> here is the output when i try to execute as a non-root user:
> >>
> >> ./javathreads: line 2: /home/proc_threads/tempfile: Permission denied
> >> awk: cmd. line:1: fatal: cannot open file
> >> `/home/proc_threads/tempfile' for reading (Permission denied)
> >>
> > The script is running, but the 'awk' line is failing to read
> > /home/proc_threads/tempfile.  What are the permissions on that file and
> > directory?
> >
> >
> >      $ ls -ld /home/proc_threads
> >
> >      $ ls -l /home/proc_threads/tempfile
> >
> >
>
> Thanks all
>
> I finally figured out that the tempfile that i was creating did not have
> proper permissions for the script to write into. Now i have fixed it
> using the chmod command and it is working fine.
>

If more than one other user executes this script at the same time,
tempfile may be overwritten by the second before the first can run
the awk line.  Change this to use a pipe.
-- 
Dale Dellutri
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.centos.org/pipermail/centos/attachments/20100526/8cf82e52/attachment.html>


More information about the CentOS mailing list