Page 1 of 1

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

Posted: Wed Dec 14, 2005 12:25 am
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

Posted: Wed Dec 14, 2005 6:07 am
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

Posted: Wed Dec 14, 2005 8:31 am
by jameswilson
well done matey, i couldnt help at all there

Posted: Wed Dec 14, 2005 11:27 pm
by zoneminder
I think perl would have been a lot easier! :D

Phil

Posted: Thu Dec 15, 2005 1:21 am
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.