http://blog.csdn.net/linuxlsq/article/details/52606408
请用至少两种方法实现!
bash for循环打印下面这句话中字母数不大于6的单词(昆仑万维面试题)。
#!/bin/bash
s="I am oldboy teacher welcome to oldboy trainingclass"
len= echo $s | wc -w
for ((i=1;i<=8;i++)) do
wordlen=$(echo $s|cut -d " " -f$i|wc -c )
if [ $wordlen -le 7 ]
then
echo $(echo $s|cut -d " " -f$i)
fi
done`这里写代码片`
#!/bin/bash
b() {
str="I am oldboy teacher welcome to oldboy training class"
for i in $str
do
m=$(echo $i|wc -c)
if [ $m -le 7 ]
then
echo $i
fi
done
}
c(){
str="I am oldboy teacher welcome to oldboy training class"
for i in $str
do
if [ ${#i} -le 6 ]
then
echo $i
fi
done
}
str=(I am oldboy teacher welcome to oldboy training class)
for i in $str
do
if [ "'echo $i|wc -l'" -le 6 ]
then
echo $i
fi
done
监控web站点目录(/var/html/www)下所有文件是否被恶意篡改(文件内容被改了),如果有就打印改动的文件名(发邮件),定时任务每3分钟执行一次(10分钟时间完成)。
[root@db02 tmp]# cat html.sh
#!/bin/sh
html_dir=/var/html/www
html_file=`find /var/html/www -type f`
check_dir=/tmp/checkdir
[ ! -d $check_dir ] && mkdir $check_dir
for n in $html_file
do
md5sum $n >>$check_dir/1.txt
done
while true
do
md5sum -c $check_dir/1.txt|grep FAILED >>$check_dir/2.txt
[ -s $check_dir/2.txt ] && \
echo "`cat $check_dir/2.txt`"|mail -s "date:`date +%F-%H:%M:%S` Web is dangerous" 18576749166@163.com
>$check_dir/2.txt
sleep 3
done