bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Text utility


From: Jonathan Andrews
Subject: Text utility
Date: Tue, 04 May 2004 16:27:58 +0100

Hi,

I've written a utility to maintain text files that follow the
"VARIABLE=value" format.

This file format is used by Redhat amongst others but its applicable to
any small configuration file or very simple flat file database.

It also is very useful for embedded systems for storing application
configuration information and simple cgi scripting (this is what I wrote
it for).

Its also a good way to get stuff in and out of bash as in

MYIP=`readwriteconfig -r /etc/sysconfig/networking/ifcfg-eth0`

and

readwriteconfig -w /etc/sysconfig/networking/ifcfg-eth0 IPADDR=$MYIP


Anyway .. I called it readwriteconfig, its partly documented - if anyone
wants it I will finish the documentation.

Its coded in plain C.

This is a simplified overview. The read mode is similar to grep, but
exists the code once the string has been found. The write mode could be
done with other sets of utils, but having a utility makes it more
accessible.

"readwriteconfig -r <filename> VARIABLENAME"
        Returns variable value or a fail code'

"readwriteconfig -rs <filename> VARIABLENAME"
        Same, but fails silently

"readwriteconfig -w <filename> VARIABLE=value"
        Update the line in the file replacing the OLD value if found,
appending it if not.

If it fits here let me know and I will put the source up somewhere.

Cheers,
Jon





***********************************************************
Example simple cgi using plain bash for small memory device
The configuration file is updated by another process.

# Check if the unit containing the temperature sensor is present
HW=`readwriteconfig -rs /config/hardware_units.cfg U_$TEMP`
if [ "$HW" != "1" ]; then
        echo "<br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;No unit
$TEMP present <br><br><br><br><br>"
        echo "</table>"
        ./OnSight-bottomline.cgi
        exit 0
fi



Example configuration file from bash only application
*****************************************************
The configuration file /config/hardware_units.cfg

UPDATEDBY=OnSight-serialbus
U_0=1
U_1=0
U_2=1
U_3=0
U_4=1
U_5=0
U_6=1
U_7=0
U_8=0
NUMBEROFUNITS=4
COMPLETE=TRUE







reply via email to

[Prev in Thread] Current Thread [Next in Thread]