linux自动化shell脚本练习(一)(for循环)

使用for循环在/clsn目录下批量创建10个html文件,其中每个文件需要包含10个随机小写字母加固定字符串clsn,脚本内容:

[root@lry scripts]# cat make_file.sh 
#!/bin/bash
##############################################################
# File Name: make_file.sh
# Created Time : 2018-06-26 20:32:33
# Description:
##############################################################

[ -d /clsn ] || mkdir -p /clsn
rpm -qa | grep pwgen &>/dev/null
if [ $? -eq 1 ]
	then
		yum install pwgen -y &>/dev/null
fi

cd /clsn &&\
for i in {1..10}
	do
	#File_Name = `uuidgen |tr "0-9-" "a-z"|cut -c 1-10`
	File_Name2=`pwgen -1A0 10`
	touch ${File_Name2}_clsn.html
done

bash这个脚本

[root@lry clsn]# ll /clsn
total 0
-rw-r--r-- 1 root root 0 Jun 26 20:55 aiyoaxaefu_clsn.html
-rw-r--r-- 1 root root 0 Jun 26 20:55 chaimohphu_clsn.html
-rw-r--r-- 1 root root 0 Jun 26 20:55 eewohseefu_clsn.html
-rw-r--r-- 1 root root 0 Jun 26 20:55 meevaifugh_clsn.html
-rw-r--r-- 1 root root 0 Jun 26 20:55 mopohseeje_clsn.html
-rw-r--r-- 1 root root 0 Jun 26 20:55 soorooboch_clsn.html
-rw-r--r-- 1 root root 0 Jun 26 20:55 yeonahceej_clsn.html
-rw-r--r-- 1 root root 0 Jun 26 20:55 yiengahfoh_clsn.html
-rw-r--r-- 1 root root 0 Jun 26 20:55 yupiweuzaz_clsn.html
-rw-r--r-- 1 root root 0 Jun 26 20:55 zeipeiseiy_clsn.html
其中,
[root@lry scripts]# rpm -qa | grep pwgenaa
[root@lry scripts]# echo $?
1
[root@lry scripts]# rpm -qa | grep pwgen
pwgen-2.07-1.el7.x86_64
[root@lry scripts]# echo $?
0
echo $0的值等于0表示成功状态


猜你喜欢

转载自blog.csdn.net/u013230234/article/details/80834645