亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊(cè) 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 4532 | 回復(fù): 5
打印 上一主題 下一主題

關(guān)于使用awk直接在文中替換的問題 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2010-01-04 16:49 |只看該作者 |倒序?yàn)g覽
  1. awk '{ sub(/piobe:/,":piobe:");print > "/tmp/inittab" }' /tmp/inittab
復(fù)制代碼


想實(shí)現(xiàn)對(duì)inittab中piobe服務(wù)直接用:冒號(hào)注釋掉,但是實(shí)測結(jié)果是,冒號(hào)是加上了,但是inittab會(huì)不斷增長空行,直到使用Ctrl C強(qiáng)制中斷,否則命令執(zhí)行完了光標(biāo)就一直不跳出來。不知道是哪里出了問題,請(qǐng)各位指點(diǎn)一下,謝謝!

[ 本帖最后由 banhao 于 2010-1-6 21:13 編輯 ]

論壇徽章:
23
15-16賽季CBA聯(lián)賽之吉林
日期:2017-12-21 16:39:27白羊座
日期:2014-10-27 11:14:37申猴
日期:2014-10-23 08:36:23金牛座
日期:2014-09-30 08:26:49午馬
日期:2014-09-29 09:40:16射手座
日期:2014-11-25 08:56:112015年辭舊歲徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:49:0315-16賽季CBA聯(lián)賽之山東
日期:2017-12-21 16:39:1915-16賽季CBA聯(lián)賽之廣東
日期:2016-01-19 13:33:372015亞冠之山東魯能
日期:2015-10-13 09:39:062015亞冠之西悉尼流浪者
日期:2015-09-21 08:27:57
2 [報(bào)告]
發(fā)表于 2010-01-04 16:53 |只看該作者

回復(fù) #1 banhao 的帖子

awk 直接修改原文件是有問題的,不同版本的 awk 結(jié)果都不一樣。
還是老老實(shí)實(shí)用臨時(shí)文件過渡吧。

論壇徽章:
0
3 [報(bào)告]
發(fā)表于 2010-01-04 16:54 |只看該作者
由于你在awk中重定向到了/tmp/inittab

論壇徽章:
0
4 [報(bào)告]
發(fā)表于 2010-01-04 16:57 |只看該作者
/tmp/inittab是我復(fù)制了/etc/inittab用來測試的,總不能直接拿/etc/inittab來測試吧。

論壇徽章:
1
榮譽(yù)會(huì)員
日期:2011-11-23 16:44:17
5 [報(bào)告]
發(fā)表于 2010-01-04 17:24 |只看該作者
用sed或者vim吧

論壇徽章:
0
6 [報(bào)告]
發(fā)表于 2010-01-04 17:41 |只看該作者
#!/usr/bin/ksh
# IBM_PROLOG_BEGIN_TAG
# This is an automatically generated prolog.
#  
# bos610 src/bos/usr/lib/security/aixpert/scripts/comntrows.sh 1.4
#  
# Licensed Materials - Property of IBM
#  
# Restricted Materials of IBM
#  
# COPYRIGHT International Business Machines Corp. 2006,2007
# All Rights Reserved
#  
# US Government Users Restricted Rights - Use, duplication or
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
#  
# IBM_PROLOG_END_TAG
# @(#)84        1.4  src/bos/usr/lib/security/aixpert/scripts/comntrows.sh, aixpert, bos610 2/25/07 07:36:10
#        COMPONENT_NAME                : (AIXPERT) comntrows.sh
#        FUNCTIONS                : None
#        ORIGINS                        : 27
#
#        Command Line Arguments        : The script takes 5 command line arguments.
#                                The first argument mentions the unique string
#                                or daemon or script in a line that has to be
#                                disabled/commented. The second argument mentions
#                                the file where the enrty corresponding to the
#                                daemon/script/string (mentioned by the first
#                                argument) is present. The third argument should
#                                be the comment character in the file specified
#                                by the second argument.
#                                The fourth argument mentions whether the script
#                                or daemon has to be disabled/enabled. Value 'a'
#                                indicates that the daemon should be enabled and
#                                'd' indicates that the daemon should be disabled.
#                                The fifth argument is optional and should be rulename.
#
#        Syntax                        : comntrows {daemon|scriptname} filename
#                                                commentchar {a|d} [rulename]
#
#        OUTPUT                        : None
#
#        Description                : This script disables/enables the daemons/scripts
#                                by commenting/uncommenting the corresponding entries
#                                from the specified file. If the rulename is specified
#                                and if there are any changes done by the rule, then
#                                an undo rule with name Undo$5 <timestamp> will be
#                                generated.This script should be run with
#                                superuser privileges.

export PATH=/usr/bin:/usr/sbinPATH

# Initialize variables AIXPERT_FIFO, LOG, REPORT and UNDOXML
. /etc/security/aixpert/bin/initialize_variables

TMP=/etc/security/aixpert/tmp/comtrows
PID=$$

# Log output and errors to /etc/security/aixpert/log/aixpert.log
exec 1>>$LOG
exec 2>&1

if ( [ $# -lt 4 ] || [ $# -gt 5 ] ) || ( [ "$4" != "a" ] && [ "$4" != "d" ] )
then
        dspmsg -s 6 aixpert.cat 1 "Usage :\
comntrows daemon|scriptname filename commentchar {a|d} [rulename]\n"
        exit 1
fi

# echo all the commands and the current time and date to the AIXpert log
set -x
date
echo $0

# Check whether the file specified by argument 2 is a regular file or not.
if [ -f $2 ]
then
        # Determine whether the entry for the daemon/script exists/commented/uncommented
        # Status value 'a' states that the daemon/process is uncommented in /etc/inittab.
        # Value 'd' states that the daemon/process is commented, and value 'n' specifies
        # that the daemon/process's entry doesnt exist in the /etc/inittab file.
        status=`awk -v dmn=$1 -v cmt=$3 -v exist="n" '
                BEGIN {
                format=sprintf("(^[\t ]*%s)|(^[\t ]*[^%s]+%s)",dmn,cmt,dmn);
                comformat=sprintf("^[\t ]*%s.*%s",cmt,dmn);
                }
                {
                if(match($0,format))
                {
                        exist="a";
                }
                else if(match($0,comformat))
                {
                        exist="d"
                }
                }
                END {
                printf("%s",exist)
                }' $2`
       
        # If the entry for the daemon/script exists and is commented/uncommented
        # when the script has been invoked to uncomment/comment respectively
        # the daemon/script entry.

        # Check whether AIXPERT_CHECK_REPORT environment variable is set/not.
        report=`echo $AIXPERT_CHECK_REPORT`

        if ( [ "$status" != "n" ] && [ "$4" != "$status" ] )
        then
                if [ "$report" = "1" ]
                then
                        if [ "$status" = "a" ]
                        then
                                curstat="enabled"
                                desstat="disabled"
                        else
                                curstat="disabled"
                                desstat="enabled"
                        fi
                        dspmsg -s 6 aixpert.cat 2 "comntrows.sh:\
Daemon/Script/String:%s in file %s should have status %s,\
however it is %s now\n" $1 $2 $desstat $curstat >>$REPORT
                        dspmsg -s 6 aixpert.cat 2 "comntrows.sh:\
Daemon/Script/String:%s in file %s should have status %s,\
however it is %s now\n" $1 $2 $desstat $curstat >>$AIXPERT_FIFO
                        exit 1
                fi

                # Construct the regular expression string to be searched using
                # the arguments $1(daemon name) and $3 (comment char),
                # when a match is found comment/uncomment the line with argument
                # $3 as comment char, Store the output of awk in $TMP$PID

                if [ "$4" = "d" ]
                then
                        awk -v dmn=$1 -v cmt=$3 '
                        BEGIN {
                        format=sprintf("(^[\t ]*%s)|(^[\t ]*[^%s]+%s)",dmn,cmt,dmn);
                        }
                        {
                        if(match($0,format))
                        {
                                print cmt $0
                        }
                        else
                        print $0
                        }' $2 >>$TMP$PID
                else
                        awk -v dmn=$1 -v cmt=$3 '
                        BEGIN {
                        format=sprintf("(^[\t ]*%s.*%s)",cmt,dmn);
                        }
                        {
                        if(match($0,format))
                        {
                                # replace the first occurence of comment in the record
                                sub(cmt,"",$0)
                        }
                        print $0
                        }' $2 >>$TMP$PID


                fi

                # Move the file $TMP$PID to $2
                mv $TMP$PID $2
        elif [ "$status" = "n" ]
        then
                if [ "$report" = "1" ]
                then
                        if [ "$4" = "a" ]
                        then
                                desstat="enabled"
                        else
                                desstat="disabled"
                        fi
                        dspmsg -s 6 aixpert.cat 6 "comntrows.sh:\
Daemon/Script/String:%s should have status %s,\
however its entry is not found in file %s\n" $1 $desstat $2 >>$REPORT
                        dspmsg -s 6 aixpert.cat 6 "comntrows.sh:\
Daemon/Script/String:%s should have status %s,\
however its entry is not found in file %s\n" $1 $desstat $2 >>$AIXPERT_FIFO
                        exit 1
                else
                        # Entry not found in $2
                        dspmsg -s 6 aixpert.cat 7 "comntrows.sh:\
Daemon/Script/String:%s's entry not found in file %s\n" $1 $2
                        exit 1
                fi
        fi

        if [ "$4" = "d" ]
        then
                daemon=`echo $1|awk -F ":" '{print $1}'`
                # Check whether string specified by argument $1 is a daemon or not
                # Stop the daemon, if it's in active state
                lssrc -s $daemon
                if [ $? -eq 0 ]
                then
                        lssrc -s $daemon|grep active
                        if [ $? -eq 0 ]
                        then
                                # Dynamic Security Check
                                if [ "$report" = "1" ]
                                then
                                        dspmsg -s 6 aixpert.cat 3\
"comntrows.sh: Daemon:%s is still active, however is should be in\
inoperative state\n" $1 >>$REPORT
                                        dspmsg -s 6 aixpert.cat 3\
"comntrows.sh: Daemon:%s is still active, however is should be in\
inoperative state\n" $1 >>$AIXPERT_FIFO
                                        exit 1
                                fi
                                stopsrc -s $daemon
                        fi
                fi
        elif [ "$4" = "a" ]
        then
                daemon=`echo $1|awk -F ":" '{print $1}'`
                # Check whether string specified by argument $1
                # is a daemon or not, Start the daemon, if it's not active
                lssrc -s $daemon
                if [ $? -eq 0 ]
                then
                        lssrc -s $daemon|grep inoperative
                        if [ $? -eq 0 ]
                        then
                                # Dynamic Security Check
                                if [ "$report" = "1" ]
                                then
                                        dspmsg -s 6 aixpert.cat 4\
"comntrows.sh: Daemon:%s is in inoperative state, however it should be\
active\n" $1 >>$REPORT
                                        dspmsg -s 6 aixpert.cat 4\
"comntrows.sh: Daemon:%s is in inoperative state, however it should be\
active\n" $1 >>$AIXPERT_FIFO
                                        exit 1
                                fi
                                startsrc -s $daemon
                        fi
                fi
        fi
        # Dynamic Security Check
        if [ "$report" = "1" ]
        then
                exit 0                # Everything is fine
        fi

        if [ $# -eq 5 ]
        then
                empty=`grep "^<AIXPertUndo>" $UNDOXML`
                if [ "$empty" = "" ]
                then
                        echo "\n<AIXPertUndo>\n</AIXPertUndo>" >> $UNDOXML
                fi

                # Get the rulename and put it in undo rule
                name=`echo $AIXPERT_NAME`
                # Get the rule description & pass it to undo rule
                desc=`echo $AIXPERT_DESC`

                # Add an undo XML rule to the file $UNDOXML
                awk -v rulehalf1="\t<AIXPertEntry name=\"$name\">\n\
\t\t<AIXPertRuleType type=\"Undo\"/>\n\
\t\t<AIXPertDescription>Undo action for \"$desc\"</AIXPertDescription>\n\
\t\t<AIXPertPrereqList/>\n"\
-v rulehalf2="\t\t<AIXPertCommand>/etc/security/aixpert/bin/comntrows\
</AIXPertCommand>\n\t\t<AIXPertArgs>$1 $2 $3 $status</AIXPertArgs>\n\
\t\t<AIXPertGroup>Rules for /etc/inittab</AIXPertGroup>\n\
\t</AIXPertEntry>" '{if(match($0,"^[\t ]*</AIXPertUndo>"==0) print $0;\
else print rulehalf1 rulehalf2 "\n" $0}' $UNDOXML >$TMP$PID
                mv $TMP$PID $UNDOXML
        fi
else
        dspmsg -s 6 aixpert.cat 5 "comntrows.sh: The file %s doesn't exist\n" $2
fi

exit 0



這段代碼是AIX5.3以后的新功能AIX Security Expert中的實(shí)現(xiàn)方式,但是有點(diǎn)看不懂,也是通過awk來實(shí)現(xiàn)的,有沒有人能解讀一下其中最核心的部分?
這個(gè)腳本名字是comntrows,可以直接被調(diào)用,調(diào)用方式為 ./comntrows qdaemon: /etc/inittab : d  如果將d改為a,就可以將注釋的冒號(hào)從inittab中去掉。d表示注釋掉該行,a表示恢復(fù)該行。
您需要登錄后才可以回帖 登錄 | 注冊(cè)

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號(hào)-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號(hào):11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請(qǐng)注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP