1

我编写了这个小 shell 函数来修改 samba conf 文件。但似乎,它在这条线的某个地方失败了sed -e "$t1,$t2 d" $CFGFILE > $TMPFILE。错误是:

Doing Samba customization...
/etc/samba/smb.conf
/etc/samba/smb.conf.tmp
sed: -e expression #1, char 1: unknown command: `,'

我也面临同样的问题sedsed -e "$t1, $ d" $CFGFILE > $TMPFILE//目的是从行号 t1 删除直到结束

这是shell函数:

updateSmbConf()
{
SMBCFG="$DIR_ETCSAMBA/smb.conf"
SMBCFGTMP="$SMBCFG.tmp"

echo $SMBCFG
echo $SMBCFGTMP

# Fix for bug #3147
sed "s/INSITEONE-CIFS/DELL-CIFS/" $SMBCFG > $SMBCFGTMP
sed "s/InSiteOne CIFS Archive/DCCA CIFS Archive/" $SMBCFG > $SMBCFGTMP
cp $SMBCFGTMP $SMBCFG
rm $SMBCFGTMP

t1=` grep -n "\[Archive\]" $CFGFILE | cut -f1 -d:`
t2=$(($t1+11-1)) # Remove the next 11 lines
sed -e "$t1,$t2 d" $CFGFILE > $TMPFILE
cp $TMPFILE $CFGFILE
rm $TMPFILE

#[SampleHA]
#t1=` grep -n "\[SampleHA\]" $CFGFILE | cut -f1 -d:`
#sed -e "$t1, $ d" $CFGFILE > $TMPFILE
#cp $TMPFILE $CFGFILE
#rm $TMPFILE
}

这是我要修改的 smb.conf:

------------------------------------------------------------------------------------
                     COMPLETE SMB.CONF
------------------------------------------------------------------------------------
cat /etc/samba/smb.conf
# smb.conf is the main Samba configuration file. You find a full commented
# version at /usr/share/doc/packages/samba/examples/smb.conf.SUSE if the
# samba-doc package is installed.
# Date: 2006-07-13
[global]
       guest account = insite1
       oplocks = no
       msdfs root = yes
       workgroup     = INSITEONE-CIFS
       server string = "InSiteOne CIFS Archive"
       security      = SHARE
       syslog        = 0
       max smbd processes = 15
       interfaces = eth* lo
       bind interfaces only = no

#[Archive]
#       hosts allow = 127.0.0.1 10.135.30.135 10.135.30.135
#       hosts deny = ALL
#       vfs objects  = relay:"host = localhost; \
#                             port = 1025;      \
#                             log_level  = 0"
#       comment = InSiteOne Archive File System
#       path = /opt/samba
#       read only = No
#       guest ok = Yes
#       locking = no
[DCCAArchive]
        comment = DCCA Archive File System
        path = /opt/insiteone/fuse-mount/ifm
        read only = No
        public = yes
        writeable = yes
        create mask=0777
        guest ok = Yes
#[SampleHA]
#        comment = High Availability Share
#        path = <Path of Local Archive e.g. /opt/samba3/archive>
#        read only = No
#        guest ok = Yes
#        locking = no
#        hosts allow = 127.0.0.1 OTHERPROXYIP
#        hosts deny = ALL
#        directory mode = 0775
#        create mode = 0664
4

1 回答 1

2

您标记了问题,因此使用 GNU sed 您可以:

sed -i '/\[Archive\]/,+11 d' $SMBCFG

这会就地修改文件,因此不需要 tmpfile,并匹配包含 的行[Archive],因此不需要grep,并删除它和接下来的 11 行。

于 2013-08-13T17:37:49.737 回答