修改主机名/添加用户名和密码/挂载目录等多功能脚本

该脚本的主要目的就是:修改主机名,添加用户名和密码并且挂载目录的脚本。

#!/bin/bash

#Add the hostname
read -p  "Please input your hostname:" Hostname
hostname $Hostname 【必须得添加,如果不添加的话,我们的主机头就不会修改,

old=`cat /etc/sysconfig/network | grep HOSTNAME | awk -F= '{print $2}'`
sed -i "s/$old/$Hostname/g"  /etc/sysconfig/network

echo "The /etc/sysconfig/network has changed,please check:"
echo "========================================="
cat /etc/sysconfig/network
echo "========================================="

ADDR=`ifconfig | grep Bcast | awk '{print $2}' | awk -F: '{print $2}'`
Hostn=`echo $Hostname|awk -F. '{print $1}'`
flage=`grep $ADDR /etc/hosts`
if [ -n "$flage" ];then
 sed -i "/^$ADDR/d" /etc/hosts
echo "$ADDR          $Hostname  $Hostn" >> /etc/hosts
fi                                                               判断语句,主要是为了在/etc/rc.local中重复添加mount语句同时应该注意判断语句用的精妙之处,可参考我的博客】      

echo "                                  "
echo "Hostname has added to /ec/hosts,please check:"
cat /etc/hosts
echo "                                  "


#start the portmap service
service portmap start
chkconfig --level 2345 cups on 
【开启端口映射】

cd
mkdir -p /nfs
mount -t nfs 192.168.55.233:/opt/nfs /nfs
echo "Please check the mount point whether or not added to /nfs:"
df -h
echo "******************************************"
flag=`grep mount /etc/rc.local`
if [ -n "$flag" ];then
 sed -i '/^mount/d' /etc/rc.local
fi                                                               
【判断语句,主要是为了在/etc/rc.local中重复添加mount语句,同时应该注意判断语句用的精妙之处,可参考我的博客

echo "mount -t nfs 192.168.55.233:/opt/nfs /nfs" >> /etc/rc.local
echo "We have added the mount point to /etc/rc.local,please check:"
cat /etc/rc.local
echo "******************************************"

#This shell is to add a user and its password!
echo "Now we'll add the user oracle and its password! "
useradd oracle
echo "                                  "
echo 99billadmin | passwd --stdin oracle
cat /etc/passwd | grep oracle
【在shell脚本中添加用户名密码】

echo "                                  "
echo "You have successfully added the user oracle and its password!"

测试结果如下:

 

退出重新登录,显示结果为:

 注意:

主机名设置完成后应重启系统,没有条件重启系统应重启重要服务,如 apache,snmp,ntp 等。

 


 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值