Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4733208
  • 博文数量: 930
  • 博客积分: 12070
  • 博客等级: 上将
  • 技术积分: 11448
  • 用 户 组: 普通用户
  • 注册时间: 2008-08-15 16:57
文章分类

全部博文(930)

文章存档

2011年(60)

2010年(220)

2009年(371)

2008年(279)

分类:

2008-08-31 19:35:17

    今天在自己电脑上搭建了个server,同学(貌似量还比较大)访问了下,电脑有点超负荷,linux阿,有点小受不了,索性kill apache2,I call i服了 you!真多^_^
    ps:一个小教训,以前写了脚本后,有的时候懒得chmod +x,总是sh scriptname.sh,今天发现都不对,整了半天,原来是要bash scriptname.sh,默认是shell貌似不是bash
    想想写了个脚本,有点小成就写在这里
    #!/bin/bash
#kill_process.sh
current_PID=$$
echo $current_PID
ps aux | grep "apache2" | grep -v "grep" | awk '{print $2}' > /tmp/${current_PID}.txt
while read -r pid
do
{
echo "Kill -9 $pid"
kill -9 $pid
}
done < /tmp/${current_PID}.txt
#rm -f /tmp/${current_PID}.txt


    只复制目录结构而不复制文档,很有用的,对我自己
#!/bin/bash
#cpdir.sh

process_id=$$
usage()
{
    echo "Usage: ./cpdir.sh source_dir dest_src"
}
#判断输入
if [ $# -ne 2 ]
    then
    {
        usage
        echo "input error"
        exit
    }
fi

srcdir=$1
destdir=$2

#判断源与目的目录是不是目录
if [ ! -d $srcdir ]
    then
    {
        usage
        echo "${srcdir} is not a dir\n"
        exit
        }
fi

if [ ! -d $destdir ]
    then
    {
        usage
        echo "${dest} is not a dir\n"
        exit
        }
fi
#讲源目录结构cp到tmp file
find ${srcdir}/* -type d > /tmp/srcdir_tmp_${process_id}.txt
sed -n "s/^${srcdir}/${destdir}/p" /tmp/srcdir_tmp_${process_id}.txt > /tmp/srcdir_${process_id}.txt
rm -rf ${destdir}/*
while read line
    do
    {
        mkdir $line
    }
    done < /tmp/srcdir_${process_id}.txt
find ${destdir}/* -type d > /tmp/destdir_${process_id}.txt

diff /tmp/srcdir_${process_id}.txt /tmp/destdir_${process_id}.txt

rm -f /tmp/*.txt
阅读(1326) | 评论(0) | 转发(0) |
0

上一篇:awk 用法总结

下一篇:播放音乐的script

给主人留下些什么吧!~~