Stuck on a /bin/sh script, cat, sed etc for ZM

A place for discussion of topics that are not specific to ZoneMinder. This could include Linux, Video4Linux, CCTV cameras or any other topic.
Post Reply
User avatar
cordel
Posts: 5210
Joined: Fri Mar 05, 2004 4:47 pm
Location: /USA/Washington/Seattle

Stuck on a /bin/sh script, cat, sed etc for ZM

Post by cordel »

Heres where I'm stuck,
Any help would be lovely.

This script is supposed to check the zm.conf file to make sure that the fields are populated (as this is primarily for a new install most should not) and ask for the values to populate those fields in the file. It asks and gets the value but Something is incorrect about my syntax to put to variable into the file.

So my problem is the line that starts with cat $ZM_CONFIG

Code: Select all

if [ -f $ZM_CONFIG ]; then
    . $ZM_CONFIG
else
    echo "ERROR: $ZM_CONFIG not found."
    exit 1
fi

for n in ZM_DB_SERVER ZM_DB_NAME ZM_DB_USER ZM_DB_PASS; do
    eval "val=\$$n"
    if [ "$val" = "" ]; then
        echo "ERROR($ZM_CONFIG): $n should not be empty."
        echo "Enter a $n for ZM to use the Database."
        echo -n "$n : "
            if [ "$n" = "ZM_DB_PASS" ]; then
                stty -echo    # Turns off screen echo.
                read newval
                stty echo     # Restores screen echo.
            else
                read newval
            fi
    cat $ZM_CONFIG |sed 's/^$n=.*$/$n=$newval/g' /tmp/$$ && mv /tmp/$$ $ZM_CONFIG
    fi
done
This is the only show stopper for the new CTU-ZM 64 bit distro.
any help or ideas are welcome.
cat and sed have always been a week point for me and it is time I get a grasp on them. I have been googling for the last few days and am missing something in the syntax of how it all comes together. You'd think after I have managed to grasp everything else :oops: I'd get these. but looking as how the various wild card strings( Regular Expressions)can be put together, I'm lost. If even a pointer to some good tutorials would be helpful.

Regards,
Cordel
Image
Image
3939663646337

It's better to keep your mouth shut and appear stupid than open it and remove all doubt.
-Mark Twain
User avatar
cordel
Posts: 5210
Joined: Fri Mar 05, 2004 4:47 pm
Location: /USA/Washington/Seattle

Post by cordel »

And the answer is:

Code: Select all

cp $ZM_CONFIG $ZM_CONFIG.bak &&
        sed 's/^'$n='.*$/'$n=$newval'/g' $ZM_CONFIG.bak >$ZM_CONFIG
I didn't sleep at all last night pounding my head on this one, then I found some good reference. Finaly after going though at least 80+ other sites.
http://www.student.northpark.edu/pement ... edfaq.html
Just in case any one else is interested.

Expect to see the beta ver of the 64 bit distro in the next few days.
I'm going to bed now.
Good night,
Corey
jameswilson
Posts: 5111
Joined: Wed Jun 08, 2005 8:07 pm
Location: Midlands UK

Post by jameswilson »

well done matey, i couldnt help at all there
James Wilson

Disclaimer: The above is pure theory and may work on a good day with the wind behind it. etc etc.
http://www.securitywarehouse.co.uk
User avatar
zoneminder
Site Admin
Posts: 5215
Joined: Wed Jul 09, 2003 2:07 pm
Location: Bristol, UK
Contact:

Post by zoneminder »

I think perl would have been a lot easier! :D

Phil
User avatar
cordel
Posts: 5210
Joined: Fri Mar 05, 2004 4:47 pm
Location: /USA/Washington/Seattle

Post by cordel »

I haven't ventured over to perl yet :? I have glanced over some documentation, but thats it. What was really buging me was that I was stuck on a one liner :lol:
It would be nice to be able to consentrate on learning just one language for a bit.
Post Reply