View unanswered posts | View active topics It is currently Mon May 20, 2013 4:22 pm



Reply to topic  [ 5 posts ] 
Stuck on a /bin/sh script, cat, sed etc for ZM 
Author Message
User avatar

Joined: Fri Mar 05, 2004 5:47 pm
Posts: 5218
Location: /USA/Washington/Seattle
Post Stuck on a /bin/sh script, cat, sed etc for ZM
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:
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
[url=http://tinyurl.com/cae63]Image
3939663646337[/url]
It's better to keep your mouth shut and appear stupid than open it and remove all doubt.
-Mark Twain


Wed Dec 14, 2005 1:25 am
Profile WWW
User avatar

Joined: Fri Mar 05, 2004 5:47 pm
Posts: 5218
Location: /USA/Washington/Seattle
Post 
And the answer is:
Code:
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


Wed Dec 14, 2005 7:07 am
Profile WWW

Joined: Wed Jun 08, 2005 9:07 pm
Posts: 5078
Location: Midlands UK
Post 
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


Wed Dec 14, 2005 9:31 am
Profile WWW
Site Admin
User avatar

Joined: Wed Jul 09, 2003 3:07 pm
Posts: 5221
Location: Bristol, UK
Post 
I think perl would have been a lot easier! :D

Phil


Thu Dec 15, 2005 12:27 am
Profile ICQ YIM WWW
User avatar

Joined: Fri Mar 05, 2004 5:47 pm
Posts: 5218
Location: /USA/Washington/Seattle
Post 
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.


Thu Dec 15, 2005 2:21 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 5 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group