一些脚本_脚本练习

 

#!/bin/bash

read -p "Please type the user you want select :" USER
grep "$USER" /etc/passwd &> /dev/null
if [ $? -eq '0' ];then
SHELL=`grep "^$USER" /etc/passwd |cut -d: -f7 | cut -d'/' -f3`
echo "$USER : $SHELL" 
else
echo "The $USER is unexist!"
fi
read -p "Type 'n|N' fpr continue ,others for quiting:" C
C=`echo $C | tr 'a-z' 'A-Z'`
while [ $C == 'N' ]; do
read -p "Please type the user you want select :" USER
grep "$USER" /etc/passwd &> /dev/null
if [ $? -eq '0' ];then
SHELL=`grep "^$USER" /etc/passwd |cut -d: -f7 | cut -d'/' -f3`
echo "$USER : $SHELL" 
else
echo "The $USER is unexist!"
fi
read -p "Type 'n|N' fpr continue ,others for quiting:" C
C=`echo $C | tr 'a-z' 'A-Z'`
done

 
一些脚本_休闲_02
#!/bin/bash
let NUM=0
while [ $NUM -le 19 ];do
let NUM=$NUM+1
grep "linuxuser$NUM:" /etc/passwd >/dev/null || (useradd linuxuser$NUM && echo "linuxuser$NUM" | passwd --stdin linuxer$NUM)
 
echo "linuxuser$NUM , UID:`grep "linuxuser$NUM:" /etc/passwd | cut -d: -f3`  GID:`grep "linuxuser$NUM:" /etc/passwd | cut -d: -f4`" 
done
 
 
一些脚本_脚本练习_03
#!/bin/bash
read -p "Please input the strat IP and end IP :" START END
let IP=$START 
while [ $IP -le $END ]; do
ping -c2 -w2 192.168.0.$IP &>/dev/null && echo "The host 192.168.0.$IP is up." | tee -a  /tmp/host_state || echo "The host 192.168.0.$IP is down." | tee  -a   /tmp/host_state
let IP+=1
done
sed -i 's@\(^.*[down\.]$\)@#\1@g' /tmp/host_state
 
 

一些脚本_脚本练习_04

#!/bin/bash
#[ ! -d /tmp/net ] && mkdir /tmp/net ; cd /tmp/net || cd /tm#p/net
find /tmp -name net > /dev/null && cd /tmp/net || ( mkdir /tmp/net && cd /tmp/net)
# if `which lftpget &> /dev/null`; then
#MYGET=lftpget
#elif `which wget &> /dev/null`; then
#MYGET=wget
#else
#echo "No download tools."
#exit 6
#fi
lftpget ftp://192.168.0.254/pub/Files/1.txt
#lftp 192.168.0.254/pub/Files
#wget 1.txt
mv 1.txt 1-`date '+%F-%H-%M-%S'`.txt
echo "Download finished."