#!/bin/bash
weekday=`date --date='3 days ago' +%a`
echo "$weekday"
time=`date --date='3 days ago' +%T`
echo "$time"
today=`date --date='3 days ago' | sed 's/^.*'${weekday}'//g' | sed 's/'${time}'.*$//g'`
echo "$today"
path1=/var/spool/mqueue
a=(`/bin/ls -lh $path1 | grep "$today" | awk '{print $9 }'`)
cd $path1
echo "${a[@]}"
rm -rf "${a[@]}"
///////////////////
執行結果
[root@]# ./del_qmail.sh
Wed
19:23:31
Jul 21
dfo6KG0HQE005112 dfo6KG93l3005616 dfo6KGcDdg006924 dfo6KGDoCk005825 dfo6KGI0je006012 dfo6KGNXsV006282 dfo6KGrM36007559 dfo6KGY50R006773 dfo6KH1K7D008105 dfo6KH2Skj008151 dfo6KH3kcu008209 dfo6KH9McP008445 dfo6KHa3oT009697 dfo6KHAfOA008508 dfo6KHERUG008652 dfo6KHIGKl008806 dfo6KHK0Bk008894 dfo6KHWGBA009473 dfo6KHZIdl009670 dfo6KI01Dk010814 dfo6KI1Es9010885
附註:
#設定間隔符號為換行,搭配$*將陣列的值一口氣輸出
IFS=$'\n'
echo "${array[*]}"
#將陣列中的值利用$@一口氣輸出與$*不同的是,不會將值合併成單一字串
echo "${array[@]}"
參考
http://go-linux.blogspot.com/2007/03/basharray.html
沒有留言:
張貼留言