标签:touch ssl 如何 case 数列 you style lin 返回
用for实现脚本read -p "pleasr input directory: " DIS
for F inls $DIS
;do
TY=file $DIS/$F | egrep -o "link|text|block|directory"
case $TY in
text)
echo "file $DIS/$F is file"
;;
link)
echo "file $DIS/$F is Link"
;;
block)
echo "file $DIS/$F is Block"
;;
directory)
echo "file $DIS/$F is Directory"
;;
*)
echo "file $DIS/$F is Others"
esac;
done
取随机8位字符的方法
openssl rand 4 -base64
tr -dc ‘0-7‘ </dev/urandom |head -c8for USER in user{1..10};do
useradd $USER
echoopenssl rand 4 -base64
| passwd --stdin $USER &>/dev/null
echo $USER created successful;
done
for F in
ls /etc/rc.d/rc3.d/ | egrep ‘^K|^S‘
;do
S=echo $F | egrep -o ‘^K|^S‘
if [ "$S" = "K" ];then
echo $F stop
else
echo $F start
fi;
done
或者
for i inls /data/
;do
[[ "$i" =~ ^k. ]] && echo "$i stop"
[[ "$i" =~ ^s. ]] && echo "$i start"
done
read -p ‘please input digit: ‘ D
[ $D -gt 0 ] || echo "please input digit"
sum=0
for i inseq $D
;do
let sum+=$i;
done
echo $sum
sum=0
for i in {3..100..3};do
let sum+=$i
done
echo $sum
或者
for i in {1..100};do
if [ $[ $i%3 ] -eq 0 ];then
let sum+=i
fi
done
echo "sum is $sum"
read -p "please input network: " NET
SH=echo $NET | sed -rn ‘s/(.*\.)(.*)\.(.*)/\1/p‘
for i in {0..255};do
for j in {1..254};do
{ ping -c1 -W1 ${SH}${i}.${j} &>/dev/null && echo ${SH}${i}.${j} is up; }&
done
wait
done
echo "scan host is finished"
echo "******************九九乘法表******************"
for i in {1..9};do
for j in {1..9};do
echo -e "$j$i=`echo $j$i | bc` \c"
if [ $i -eq $j ];then
echo ""
break
fi
done
done
for (( i=1;i<=10;i++ ));do
RAN=tr -dc ‘[:alpha:]‘ </dev/urandom | head -c8
touch /testdir/${i}${RAN}.html -p
done
echo "Ten file mkdir successful."
read -p "please input triangle line: " line
for ((j=1;j<=$line;j++));do
COL_LOG=‘\e[1;5;‘
COL_AND=‘\e[0m‘
for ((a=1;a<=line-j;a++));do
echo -e " \c"
done
sum=echo 2*$j-1|bc
for ((i=1;i<=${sum};i++));do
RAND="$[$RANDOM%7+31]m"
echo -e "${COL_LOG}${RAND}* \c"
done
echo -e "${COL_AND}"
done
sum=1
for ((n=1;n<10;n++));do
sum=$[2*$[$sum+1]]
done
echo "所摘桃子数: $sum"
sum=0
i=1
while [ $i -le 100 ];do
echo -e "$i \c"
sum=$[${sum}+${i}]
i=$[$i+2]
done
echo
echo "100以内所有正奇数之和为:$sum"
read -p "please input new(eg:192.168.0.0): " net
netid=echo $net|cut -d. -f1-2
i=0
up=0
down=0
while [ $i -le 254 ];do
j=1
while [ $j -le 254 ];do
if ping -c1 -w1 $netid.$i.$j &>/dev/null;then
echo "the $netid.$i.$j is up"
let up++
else
echo "the $netid.$i.$j is down"
let down++
fi
let j++
done
let i++
done
echo "the up is $up"
echo "the down is $down"
i=1
while [ "$i" -le "9" ];do
j=1
while [ "$j" -le "$i" ];do
echo -e "$j$i=`echo $i$j|bc` \c"
let j++
done
echo ""
let i++
done
i=1
while true;do
NUM=$RANDOM
if [ "$i" -eq "1" ];then
MAX=$NUM
MIN=$NUM
else
if [ "$MAX" -lt "${num[$i]}" ];then
MAX=${num[$i]}
elif [ "$MIN" -gt "${num[$i]}" ];then
MIN=${num[$i]}
else
true
fi
fi
let i++
done
echo "num is : ${num[@]}"
echo "最大值MAX:$MAX 最小值MIN:$MIN"
i=1
D_COLOR=‘\033[1;41m‘
S_COLOR=‘\033[1;47m‘
AND_COLOR=‘\033[0m‘
while [ $i -le 8 ];do
if [ "$[$i%2]" -eq "0" ];then
j=1
while [ $j -le 8 ];do
if [ "$[$j%2]" -eq "0" ];then
echo -e "${S_COLOR} ${AND_COLOR}\c"
else
echo -e "${D_COLOR} ${AND_COLOR}\c"
fi
let j++
done
else
j=1
while [ $j -le 8 ];do
if [ "$[$j%2]" -eq "0" ];then
echo -e "${D_COLOR} ${AND_COLOR}\c"
else
echo -e "${S_COLOR} ${AND_COLOR}\c"
fi
let j++
done
fi
echo ""
let i++
done
RAN=1
cat test.txt | while read CHESS;do
{ while true;do
MD=echo $RAN|md5sum|cut -c1-10
if [[ "$MD" == "$CHESS" ]];then
echo $RAN
break
else
let RAN++
fi
done }&
wait
done
until false;do
if who |grep "^hacker>" &> /dev/null;then
who|grep "^hacker>" > /var/log/login.log
break
fi
sleep 3
done
n=$[$RANDOM%11]
time=1
while read -p "input a 0-10 number : " num ;do
if [ $num -gt $n ];then
echo "$num is greater"
elif [ $num -lt $n ];then
echo "$num is lower"
else
echo "guess right!"
break
fi
done
sum=0
while [ $# -gt 0 ];do
lines=cat $1|wc -l
shift
sum=$[$sum+$lines]
done
echo $sum
max=$1
min=$1
while [ $# -gt 0 ];do
if [ $1 -lt $min ];then
min=$1
fi
if [ $1 -gt $max ];then
max=$1
fi
shift
done
echo "maxnum is $max"
echo "minnum is $min"
os () {
if [sed -r "s@.*([0-9]+)\..*@\1@"
/etc/centos-release` -eq 6 ];then
echo "os is 6"
else
echo "os is 7."
fi
}
os
eth0ip () {
ip=ifconfig eth0|grep netmask|tr -s ‘ ‘|cut -d ‘ ‘ -f3
echo ip=$ip
}
eth0ip
redgreen(){
echo -e "\033[1;32mOK\033[0m"
echo -e "\033[1;31mFAILD\033[0m"
}
redgreen
args(){
if [ $# -eq 0 ];then
echo "please give a parameter!"
fi
}
args $1
(1) 脚本可接受参数: start, stop, restart, status
(2) 如果参数非此四者之一,提示使用格式后报错退出
(3) 如是start:则创建/var/lock/subsys/SCRIPT_NAME, 并显示“启动成功” 考虑:如果事先已经启动过一次,该如何处理?
(4) 如是stop:则删除/var/lock/subsys/SCRIPT_NAME, 并显示“停止完成” 考虑:如果事先已然停止过了,该如何处理?
(5) 如是restart,则先stop, 再start 考虑:如果本来没有start,如何处理?
(6) 如是status, 则如果/var/lock/subsys/SCRIPT_NAME文件存在,则显示“SCRIPT_NAME is running...” ,如果/var/lock/subsys/SCRIPT_NAME文件不存在,则显示“SCRIPT_NAME is stopped...”
(7)在所有模式下禁止启动该服务,可用chkconfig 和 service命令管理 说明: SCRIPT_NAME为当前脚本名
#!/bin/sh
#chkconfig:- 96 07
#description
[ -f /etc/rc.d/init.d/basename $0
]||mv /app/script/basename $0
/etc/rc.d/init.d/basename $0
&>/dev/null
chkconfig --addbasename $0
start () {
touch /var/lock/subsys/basename $0
. /etc/init.d/functions
action "basename $0
start successful!" true
}
stop () {
rm /var/lock/subsys/basename $0
. /etc/init.d/functions
action "basename $0
is stopped" true
}
restart () {
stop
start
}
status () {
if [ -f /var/lock/subsys/basename $0
];then
. /etc/init.d/functions
action "basename $0
is running" true
else
action "basename $0
is stopped" true
fi
}
case $1 in
start)
if [ -f /var/lock/subsys/basename $0
];then
echo "basename $0
is running"
else
start
fi
;;
stop)
if [ -f /var/lock/subsys/basename $0
];then
stop
else
echo "basename $0
has been stopped before"
Fi
;;
restart)
if [ -f /var/lock/subsys/basename $0
];then
stop
start
else
start
fi
;;
status)
status
;;
esac
(1) 提示用户输入一个可执行命令名称
(2) 获取此命令所依赖到的所有库文件列表
(3) 复制命令至某目标目录(例如/mnt/sysroot)下的对应路径下
如: /bin/bash ==> /mnt/sysroot/bin/bash /usr/bin/passwd ==>/mnt/sysroot/usr/bin/passwd
(4) 复制此命令依赖到的所有库文件至目标目录下的对应路径下: 如: /lib64/ldlinux-x86-64.so.2 ==> /mnt/sysroot/lib64/ld-linux-x86-64.so.2
(5)每次复制完成一个命令后,不要退出,而是提示用户键入新的要复制的命令, 并重复完成上述功能;直到用户输入quit退出
#!/bin/sh
while read -p "please input a COMMND : " command ;do
if [[ "$command" =~ [Qq][Uu][Ii][Tt] ]];then
break
elif [ -z "$command" ];then
echo "empty is not allowed."
continue
else
dir=which $command 2> /dev/null
if [ -z $dir ];then
echo "command is not exit."
continue
else
echo "command in the directory of $dir."
ldd $dir &> /dev/null
lib=ldd $dir |grep -Eo "/lib64/.*"|sed -r ‘s#(.*)\(.*\)#\1#‘
fi
cpall(){
mkdir -p /mnt/sysrootdirname $dir
mkdir -p /mnt/sysroot/lib64
cp -a $dir /mnt/sysroot$dir && echo ""$command" has been copied."
cp -a $lib /mnt/sysroot/lib64 && echo ""$command" lib has been copied."
}
cpall
fi
done
#!/bin/sh
max() {
if [ $# -ne 2 ];then
echo "please enter two digits"
exit 1
else
if [[ $1 =~ ^-?[0-9]+$ ]] && [[ $2 =~ ^-?[0-9]+$ ]];then
if [ $1 -gt $2 ];then
echo $1
else
echo $2
fi
else
echo "please enter integer"
exit 2
fi
fi
}
max $1 $2
fibonacci(){
if [ $1 -eq 0 ];then
echo 0
elif [ $1 -le 1 ];then
echo 1
else
echo $[$(fibonacci $[$1-1])+$(fibonacci $[$1-2])]
fi
}
fibonacci $1
#!/bin/sh
step=0
move (){
let step++
echo "$step: move disk $1 $2 -----> $3"
}
hanoi(){
if [ $1 -eq 1 ];then
move $1 $2 $4
else
hanoi "$[$1-1]" $2 $4 $3
move $1 $2 $4
hanoi "$[$1-1]" $3 $2 $4
fi
}
read -p "please input the number of plates: " number
hanoi $number A B C
#!/bin/sh
declare -a rand
declare -i sub=
echo "Please input the numbers you want to sort:"
read -a rand
for ((i=0;i<${#rand[]}-1;i++));do
for ((j=0;j<${#rand[]}-i-1;j++));do
if [ ${rand[$j]} -gt ${rand[$j+1]} ];then
sub=${rand[$j+1]}
rand[$j+1]=${rand[$j]}
rand[$j]=$sub
fi
done
done
echo "The numbers have been sorted:${rand[*]}"
1 2 3 | 1 4 7 | |
---|---|---|
4 5 6 | ===> | 2 5 8 |
7 8 9 | 3 6 9 |
#!/bin/sh
arr=([00]=1 [01]=2 [02]=3 [10]=4 [11]=5 [12]=6 [20]=7 [21]=8 [22]=9)
size=3
showmatrix () {
for ((i=0;i<size;i++));do
for ((j=0;j<size;j++));do
echo -e "${arr[$i$j]} \c"
done
echo
done
}
echo "Before convert"
showmatrix
for ((i=0;i<size;i++));do
for ((j=i;j<size;j++));do
if [ $i -ne $j ];then
temp=${arr[$i$j]}
arr[$i$j]=${arr[$j$i]}
arr[$j$i]=$temp
fi
done
done
echo "After convert"
showmatrix
#!/bin/sh
read -p "输入高度" g #g是最高行
declare -a a
for i inseq $g
;do #$i是当前行
if [ $i -eq 1 ];then
for o inseq $[$g-$i]
;do
echo -n " "
done
a[1]=1
echo "1"
continue
fi
for j inseq $i
;do #j表示当前行的第几个数字
if [ $j -eq 1 ];then
for o inseq $[$g-$i]
;do
echo -n " "
done
echo -n "1"
a[$i$j]=1
elif [ $j -eq $i ];then
echo -n " 1"
a[$i$j]=1
else
let a[$i$j]=${a[$[i-1]$[j-1]]}+${a[$[i-1]$[j]]}
echo -n " ${a[$i$j]}"
fi
done
echo
done
标签:touch ssl 如何 case 数列 you style lin 返回
原文地址:https://blog.51cto.com/12980155/2375578