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 05-24-2011, 07:15 AM   #1
brownie_cookie
Member
 
Registered: Mar 2011
Location: Belgium
Distribution: CentOS release 5.5 (Final), Red Hat Enterprise Linux ES release 4 (Nahant Update 8)
Posts: 416
Blog Entries: 2

Rep: Reputation: 12
can't write to a file...


Hi all

I'm writing a script/plugin for Nagios for testing a WebLogic server..
I redirect some output to a file, and then i read that file to get some data, but i can't seem to write to that file with my script :s...

this is the most important code
Code:
$JAVA_HOME/java -classpath $CLASSPATH weblogic.Admin -url t3://$host:$port -username $user -password $pass GET -pretty -type $service > /usr/lib/nagios/plugins/lib/output.txt
the variables are filled in on the right way, so that's not the problem...
everytime i execute my plugin he needs to rewrite that file ('>'), but that doesn't seem to work...
to file is accessible and everything...

does anyone have a suggestion?

* EDIT *
When i execute this script through a local terminal (PuTTy), it works
but when i execute it from Nagios, it doesn't work..

Last edited by brownie_cookie; 05-24-2011 at 07:19 AM.
 
Old 05-24-2011, 07:32 AM   #2
brownie_cookie
Member
 
Registered: Mar 2011
Location: Belgium
Distribution: CentOS release 5.5 (Final), Red Hat Enterprise Linux ES release 4 (Nahant Update 8)
Posts: 416
Blog Entries: 2

Original Poster
Rep: Reputation: 12
solved it

appearently, when Nagios executes a script, he becomes a user, named apache (don't ask me why)
and because of that, he doesn't have enough rights to read a file...
so i changed the permissions of that file
Code:
# chmod 777 output.txt
slightly overkill, but now i'm sure..
it's only a output file, no info of interests for other people so it doesn't matter

thanks anyways guys
 
Old 05-24-2011, 08:46 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,252

Rep: Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685
Why not add apache to the group of the file so you at least stop world from writing. Also, is setting it to execute such a good idea?
 
Old 05-24-2011, 09:22 AM   #4
brownie_cookie
Member
 
Registered: Mar 2011
Location: Belgium
Distribution: CentOS release 5.5 (Final), Red Hat Enterprise Linux ES release 4 (Nahant Update 8)
Posts: 416
Blog Entries: 2

Original Poster
Rep: Reputation: 12
yes, but i find it strange that he executes it as apache...
because i use some sort of software (NRPE) and i had to made a user 'Nagios', so i thought he need that user to execute plugins..

can you perhaps explain how i can add apache to that group?
i know that those permissions are not necessary, but it is only a file where nothing important gets stored in

what is your suggestion for this?
 
Old 05-24-2011, 10:26 AM   #5
hurryi
Member
 
Registered: Apr 2010
Distribution: RHEL
Posts: 77

Rep: Reputation: 7
hello,

i am not really familiar with nagios but found this, it might help
http://www.supportsages.com/blog/200...gios-and-nrpe/

"Create a new nagcmd group for allowing external commands to be submitted through the web interface. Add both the nagios user and the apache user to the group."
Code:
    /usr/sbin/groupadd nagcmd
    /usr/sbin/usermod -a -G nagcmd nagios
    /usr/sbin/usermod -a -G nagcmd apache
 
Old 05-24-2011, 10:26 AM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,252

Rep: Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685
Have a look at the usermod command and specifically its -G option (check man page). As it is only to be read or written to, I would suggest something like 664.
This was both owner and group members can read and update the file but the world can only look at it ( which may be good for when you are using your own login )
You say that it holds nothing important now, but the last thing you want to o is find there is a single executable line in it at some point and someone runs the file
mistakenly.
 
  


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
Prompt the user for a file to open, extract the XML and write to another text file. richiep Linux - Newbie 7 10-22-2010 04:34 PM
grip : no write access to write encoded file bidouilleur Linux - Software 5 10-09-2010 10:23 PM
forrtl: severe (47): write to READONLY file, unit 5, file /dev/pts/1 terrence Programming 1 10-01-2005 11:22 PM
Grip- "no write access to write encoded file" Alvis Linux - Software 4 01-06-2004 05:18 PM


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