赞
踩
#!/usr/bin/env bash
while read line
do
name=`echo $line|awk -F'=' '{print $1}'`
value=`echo $line|awk -F'=' '{print $2}'`
echo "name is ${name},value is ${value}"
done<config.cfg
# 注:需先准备好config.cfg文件
ip=127.0.0.1
port=80
注:<输入重定向,line变量从config.cfg文件中读取;``将内部数据当做一个命令执行
#!/bin/bash
while [ 1 ]
do
fCount=$(ls -l|grep log$|wc -l)
if [ $fCount -gt 9 ]
then
dFile=$(ls -ltr|grep log$|awk 'NR==1 {print $9}')
echo "Delete file:$dFile"
rm -rf $dFile
else
echo "File count<9"
fi
sleep 5
done
创建脚本文件./clear_log.sh,执行时须在目录下创建.log文件
注:while [ 1 ]代表死循环;log$代表以log结尾;wc -l代表显示行数;-gt代表大于;-ltr代表l详细信息,t按时间排序最新的显示在最前面,r倒序;NR==1代表取第一天记录
#!/bin/bash #Generate 1 Million user data which have three items: Phone number:ip address:email address filename="User.txt" if [ -e "$filename" ] then echo "Clean up old file" rm -rf $filename fi phone_start="138" ipv4_start="0x" email_end="qq.com" declare -i s_loop=11000001 declare -i ip_loop=0 declare -i e_loop=11001001 echo "Generate 1 Million data " date while [ $s_loop -lt $e_loop ] do ip_loop=$(($s_loop + 20000000)) echo "$phone_start$s_loop:$ipv4_start$s_loop:$phone_start$s_loop@$eamil_end">>$filename s_loop=$(($s_loop + 1)) done echo $s_loop date
创建脚本文件./generate_data.sh
注:-e判断是否存在;-lt小于
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。