免费注册 查看新帖 |

Chinaunix

广告
  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1395 | 回复: 0
打印 上一主题 下一主题

求一shell脚本的注解 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-05-05 10:42 |只看该作者 |倒序浏览
[i=s] 本帖最后由 appletan 于 2011-05-05 10:44 编辑 [/i]

有一个脚本内容如下,请高手帮忙解释下此shell脚本实现的功能是?
是配在root的crontab里定时执行的


file1="/etc/passwd"
file_out="/tmp/userlist"

cat $file1 | while read line; do
        username=`echo $line | awk -F: '{print $1}'`
        homedir=`echo $line | awk -F: '{print $6}'`
        logincmd=`echo $line | awk -F: '{print $7}'`

        # Set the first guess, depends on the platform
        # Test if the account can really login
        canlogin=

        if [ "$logincmd" = "/bin/bash" ]
        then
                canlogin=1
                filename='/.bash_history'
        fi
        if [ "$logincmd" = "/bin/sh" ]
        then
                canlogin=1
                filename='/.sh_history'
        fi
        if [ "$logincmd" = "/bin/csh" ]
        then
                canlogin=1
                filename='/.sh_history'
        fi
        if [ "$logincmd" = "/bin/ksh" ]
        then
                canlogin=1
                filename='/.sh_history'
        fi

        if [ $canlogin ]
        then
                if [ "$homedir" = "/" ]
                then
                        file2=$filename
                else
                        file2=$homedir"/"$filename
                fi
                if [ -f "$file2" ]
                then
                        cp $file2 /tmp/history
                        echo $username"----------"$file2
                        while read cmd
                        do
                                echo $cmd
                                logger -t "oscmd" "$username:$cmd"
                        done < "/tmp/history"
                        cp -f /dev/null $file2
                else
                   echo "----------"$username" history file doesn't exist---------"
                fi
        else
                echo "----------$username can't login----------"
        fi
done
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP