#!/bin/bash #description: useradd for i in `seq -f"%02g" 1 20`;do useradd user$i echo "user$i-`echo $RANDOM|md5sum|cut -c 1-5`"|passwd –stdinuser$i >/dev/null 2>&1 done
#!/bin/bash for ip in `seq 1 255` do { ping -c 1 192.168.1.$ip > /dev/null 2>&1 if [ $? -eq 0 ]; then echo 192.168.1.$ip UP else echo 192.168.1.$ip DOWN fi }& done wait
[root@localhost tmp]# cat checksh.sh #!/bin/bash read -p "please input check script-> " file if [ -f $file ]; then sh -n $file > /dev/null 2>&1 if [ $? -ne 0 ]; then read -p "You input $file syntax error,[Type q to exit or Type vim to edit]" answer case $answer in q | Q) exit 0 ;; vim ) vim $file ;; *) exit 0 ;; esac fi else echo "$file not exist" exit 1 fi
1、创建一个函数,能接受两个参数:
1)第一个参数为URL,即可下载的文件;第二个参数为目录,即下载后保存的位置;
2)如果用户给的目录不存在,则提示用户是否创建;如果创建就继续执行,否则,函数返回一个51的错误值给调用脚本;
3)如果给的目录存在,则下载文件;下载命令执行结束后测试文件下载成功与否;如果成功,则返回0给调用脚本,否则,返回52给调用脚本;
[root@localhost tmp]# cat downfile.sh #!/bin/bash url=$1 dir=$2 download() { cd $dir >> /dev/null 2>&1 if [ $? -ne 0 ];then read -p "$dir No such file or directory,create?(y/n)" answer if [ "$answer" == "y" ];then mkdir -p $dir cd $dir wget $url 1> /dev/null 2>&1 else return "51" fi fi if [ $? -ne 0 ]; then return "52" fi } download $url $dir echo $?