Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1007171
  • 博文数量: 128
  • 博客积分: 10012
  • 博客等级: 上将
  • 技术积分: 2050
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-15 17:49
文章分类

全部博文(128)

文章存档

2011年(16)

2009年(57)

2008年(55)

分类:

2011-06-13 21:14:48

1.利用top取某个进程的CPU的脚本:
#/bin/sh
Max_CPU=0
Avg_CPU=0
Total_Time=1
Process=$1
Interval=$2
# check the parameters
if [ $# -ne 2 ]; then
echo "Usage: $0 ProcessName Interval"
exit
fi
LogFile="Per.txt"
echo "`date`" > $LogFile
while sleep $Interval
do
top -d 1 -n 1|grep $Process|grep -v grep|awk '{print $9"\t"$10}' >> $LogFile
done

2.判断是否是设备文件
#/bin/bash

echo -e "The program will Judge a file is or not a device file.\n\n"
read -p "Input a filename:" filename
if [ -b $filename -o -c $filename ]; then
echo "$filename is a device file"
exit 0
else
echo "$filename is not a device file"
exit 1
firead –p:用于在读数据时输出提示信息

注意! [ 之间是有空格的:if ! [ -f $filename ] ; then。一般用if [ ! * ]

3. 统计IP访问
 要求分析apache访问日志,找出访问页面数量在前100位的IP数。日志大小在78M左右。以下是apache的

访问日志节选
 202.101.129.218 - - [26/Mar/2006:23:59:55 +0800] "GET /online/stat_inst.php?pid=d065

HTTP/1.1" 302 20-"-" "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"

 答案1. cat ip.txt | awk '{ print $1}' |sort -nr|uniq -c |head -100
 答案1. awk '{ print $1}' ip.txt |sort -nr|uniq -c |heae -100

4. 求2个数之和
#/bin/bash
typeset first second
read -p "Input the first number:" first
read -p "Input the second number:" second
result=$[$first+$second]
echo "result is : $result"
exit 0

5. 打印root可以使用可执行文件数
处理结果:
root's bins: 2306
echo "root's bins: $(find ./ -type f | xargs ls -l | sed '/-..x/p' | wc -l)"
root's bins: 3664

6.编译当前目录下的所有.c文件
 for file in *.c; do echo $file ; gcc -o $(basename $file .c) $file  ; sleep 2;  done >

compile 2>&1

 7.将一目录下所有的文件的扩展名改为bak
for i in *.*;do mv $i ${i%%.*}.bak;done

阅读(2540) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~