收藏文章 楼主

echo-写入与交互界面-linux

版块:KVM虚拟化   类型:精华/置顶   作者:小绿叶技术博客   查看:4165   回复:0   获赞:2   时间:2019-03-18 15:31:32

#!/bin/bash

# date:2019-03-19

#Author:GuoRi

a=`ifconfig |grep -w inet|awk 'NR==1{print$2}'`

b=hostname

echo "$a $b" >> /etc/hosts



--------------------赛选出本机IP------------

ifconfig |grep -w inet|awk 'NR==1{print$2}'

赛选出本机IP


ifconfig |grep -w inet

完全匹配inet的信息


|awk '{print$2}'

过滤2列


'NR==1

选择第一个IP

---------------------------------------------------------

a=`ifconfig |grep -w inet|awk 'NR==1{print$2}'`

给a赋值:本机IP


echo "$a"

打印a


echo "$a $b" >> /etc/hosts

将a和b的值写入文件

---------------------------------------------------------------


sed -i '7s/enforcing/disabled/g' /etc/selinux/config

替换第7行代码


/enforcing/disabled/

被替换与替换的字符


------------------------------------------

  -e多重匹配

sed -i -e '7s/disabled/enforcing/g' -e  /etc/selinux/config ''


^ 行首


timedatectl list-timezones|grep shang

设置时区位上海


sed -i '8s/^/server controllwe iburst/g' /etc/con



=================================================

-------------------------完整代码-------------

#!/bin/bash

# date:2019-03-19

#Author:GuoRui


#配置域名映射

echo "配置域名映射"

a=`ifconfig |grep -w inet|awk 'NR==1{print$2}'`

b=`hostname`

echo "$a $b" >> /etc/hosts



sed -i '7s/enforcing/disabled/g' /etc/selinux/config


iptables -F

iptables -X

iptables -Z

/usr/sbin/iptables-save


yum install -y chronyd


systemctl restart chronyd

systemctl enable chronyd

chronyc sources

=======================echo交互界面==修改数据库密码========================


#!/bin/bash

(

echo "000000"

eleep 3

echo "y"

seleep 10

echo "123456"

seleep 3

echo "123456"

seleep 3

echo "y"

seleep 3

echo "n"

seleep 3

echo "y"

seleep 3

echo "y"

seleep 3

)|mysql_secure_installation


seleep 3===>代表上一条命令成功后等待3秒后执行下一条命令

提供企业建站服务,免费网防系统,提交信息登录 http://yundun.ddoss.cn 邮箱: proposal@ddoss.cn 
回复列表
默认   热门   正序   倒序

回复:echo-写入与交互界面-linux

头像

用户名:

粉丝数:

签名:

资料 关注 好友 消息