views:

101

answers:

4

Say i have a bash script:

#!/bin/bash
php ./listen.php 3001 3003 26 &
php ./listen.php 3002 3004 120 &

can i pipe all of them to same output log file at the same time without conflict? example:

#!/bin/bash
php ./listen.php 3001 3003 26 >/tmp/log 2>&1 &
php ./listen.php 3002 3004 120 >/tmp/log 2>&1 &
+4  A: 

> overwrites, so you'll want >> instead. stdout is line-buffered by default, so that is relatively safe. stderr is not. You should consider writing to the system log instead though.

Ignacio Vazquez-Abrams
I'm pretty sure stdout is line buffered only on underflow on most platforms. Very large writes to stdout are done in BUFSZ chunks, without regard to line endings. But yeah, the syslog suggestion seems best, there are utilities you can use that will syslog from stdin.
Andy Ross
This needs to be made clear: with > the second of the pipes to run will delete the initial output of the first. >> is definitely needed here.
Justin Smith
i ended up piping them to seperate logfiles just to be sure :)
jonaz
A: 

Most probably if each write constains new line terminated line.

Hovewer the lines from the both application will be interviling. Just try and see.

dimba
+2  A: 
Norman Ramsey
Seems like -f really refers to putting a specific file into the logs, according to the man pages both on my machine and your link. echo "blah" | logger -f /tmp/blahblah (with /tmp/blahblah not existing) produced "No such file or directory" error.
Platinum Azure
A: 

Theoretically you can:

#!/bin/bash

{ php ./listen.php 3001 3003 26 & php ./listen.php 3002 3004 120 & } >/tmp/log 2>&1

but I don't know how readable the result will be.

marco