[RndTbl] Scripting question

Trevor Cordes trevor at tecnopolis.ca
Tue Jan 30 15:27:03 CST 2007


On 30 Jan, Kevin McGregor wrote:
> I have this script:
> #!/bin/bash
> 
> if [ -e /var/run/pgsql.pipe ]; then
>         while [ -e /var/run/pgsql.pipe ]
>         do
>                 psql -q -h padsysdb -U sysloguser syslog </var/run/pgsql.pipe
>         done
> fi

The if and while are redundant, no?  Just use the while.

And does anything ever delete the pgsql.pipe file?  If not, why the
while?  If you do Sean's inittab respawn you don't need the while.

If you're not expecting it to die, then you could try rc.local (run with
&), with or without the while.

Oh ya, one other glitch: if the pipe doesn't exist at boot, your script
will just end... or respawn too rapidly!  Don't you want something more
like:

while [ true ]
do
  if [ -e /var/run/pgsql.pipe ]; then
    psql -q -h padsysdb -U sysloguser syslog </var/run/pgsql.pipe
  fi
  sleep 30
done

Oh ya, there's also potential race conditions there, but if you add
>/dev/null 2>&1 to the psql line it probably won't matter.



More information about the Roundtable mailing list