mecorn 发表于 2005-11-16 10:47:59

请教两个简单的脚本编程

1、怎样编写一个shell,该shell用以扫描登录用户的默认目录,对所有以“.a”为后缀的文件合并到用户默认目录下“total.a”文件中,并删除原来的文件?



2、编写一个shell,对指定目录,检查其中文件属性是否为777,如发现则提示该文件有危险的属性,并改为754。



谢谢~~ :)

mecorn 发表于 2005-11-16 14:00:25

各位高手,谁知道的请告诉一下嘛,救救命啊.

sparks 发表于 2005-11-16 15:27:24

1.
#!/bin/sh                                                                                 
for file in `find $HOME -name "*.a"`; do
    cat $file >>$HOME/total.a
    rm -f $file
done

2.
#!/bin/sh
for file in `ls $1`; do
   ls -l $1/$file | egrep '^-rwxrwxrwx' >/dev/null 2>&1
   if [ $? -eq 0 ]; then
      echo "$1/$file: file attribute 777!"
      chmod 754 $1/$file
   fi
done

bison_gao 发表于 2005-11-16 23:44:26

sparks好手段呀!

mecorn 发表于 2005-11-18 08:54:23

谢谢,谢谢.请问sparks,我可以加你QQ吗?


因为我想请你吃饭,以表达你的救命之恩.

sparks 发表于 2005-11-18 10:24:52

救人一命,胜造十级浮屠
谢谢你给我这个机会啊! 呵呵
页: [1]
查看完整版本: 请教两个简单的脚本编程