Shell命令_for



chmod 755 demo.sh
./demo.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/bash
# Author:James 2016-10-15
 
# 集合以空格分割
for  i in 1 2 3 4 5 6
    do
        echo "$i"
    done
 
 

 


#!/bin/bash
# Author:James 2016-10-15
# 批量压缩脚本
 
cd /tmp/shs
#所有sh文件覆盖到sh.log文件
ls *.sh > sh.log
for i in $(cat sh.log)
    do
        #tar -zxf $i &>/dev/null
        echo "File Name is $i"
    done
rm -rf /tmp/shs/sh.log
 

 


 
#!/bin/bash
# Author:James 2016-10-15
# 计算1..100之和
 
sum=0
for(( i=1;i<=100;i++ ))
        do
                #echo "$i"
                sum=$(( $sum+$i ))
        done
echo "sum is:$sum"
 
 
 

 


#!/bin/bash
# Author:James 2016-10-15
# 批量添加用户和默认密码
 
#等待30秒输入name
read -t 30 -p "input name:" name
read -t 30 -p "input password:" pass
read -t 30 -p "input number:" num
 
# 输入的name,pass,num都不是控制
if [ ! -z "$name" -a ! -z "$pass" -a ! -z "$num" ]
        then
                # 将num变量以数字开头的结尾的字符改为空字符串
                y=$(echo $num | sed 's/^[0-9]*$'//g)
                #变量y为空,表示num变量都是数字
                if [ -z "$y" ]
                        then
                                for(( i=1;i<=$num;i++ ))
                                        do
                                                #批量添加用户
                                                /usr/sbin/useradd "$name$i" &>/dev/null
                                                #批量赋予默认密码
                                                echo $pass | /usr/bin/passwd --stdin "&name$i" &>/dev/null
                                        done
                fi
fi
 
# 使用cat /etc/passwd 查看用户是否增加成功





posted @ 2016-10-15 11:14    阅读(268)  评论(0编辑  收藏  举报