標籤:linux常用命令 linux高頻率命令 linux高頻率shell指令碼 linux常用指令碼
以下是在部署OpenStack過程中摘錄的一些較為常用的命令列或shell指令碼,僅供參考。
1.殺死所有存在的殭屍進程
ps -ef | grep defunc | grep -v grep | awk ‘{print $3}‘ | xargs kill -9#pkill dnsmasq
2.去掉設定檔中的#符號和空白行
cat >/root/delsc.sh <<eof#!/bin/bash# delete all spaces and comments of specialized file, using with filename[[ "\$1" == ‘‘ ]] && echo "delete all spaces and comments of specialized file, using with \[email protected] filename" && exit 1grep -v \# \$1 | grep -v ^$eofcat /root/delsc.shchmod +x /root/delsc.shln -s /root/delsc.sh /usr/local/bin/delsc
3.CentOS7安裝vmtools
# mount /dev/cdrom /mnt/# cp /mnt/VMwareTools-9.4.10-2092844.tar.gz /tmp/# cd /tmp/# tar zxf VMwareTools-9.4.10-2092844.tar.gz# /tmp/vmware-tools-distrib/vmware-install.plyum install open-vm-tools -ysystemctl enable vmtoolsd.servicesystemctl start vmtoolsd.servicesystemctl status vmtoolsd.service
4.修改Linux系統時區
mv /etc/localtime /etc/localtime~ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtimechown -h --reference=/etc/localtime~ /etc/localtimechcon -h --reference=/etc/localtime~ /etc/localtime
5.中國大陸常用時間伺服器列表
cat > /etc/ntp.conf <<eofserver 2.cn.pool.ntp.org iburstserver 3.asia.pool.ntp.org iburstserver 0.asia.pool.ntp.org iburstrestrict -4 default kod notrap nomodifyrestrict -6 default kod notrap nomodifyeof
6.配置時間同步
rpm -qa | grep ntp || yum install -y ntpntpdate -u pool.ntp.org || ntpdate -u time.nist.gov || ntpdate -u time-nw.nist.govdatecat >>/etc/rc.local<<EOFntpdate -u pool.ntp.org || ntpdate -u time.nist.gov || ntpdate -u time-nw.nist.govhwclock -wEOF# Recommoned dotouch /etc/cron.daily/ntpdatecat >>/etc/cron.daily/ntpdate<<EOFntpdate -u pool.ntp.org || ntpdate -u time.nist.gov || ntpdate -u time-nw.nist.govhwclock -wEOF
7.對設定檔更改前先備份設定檔
operationfile=/etc/keystone/keystone.confbakoperationfile=$operationfile$(date +-%F-%H-%M-%S)"~"cp $operationfile $bakoperationfilechown -R --reference=$operationfile $bakoperationfilechcon -R --reference=$operationfile $bakoperationfile
8.建立計劃任務
(crontab -l -u keystone 2>&1 | grep -q token_flush) || echo ‘@hourly /usr/bin/keystone-manage token_flush >/var/log/keystone/keystone-tokenflush.log 2>&1‘ >> /var/spool/cron/keystone
9.不切換使用者但以此使用者的身份執行命令
su -s /bin/sh -c "glance-manage db_sync" glance
10.擷取路由IP
ip=$(ifconfig `route | grep default | awk ‘{print $8}‘` | grep inet | grep -v inet6 | awk ‘{print $2}‘)
11.判斷CPU是否支援虛擬化
if [[ $(egrep -c ‘(vmx|svm)‘ /proc/cpuinfo) == 0 ]];thendefaultnum=`grep -n "^\[libvirt\]$" $operationfile | awk -F ‘:‘ ‘{print $1}‘`sedoperation=$defaultnum"a"sed -i "$sedoperation virt_type = qemu" $operationfileelsedefaultnum=`grep -n "^\[libvirt\]$" $operationfile | awk -F ‘:‘ ‘{print $1}‘`sedoperation=$defaultnum"a"sed -i "$sedoperation virt_type = kvm" $operationfilefi
12.擷取指定網卡名所對應的IP地址
ext_ens=ens160local_ip=$(ifconfig `route | grep $ext_ens | awk ‘{print $8}‘` | grep inet | grep -v inet6 | awk ‘{print $2}‘)
end
本文出自 “通訊,我的最愛” 部落格,請務必保留此出處http://dgd2010.blog.51cto.com/1539422/1584952
12個Linux系統高頻率命令列和shell小指令碼