Overclock.net - An Overclocking Community - View Single Post - Why is this correct? Looks to me like it shouldn't work.

View Single Post
post #29 of (permalink) Old 12-13-2017, 12:56 PM
herkalurk
Retired Staff
 
herkalurk's Avatar
 
Join Date: May 2010
Location: Portland, OR
Posts: 2,039
Rep: 69 (Unique: 58)
Code:
        if [ `grep -c "^#dateext" ${ROTATE}` -eq 1 ]
        then
                sed -i 's/^#dateext/dateext/g' ${ROTATE}
                echo "Uncommented dateext"
                SUCCESS[${#SUCCESS[*]}]="Log date extnesions uncommented in config\n"
        elif [ `grep -c "^dateext" ${ROTATE}` -eq 1 ]
        then
                echo "dateext already enabled"
                SKIP[${#SKIP[*]}]="Log date extensions already enabled in config\n"
        elif [ `grep -c "^dateext" ${ROTATE}` -eq 0 ]
        then
                sed -i "s/compress/compress\n\ndateext/g" ${ROTATE}
                echo "Added dateext"
                SUCCESS[${#SUCCESS[*]}]="Log date extensions setting added to config\n"
        else
                echo "Unsure of what to do? dateext isn't normal"
                FAIL[${#FAIL[*]}]="Log date extnesions settings aren't normal, please fix manually\n"
        fi

Here's another example I found in my scripts. It's part of a script to setup a RHEL box and configure the logrotate settings. The first if checks to see if dateext is commented, then uncomment, then 2nd it it's already uncommented the log the fact we skipped it, then 3rd we didn't find it, so we add it, and finally a failure message.



herkalurk is offline