My Apache 2 error log contains all error message lines splitted to individual characters - apache

I mean, all error messages is splitted into one character length, and these are the lines in my error_log. For example if the error message of my CGI application is "Error", I can see 5 lines of text, one line for every character of the error message, appended with referer and some other time informations. My error messages come from forked cURL process, and countains \r (carriage return) characters, because of the downloading progress indicator. What can I do to get the error output / stderr of my cURL processes really line-by-line?

Fortunately I managed to find the solution with Popen3 from the stdlib:
require "open3"
cmd=%Q{curl -b cookie.txt 'http://www.example.com/file/afancyfileid/yetanotherfilename.avi' -L -O -J}
Open3.popen3(cmd) {|stdin, stdout, stderr, wait_thr|
pid = wait_thr.pid # pid of the started process.
line_no=0
stderr.each_char do |c|
if c=="\r" then
line_no+=1
STDERR.puts if line_no % 5 == 0
else
STDERR.print c if line_no % 5 == 0
end
end
exit_status = wait_thr.value
}
I print only every 5th lines not to let grow my error_log so fast.

Related

Awk file shows an error

i run a simulation with udp connection and cbr application in ns2.
I run an awk file to show some results. I have 10 nodes and 2 of them (n0 and n10) send packets to each other. My problem is that i run these 2 codes to get result for both nodes but only the first one runs smoothly (n0 => n10):
1)gawk -f stats.awk src=0 dst=10 flow=0 pkt=512 file.tr
2) gawk -f stats .awk src=10 dst=0 flow=0 pkt=512 file.tr
The second code gives "division by zero attempted" error"
I don't include the stats.awk file here because it works in the first example so i guess the problem is something else? eg the flow in the second line is 0? i tried other numbers too but nothing happened.
Thanks in advance.

Ghostscript for PS integrity test: terminate at EOF, return error unless stack is empty

To test the integrity of PostScript files, I'd like to run Ghostscript in the following way:
Return 1 (or other error code) on error
Return 0 (success) at EOF if stack is empty
Return 1 (or other error code) otherwise
I could run gs in the background, and use a timeout to force termination if gs hangs with items left on the stack. Is there an easier solution?
Ghostscript won't hang if you send files as input (unless you write a program which enters an infinite loop or otherwise fails to reach a halting state). Having items on any of the stacks won't cause it to hang.
On the other hand, it won't give you an error if a PostScript program leaves operands on the operand stack (or dictionaries on the dictionary stack, clips on the clip stack or gstates on the graphics state stack). This is because that's not an error, and since PostScript interpreters normally run in a job server loop its not a problem either. Terminating the job returns control to the job server loop which does a save and restore round the total job, thereby clearing up anything left behind.
I'd suggest that if you really want to do this you need to adopt the same approach, you need to write a PostScript program which executes the PostScript program you want to 'test', then checks the operand stack (and other stacks if required) to see if anything is left. Note that you will want to execute the test program in a stopped context, as an error in the course of the program will clearly potentially leave stuff lying around.
Ghostscript returns 0 on a clean exit and a value less than 0 for errors, if I remember correctly. You would need to use signalerror in your test framework in order to raise an error if items are left at the end of a program.
[EDIT]
Anything supplied to Ghostscript on the command line by either -s or -d is defined in systemdict, so if we do -sInputFileName=/test.pdf then we will find in systemdict a key /InputFileName whose value is a string with the contents (/test.pdf). We can use that to pass the filename to our program.
The stopped operator takes an executable array as an argument, and returns either true or false depending on whether an error occurred while executing the array (3rd Edition PLRM, p 697).
So we need to run the program contained in the filename we've been given, and do it in a 'stopped' context. Something like this:
{InputFileName run} stopped
{
(Error occurred\n) print flush
%% Potentially check $error for more information.
}{
(program terminated normally\n) print flush
%% Here you could check the various stacks
} ifelse
The following, based 90% on KenS's answer, is 99% satisfactory:
Program checkIntegrity.ps:
{Script run} stopped
{
(\n===> Integrity test failed: ) print Script print ( has error\n\n) print
handleerror
(ignore this error which only serves to force a return value of 1) /syntaxerror signalerror
}{
% script passed, now check the stack
count dup 0 eq {
pop (\n===> Integrity test passed: ) print Script print ( terminated normally\n\n) print
} {
(\n===> Integrity test failed: ) print Script print ( left ) print
3 string cvs print ( item(s) on stack\n\n) print
Script /syntaxerror signalerror
} ifelse
} ifelse
quit
Execute with
gs -q -sScript=CodeToBeChecked.ps checkIntegrity.ps ; echo $?
For the last 1% of satisfaction I would need a replacement for
(blabla) /syntaxerror signalerror
It forces exit with return code 1, but is very verbous and distracts from the actual error in the checked script that is reported by handleerror. Therefore a cleaner way to exit(1) would be welcome.

Uploading job fails on the same file that was uploaded successfully before

I'm running regular uploading job to upload csv into BigQuery. The job runs every hour. According to recent fail log, it says:
Error: [REASON] invalid [MESSAGE] Invalid argument: service.geotab.com [LOCATION] File: 0 / Offset:268436098 / Line:218637 / Field:2
Error: [REASON] invalid [MESSAGE] Too many errors encountered. Limit is: 0. [LOCATION]
I went to line 218638 (the original csv has a headline, so I assume 218638 should be the actual failed line, let me know if I'm wrong) but it seems all right. I checked according table in BigQuery, it has that line too, which means I actually successfully uploaded this line before.
Then why does it causes failure recently?
project id: red-road-574
Job ID: Job_Upload-7EDCB180-2A2E-492B-9143-BEFFB36E5BB5
This indicates that there was a problem with the data in your file, where it didn't match the schema.
The error message says it occurred at File: 0 / Offset:268436098 / Line:218637 / Field:2. This means the first file (it looks like you just had one), and then the chunk of the file starting at 268436098 bytes from the beginning of the file, then the 218637th line from that file offset.
The reason for the offset portion is that bigquery processes large files in parallel in multiple workers. Each file worker starts at an offset from the beginning of the file. The offset that we include is the offset that the worker started from.
From the rest of the error message, it looks like the string service.geotab.com showed up in the second field, but the second field was a number, and service.geotab.com isn't a valid number. Perhaps there was a stray newline?
You can see what the lines looked like around the error by doing:
cat <yourfile> | tail -c +268436098 | tail -n +218636 | head -3
This will print out three lines... the one before the error (since I used -n +218636 instead of +218637), the one that had the error, and the next line as well.
Note that if this is just one line in the file that has a problem, you may be able to work around the issue by specifying maxBadRecords.

How to generate message boxes to display during and at the conclusion of a batch file process

I have created a batch file that generates a file listing output to a text file and then displays that text file in a browser. Since the listing takes awhile to generate, I want a message box to display during processing (and ideally another message box to display at the end indicating that the process completed) before it displays to the browser.
Place a line at the beginning of your script and at the end of your script.
'echo "Entry"'
'echo "Exit"'
Have the output sent to a log file which updates. This will be different depending on your language, but fairly easy to do.
As a separate process make an if statement that greps for Enrty and Exit. In Bash it would be:
grep_output=`grep Entry <file>`
if [ "$grep_output" == "" ]; then
entryoutput=true;
else
entryoutput=false;
fi
grep_output=`grep Exit <file>`
if [ "$grep_output" == "" ]; then
exitoutput=true;
else
exitoutput=false;
fi
while :; do
if $entryoutput=true and exitoutput=false; then
sleep 10
done
Not 100% on the syntax of that two condition if statement above.

BAT: Parse Output File For Error Handling

I have a process that is kicked off by a scheduled batch file daily. I need to have error handling built in to restart the process if there is an error. All works great most days but I get a time out error once a month or so that is unavoidable. The process does not output an errorlevel to the bat file so I need to be able to parse the output file to determine if the process needs to restart.
I tried using the FOR /F function to pass the contents of line 12 as a variable to use in an IF statement but I have been unsuccessful. I can obviously skip to line 12 but then I am left dealing with the tokens of the remaining lines. Does anyone have any suggestions that I could try?
Output file when all is well:
(Line Numbers Added for Readability)
1 Pricing Script
2
3 ________________________________________________________________________
4
5 Retrieve Prices
6
7 Date of price file: 070912
8 Regular only
9 Connecting to server intdata.com
10 TCP/IP connection established
11
12 TySymb Interactive Data
+400 more lines
Output file when there is an error:
1 Pricing Script
2
3 ________________________________________________________________________
4
5 Retrieve Prices
6
7 Date of price file: 071012
8 Regular only
9 Connecting to server intdata.com
10 TCP/IP connection established
11 Time Out
12 General Time Out. The User ID and/or Password might be incorrect.
I would simply look for the error message in the output using FIND or FINDSTR. I wouldn't worry about the line number.
find "General Time Out. The User ID and/or Password might be incorrect." "yourFile.log" && (
echo Timeout occurred, you must put code here to restart
)
or
findstr /c:"General Time Out. The User ID and/or Password might be incorrect." "yourFile.log" && (
echo Timeout occurred, you must put code here to restart
)
This will test only line 12 of your file for a given string:
#echo off
for /f "skip=11 tokens=*" %%i in (your_log_filename) do (
echo %%i | find "General Time Out" >nul
goto check
)
:check
if errorlevel 1 (echo No Timeout occured!) else (echo Timeout occured)