前端之家收集整理的这篇文章主要介绍了
shell demo analyse------ 2,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
shell demo 小例子
这些shell小程序都是自己上网找的一些和自己平时写的一点,和大家分享一下
- 我起的名字是createShell,可以加到/bin路径下,以后在写shell脚本时直接使用可以生成一些注释信息
#!/bin/bash
if [ -z "${1}" ];then
mtime="`date +%T| sed 's/\:/\-/g'`"
newfile="${mtime}.sh"
else
newfile="${1}.sh"
fi
if ! grep "^#!" ${newfile} &> /dev/null;then
cat >> ${newfile} <<EOF
#!/bin/bash
EOF
fi
vim +6 ${newfile}
#!/bin/bash
read -p "C NETWORK: " MYNET
PINGNET=`echo ${MYNET} | sed 's/\([0-9.]*\)\.[0-9]*/\1/g' `
let I=1
while [ ${I} -le 254 ]
do
ping -c1 -W1 ${PINGNET}.${I} &> /dev/null
[ $? -eq 0 ] && echo "${PINGNET}.${I} online :)" || echo "${PINGNET}.${I} offline :("
let I++
done
#!/bin/bash
for i in "$@"
do
[ -z ${i} ] && echo "${i} is zero " && continue
COUNT=$(cat ${i} | grep -i "^$" | wc -l)
echo "${i} 空格行为 ${COUNT}"
done
#!/bin/bash
for i in `ls`
do
[ -f ${i} ] && [ ${i}=~.*\.sh ] && chmod a+x ${i} && echo " ${i} add author ok" || echo "file error"
done
#!/bin/bash
read -p "please input save dir : " saveDir
mkdir ${saveDir}
for i in `ls`
do
[ -f ${i} ] && `mv ${i} ./${saveDir}/`
done
let count=$(ls ./${saveDir}/ | wc -l)
if [ ${count} -eq 0 ];then
echo "no file to move" && `rm -rf ${saveDir}`
fi
#!/bin/sh
clear
echo -e "\033[31m---------------------------1.date-----------------------------------"
date
echo -e "\033[31m---------------------------2.updatime-------------------------------"
uptime
echo -e "\033[31m---------------------------3.Last Logins(5)--------------------------"
last -ai | head -5
echo -e "\033[31m---------------------------4.disk------------------------------------"
df -h | grep "[\/]dev[\/]" | xargs | awk '{print "Free/total: " $4"/"$2" "$1}'
echo -e "\033[31m---------------------------5.memory----------------------------------"
free -mh | grep "Mem" | xargs | awk '{ print "Free/Total: " $4 "/" $2 }'
echo -e "\033[31m---------------------------6.most expensive Processes----------------"
top -b | head -10 | grep "^[\ ]"
echo -e "\033[31m---------------------------7.vmstat-----------------------------------"
vmstat 2 5 | grep "^[\ ]"
echo -e "\033[39m"