1. 程式人生 > >簡單的Shell指令碼

簡單的Shell指令碼

#! /bin/bash xzh=“/1/2/3/4” if [ ! -e $xzh ] then mkdir -p $xzh fi

#!/bin/bash read -p “please set file:” n if[ ! -e $n ] then touch $n fi

#!/bin/bash n=cat iplist for IP in $n do ping -c 3 -i 0.2 -w 3 $IP &> /dev/null if [ $? -eq 0 ] ; then echo “Host $IP is on-line.” else echo “Host $IP is off-line.” fi done

#!/bin/bash read -p “please set directory:” n if [ ! -e $n ] then mkdir -p $n else echo “this $n directory exist” fi

read -p “Enter your score (0-100) : " GRADE if [ $GRADE -ge 85 ] && [ GRADEle100];thenecho"GRADE -le 100 ] ; then echo "GRADE is Excellent” elif [ $GRADE -ge 70 ] && [ G

RADEle84];thenecho"GRADE -le 84 ] ; then echo "GRADE is Pass" elif [ $GRADE -gt 100 ] || [ GRADElt0];thenecho"GRADE -lt 0 ] ; then echo "GRADE is does not exist" else echo “$GRADE is FAil” fi

#!/bin/bash read -p " Enter a name : " n if [ -e $n ] && [ -d n

];thenecho"n ] ; then echo "n is directory" elif [ -e $n ] && [ -f n];thenecho"n ] ; then echo "n is file" else echo “$n is does not exist” fi

#!/bin/bash read -p “Enter The Users Password : " n for u in cat forlist do id $u &> /dev/null if [ $? -eq 0 ] then echo “Already exists” else useradd $u >/dev/nullecho"> /dev/null echo "N” | passwd --stdin $u &> /dev/null if [ ?eq0]thenecho"? -eq 0 ] then echo "u ,Create success" else echo “$u ,Create failure” fi fi done