NeronLeVelu
NeronLeVelu

Reputation: 10039

ksh - pipe cannot write to output

i use this line in a ksh (not ksh93) under AIX 6.1

# initiate earlier
LineStart=235559
cst_TracorTailLook=128
FileName=/LongPathWithSlash/logs/file.log
# /LongPathWithSlash/logs/file.log -> file_log.27Jun2014-00:00:00
# File is about 250.000 line and 60.000.000 bytes or more 

# the failing line
tail -n +$(( ${LineStart} - ${cst_TracorTailLook} + 1 )) ${FileName} |
    SomeAction

running in direct session, no problem, it return the result (test with a wc -l after pipe return a number of line) but running from and agent (Tivoli monitoring agent) this line return:

tail: 0652-046 Cannot write to output.
There is no process to read data written to a pipe.

Loking for limitation i found less limitation (ulimit-a) from the agent than direct session

                     Direct      Agent
time(seconds)        unlimited   unlimited
file(blocks)         unlimited   unlimited
data(kbytes)         131072      unlimited
stack(kbytes)        32768       32768
memory(kbytes)       32768       32768
coredump(blocks)     2097151     unlimited
nofiles(descriptors) 2000        unlimited
threads(per process) unlimited   unlimited
processes(per user)  unlimited   unlimited

I found several issue on AIX 5.3 about limitation to 2 Gb but this is not the size nor the OS version

Eventually, is there an alternative without passing through temporary file ?

Upvotes: 0

Views: 1091

Answers (2)

Walter A
Walter A

Reputation: 20022

Make sure the script that is called by the agent is finished in 10 seconds. Tailing the large logfiles should be done "outside" the agent. You said crontab is not possible here, maybe you can fire a background process:

LASTRESULT="cat ${ResultAction}"
nohup SomeAction > ${ResultAction} 2>&1 &

Of course this way your agent does not have the latest result, so be aware to start the agent often. Not too often, you do not want concurrent (background) processes scanning your output. (Check this in your current solution as well).

Can you make the logfile you are monitoring smaller? Turn off debug logging or rotating the file more often ? Does the program that is writing the logfile closing the filedescriptor after each log-action?

timestamp=${your_layout_yyyymmdd_hhmm}
mv ${FileName} ${FileName}.${timestamp}
touch ${FileName}
# I think Now you do not want to use a 
# tail -n +${offset} ${FileName}.${timestamp} | SomeAction
# and you are happy with
cat ${FileName}.${timestamp} | SomeAction

Upvotes: 1

Walter A
Walter A

Reputation: 20022

When the SomeAction after the pipe is finished before the tail is finished, you will have a broken pipe. Make sure your SomeAction will wait until tail is finished.

Upvotes: 1

Related Questions