The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to change the replace the String in sub folders bobbygsk UNIX for Dummies Questions & Answers 6 09-30-2008 09:09 AM
change string in file kamel.seg Shell Programming and Scripting 1 01-07-2008 04:45 AM
How to change only the x first characters of a string? Juha Shell Programming and Scripting 2 09-28-2007 05:17 AM
replace character in a string pattern and save the change in same file mihir0011 Shell Programming and Scripting 2 09-26-2007 02:31 PM
Change the a string in the file kamathg Shell Programming and Scripting 3 08-08-2007 05:14 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 12-15-2007
mirusnet's Avatar
Registered User
 

Join Date: Dec 2007
Posts: 139
Change a string

I have my.cnf file:

[mysqld]
log-bin = mysql-bin
relay-log = relay-bin
#skip-slave-start
......

If there is no "skip-slave-start", I want to add it.
Or uncomment if it presents and commented.
Could someone tell me how to implement this feature in the easiest way?
Reply With Quote
Forum Sponsor
  #2  
Old 12-17-2007
Yogesh Sawant's Avatar
Part Time Moderator and Full Time Dad
 

Join Date: Sep 2006
Location: Rossem, Tazenda
Posts: 798
try this shell script:
Code:
#!/bin/bash
grep '^skip-slave-start' my.cnf >& /dev/null
if [ $? -ne 0 ] ; then
    echo "skip-slave-start is not turned on, so going to turn it on..."
    grep '^ *# *skip-slave-start' my.cnf >& /dev/null
    if [ $? -eq 0 ] ; then
    # skip-slave-start is commented
        sed -i 's/^ *# *skip-slave-start/skip-slave-start/' my.cnf
            # so uncommnt it
    else
    # skip-slave-start is not present
        sed -i 's/\[mysqld\]/[mysqld]\nskip-level-start/' my.cnf
            # so add it in [mysqld] section
    fi
else
    echo "skip-slave-start was turned on"
fi
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
bash, mysql

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 07:01 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0