我想注释/取消注释以在httpd
使用sed
或的实例中禁用/启用两个配置节标记之间的缓存awk
。
我可以注释/取消注释以Cache
/Expires
关键字开头的行,但仍使模块标签保持注释状态。我该如何注释/取消注释,这样开始和结束标记之间的每一行都可以通过单个命令注释/取消注释。
这是示例缓存配置。
#<IfModule mod_cache.c>
#
#<IfModule mod_disk_cache.c>
# CacheRoot "/var/cache/mod_proxy"
# CacheEnable disk
# CacheEnable disk
# CacheEnable disk
# CacheIgnoreCacheControl On
# CacheDirLevels 1
#</IfModule>
#
#</IfModule>
#<IfModule mod_expires.c>
# Header set Cache-Control "max-age=604800, public"
# ExpiresActive On
# ExpiresDefault "access plus 1 week"
# ExpiresByType text/cache-manifest "access plus 0 seconds"
# ExpiresByType text/html "access plus 1 year"
# ExpiresByType text/xml "access plus 0 seconds"
# ExpiresByType application/xml "access plus 0 seconds"
# ExpiresByType application/json "access plus 0 seconds"
# ExpiresByType application/rss+xml "access plus 1 hour"
# ExpiresByType application/atom+xml "access plus 1 hour"
# ExpiresByType image/x-icon "access plus 1 week"
# ExpiresByType image/gif "access plus 1 month"
# ExpiresByType image/png "access plus 1 month"
# ExpiresByType image/jpg "access plus 1 month"
# ExpiresByType image/jpeg "access plus 1 month"
# ExpiresByType video/ogg "access plus 1 month"
# ExpiresByType audio/ogg "access plus 1 month"
# ExpiresByType video/mp4 "access plus 1 month"
# ExpiresByType video/webm "access plus 1 month"
# ExpiresByType application/x-font-ttf "access plus 1 month"
# ExpiresByType font/opentype "access plus 1 month"
# ExpiresByType application/x-font-woff "access plus 1 month"
# ExpiresByType image/svg+xml "access plus 1 month"
# ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
# ExpiresByType text/css "access plus 1 year"
# ExpiresByType application/javascript "access plus 1 year"
#</IfModule>
所以我想有一个命令,可以注释标记开始之间的每一行,<IfModule mod_cache.c>
直到它关闭为止,所以去了<IfModule mod_expires.c>
。
试试这个,
在脚本中包含以下内容以注释或取消注释该模块
if [ "$2" == uncomment ]; then
sed -i "/<IfModule $1>/,/<\/IfModule>/ s/^#//" apache.conf
elif [ "$2" == comment ]; then
sed -i "/<IfModule $1>/,/<\/IfModule>/ s/^\(<\| \)/#\1/" apache.conf
fi
运行脚本的语法:
sh script.sh <moduleName> <comment/uncomment>
例子:
sh script.sh mod_disk_cache.c uncomment
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句