Re: Using java process to write file failes
Re: Using java process to write file failes
- Subject: Re: Using java process to write file failes
- From: Wolfram Stebel <email@hidden>
- Date: Wed, 07 Sep 2005 22:22:32 +0200
Am 07.09.2005 18:22 Uhr schrieb "Sacha Mallais" unter
<email@hidden>:
Hi Sacha,
thanks for your answer
> On Sep 7, 2005, at 6:14 AM, Wolfram Stebel wrote:
>
>> Hi all,
>>
>> i'm trying to extract some data from my apache logs.
>> the following code creates a file (owner appserver:admin) first.
>> With the "more | grep" i try to append data to the file.
>> This gives me the error "access denied", so i think, the Process p
>> is not
>> running under "appserver" user.
>> How can i do such shell commands under the correct user?
>> Clearly, in development the code does the job without access problems.
>
> First, using "more" in this context is extremely unlikely to work:
> "more" is a pager (meaning it outputs a text file page by page so
> that you can see it all). What you probably want is "cat <file> |
> grep <blah>". However, even that is not necessary, instead: "grep
> <blah> <file>"
i used more for decades as input for grep. it does not page then, but your
tip is a much better shortcut :-) i will downgrade my server now, knowing
this ;-))
> Next, as for permissions, you're best bet is to make sure the
> permissions on the file is correct. Any other solution will have the
> same effect, and that is the easiest, so you might as well do that.
> Try this to determine if it actually is a permissions problem:
>
> sudo -u appserver cd /path/to/file
>
> If that fails, there is a permissions problem with the parent
> directories. If that works, try this next:
>
> sudo -u appserver cat /path/to/file/<file>
>
> If that fails, there is a permissions problem with the file itself.
Sorry, i did not test this, on the command line all of those commands worked
fine, so it is a permission problem.
what i tested and found working:
Process p executes the command correctly but does no output redirection to
my file with ">>" or ">".
I simply fetch the result from p.getInputStream () like this:
if ( readResult )
{
String result = null;
BufferedReader in = new BufferedReader( new
InputStreamReader ( p.getInputStream () ) );
while ( in.ready () )
{
if ( result == null )
result = in.readLine ();
else
result += "\n" + in.readLine ();
}
return result;
}
although this might be very expensive on large result sets.
One issue is remaining:
With the command:
awk -v FS=\" \" '{ total+=$10} END { print total}' myFile
i get error: /usr/bin/awk: non-terminated string ... at source line 1
when parsing a file like:
84.174.23.171 - - [05/Sep/2005:14:40:30 +0200] "GET
/MandantData/p/Documents/Tennis034_thumb.jpg HTTP/1.1" 200 53108
84.174.23.171 - - [05/Sep/2005:14:40:30 +0200] "GET
/MandantData/p/Documents/Tennis060_thumb.jpg HTTP/1.1" 200 45940
84.174.23.171 - - [05/Sep/2005:14:40:49 +0200] "GET
/MandantData/p/Logos/Hanball.gif HTTP/1.1" 200 9382
84.174.23.171 - - [05/Sep/2005:14:40:49 +0200] "GET
/MandantData/p/Logos/Leichtathletik.gif HTTP/1.1" 200 14261
84.174.23.171 - - [05/Sep/2005:14:40:27 +0200] "GET
/cgi-bin/WebObjects/WebClubs.woa/1/wo/MBZhR3UuB68HHuv54iMkKw/0.3.6.0.2.1.10.
3.1.1 HTTP/1.1" 200 13880
84.174.23.171 - - [05/Sep/2005:14:40:29 +0200] "GET
/cgi-bin/WebObjects/WebClubs.woa/1/wo/MBZhR3UuB68HHuv54iMkKw/1.3.17.1.1.12.2
.1.1 HTTP/1.1" 200 26166
84.174.54.195 - - [05/Sep/2005:17:57:29 +0200] "GET
/cgi-bin/WebObjects/WebClubs.woa/1/wo/MBZhR3UuB68HHuv54iMkKw/0.3.6.0.2.1.10.
3.1.1 HTTP/1.1" 200 13880
84.174.54.195 - - [05/Sep/2005:17:57:31 +0200] "GET
/cgi-bin/WebObjects/WebClubs.woa/1/wo/MBZhR3UuB68HHuv54iMkKw/1.3.17.1.1.12.1
.1.1 HTTP/1.1" 200 23818
84.178.229.116 - - [05/Sep/2005:20:51:28 +0200] "POST
/cgi-bin/WebObjects/WebClubs.woa/1/wo/MBZhR3UuB68HHuv54iMkKw/1.3.17
HTTP/1.1" 200 6862
84.178.229.116 - - [05/Sep/2005:20:48:57 +0200] "GET
/cgi-bin/WebObjects/WebClubs.woa/1/wo/40ARnWTBkXG7WPDb10UsDM/0.3.6.0.2.1.8.3
.1.1 HTTP/1.1" 200 14365
84.178.229.116 - - [05/Sep/2005:20:51:33 +0200] "POST
/cgi-bin/WebObjects/WebClubs.woa/1/wo/40ARnWTBkXG7WPDb10UsDM/2.3.15.1
HTTP/1.1" 200 11808
As before, commandline works well...
The lines are separated by "\n".
I cant find any tip for this error.
Thanks for your help.
Wolfram
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden