An example of application of sed command and Shell's if statement

Source: Internet
Author: User
Tags syslog

if [-f/etc/syslog.conf]; #判断文件是否存在
Then
systest= ' sed-n '/^auth.info/p '/etc/syslog.conf '; #匹配 the/etc/syslog.conf file has a auto.info string and returns a string, Systest variable is received.
if [-n \ "\ $systest \"]; #判断字符串是否存在
Then
Sed-e ' s/^auth.info.*/auth.info \\/var\\/adm\\/authlog/g '/etc/syslog.conf > config.tmp && mv config.tm  p/etc/syslog.conf; #存在则替换
Else
awk ' {print \$0} end{print \ "Auth.info/var/adm/authlog\"} '/etc/syslog.conf > config.tmp && mv config.t mp/etc/syslog.conf; #不存在则在最后一行添加, used when Sed-i is not supported under the Solaris system.

Sed-i ' \ $a auth.infos/var/adm/authlogs '/etc/syslog.conf; #不存在则在最后一行添加. Redhat,suse
Fi #第一个内层判断结束
Syserr= ' sed-n '/^*.err;auth.info/p '/etc/syslog.conf ';
if [-n \ "\ $syserr \"];
Then
Sed-e ' s/^*.err;auth.info.*/*.err;auth.info \@${loghost}/g '/etc/syslog.conf > config.tmp && mv Config. tmp/etc/syslog.conf;
Else
awk ' {print \$0} end{print \ "*.err;auth.info \@${loghost}\"} '/etc/syslog.conf > config.tmp && mv Config . tmp/etc/syslog.conf;
Fi #第二个内层判断结束
Fi
if [-f/var/adm/authlog];
Then
echo \ "\/var\/adm\/authlog exist.\";
Else
Touch/var/adm/authlog; #创建文件
Chown Root:system/var/adm/authlog; #赋权
chmod 600/var/adm/authlog; #赋权
echo \ "Create file/var/adm/authlog.\";
fi; ";

An example of application of sed command and Shell's if statement

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.