Linux下常用的shell操作

系统基本设置

#!/bin/bash
# 加载环境变量
source /etc/profile

# 设定信号捕获,防止运行中键盘触碰导致脚本运行异常;
trap "echo 'Sorry,I hava trapped Ctrl-c!'" SIGINT
trap "echo 'Sorry,I hava trapped Ctrl-z!'" SIGSTOP
trap "echo 'Sorry,I hava trapped Ctrl-d!'" SIGCONT

# 卸载防火墙
rpm -qa | grep "firewall" | xargs rpm -e --nodeps
firewall_uninstall=$?

rpm -qa | grep "iptables" | xargs rpm -e --nodeps
iptables_uninstall=$?

if [ "$firewall_uninstall" -eq 0 -a "$iptables_uninstall" -eq 0 ]
  then
    echo -e "33[32mfirewall33m uninstall success!"
  else
    echo -e "33[32mfirewall33[0m uninstall failed!"
fi

# 关闭ssh的反向解析
sed -i 's/.*UseDNS.*/UseDNS no/' /etc/ssh/sshd_config

# 关闭selinux安全上下文
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config

# 设定hosts解析记录
echo "$(ifconfig ens192 | awk '/<inet>/{print $2}') $(hostname)" >> /etc/hosts
原文地址:https://www.cnblogs.com/guge-94/p/10481721.html