Hello to all board members here,
i'm little bit stuck with one script thing, so I will be very happy, if have some ideas regarding this.
I would like to create simple wrapper to start program in background, pipe its output to syslog and create pidfile.
Basically something like this:
$command 2>&1 | logger -t $syslogtag ($!) &
echo $! > $pidfile
I'm using logger command for redirection to syslog, -t is syslog tag, so it will write something like "mydaemon (pid)" on every line of program output.
So far, so good. But obviously when I would like to write pidfile, value in $! variable is updated by pid of logger process.
I tried few things
- $_ variable normally holds, last argument of last command (so it should be "(pid)"), but it won't work for me.
- any subcommands for storing of command pid to some variable broke redirection or sending to background
- pid of subsequent command is usually incremented by one, so theoretically i could subtract one to get first pid, but it is controlled by OS and i can't rely on this.
Do you know some way, how to solve it?