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