Linux学习笔记十八:一些常见的脚本
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Linux学习笔记十八:一些常见的脚本,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2481字,纯文字阅读大概需要4分钟。
内容图文
备份命令
#!/bin/bash
if [ ! -d /data/back/bin ];then
mkdir -p /data/backup/bin
fi
if [ ! -d /data/backup/usr/bin ];then
mkdir -p /data/backup/usr/bin
fi
if [ ! -d /data/backup/lib64 ];then
mkdir -p /data/backup/lib64
fi
if [ ! -d /data/backup/lib ];then
mkdir -p /data/backup/lib
fi
while true;do
read -p "请输入一个可执行命令:" CMD
if [[ $CMD =~ ^q$ ]];then
break
elif [[ $CMD =~ ^/bin/.*$ ]];then
cp -f $CMD /data/backup/bin
LIB_DIR=`ldd $CMD|sed -nr 's/.*((\/.*\/)[^/]+) .*/\2/p'|head -n1`
for file in `ldd $CMD|sed -nr 's/.*((\/.*\/)[^/]+) .*/\1/p'`;do cp -f $file /data/backup$LIB_DIR;done
elif [[ $CMD =~ ^/usr/bin/.*$ ]];then
cp -f $CMD /data/backup/usr/bin
LIB_DIR=`ldd $CMD|sed -nr 's/.*((\/.*\/)[^/]+) .*/\2/p'|head -n1`
for file in `ldd $CMD|sed -nr 's/.*((\/.*\/)[^/]+) .*/\1/p'`;do cp -f $file /data/backup$LIB_DIR;done
fi
done
创建文件
#!/bin/bash
*******************************************************************
if [ ! -d /testdir/ ];then
mkdir /testdir
cd /testdir
for ((i=0;i<10;i++));do
touch $i`head -c 100 /dev/random |base64|grep -o "[[:alpha:]]"|head -n8|tr -d "\n"`.html
done
else
cd /testdir
for ((i=0;i<10;i++));do
touch $i`head -c 100 /dev/random |base64|grep -o "[[:alpha:]]"|head -n8|tr -d "\n"`.html
done
fi
获取模块网卡IP地址
#!/bin/bash
. functions
if [ $# -eq 0 ];then
echo "Usage: $0 NIC_NAME ..."
fi
get_ip $*
开启、关闭、重启服务
#!/bin/bash
. functions
echo "please input your action: [1-5]"
select action in "start" "stop" "status" "restart" "quit";do
case $action in
start) $action;;
stop) $action;;
restart) $action;;
status) $action;;
quit) exit;;
*) echo "请输入[1-5]"
continue;;
esac
done
画杨辉小星星三角形
#!/bin/bash
BEGIN="\e[1;5"
END="\e[0m"
read -p "input lines: " LINE
#if [ -n $LINE ];then
#LINE=7
#fi
for i in `seq $LINE`;do
j=1
k=1
while [ $k -le $[$LINE-$i] ];do
echo -e " \c"
let k+=1
done
k=1
while [ $j -le $i ];do
COLOR=$((RANDOM%7+31))
echo -e "$BEGIN;${COLOR}m* $END\c"
let j+=1
done
echo
done
查看一个网络所有up的主机
#!/bin/bash
for i in 172.22.{0..254}.{1..254};do
(ping -c1 -W1 $i &> /dev/null && echo $i is up || echo $i is down |grep -o "up" &) >> ./uphost.txt
done
打印一个99乘法表
#!/bin/bash
BEGIN="\e[1;"
END="\e[0m"
for i in `seq 9`;do
j=1
while [ $j -le $i ];do
COLOR=$((RANDOM%7+31))
echo -e "${BEGIN};${COLOR}m${j}x${i}=$[i*j]$END\t\c"
let j+=1
done
echo
done
检查服务启动状态
#!/bin/bash
. functions
. /etc/init.d/functions
service_status $*
#action $res true
检查系统的版本
#!/bin/bash
. functions
sys_ver
echo $?
有些直接调用了上篇functions函数了。。。
内容总结
以上是互联网集市为您收集整理的Linux学习笔记十八:一些常见的脚本全部内容,希望文章能够帮你解决Linux学习笔记十八:一些常见的脚本所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。