AW: AW: [Users] problems with vzctl init logging patch

Dietmar Maurer dietmar at maurer-it.com
Thu Mar 13 03:43:18 EDT 2008


> Adding a check makes sense. But first -- why do you need perl 
> at all? Is there something that can't be done in shell?
> >   

I just remembered why I hate shell programming ;-)

Please can someone tell me how to do a binary read with a shell. In perl
I simple do:

while (my $len = sysread (LOGFIFO, $buf, 4096)) {
  syswrite (LOGFILE, $buf);	
}

How to do that with a shell script? I first tried:

cat <$logfifo >>$logfile

But that spans a new process, and I do not want that. 

Using builtin commands only:

while [ 1 ]; do
        read line || break
        echo $line
done < $logfifo >>$logfile

Works, but always waits for whole lines (we want to read/write
immeniately instead)

The following code works for bash, but not for other shells:

while [ 1 ]; do
        # -n is not available everywhwere (i.e. dash)
        read -n 1 data || break
        if [ -z $data ]; then
            echo
        else
            echo -n $data
        fi
done < $logfifo >>$logfile

Any Ideas?

- Dietmar





More information about the Users mailing list