免费注册 查看新帖 |

Chinaunix

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

能帮我看下这个脚本么? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-12-29 14:54 |只看该作者 |倒序浏览
写了一个简单的查看用户登陆的脚本,命名为who.sh 放到root目录下,给了755的权限,运行sh who.sh
但是就是不通过啊,我的linux是redhat的A4的,哪位高手帮我调试下啊?是什么原因啊?运行的异常:
# sh who.sh
: command not found
: No such file or directoryho
: No such file or directory
: No such file or directory
: No such file or directoryc
: No such file or directory
: command not found
: No such file or directoryho
: No such file or directory
: No such file or directory
: command not found


脚本

#!/bin/sh
# Purpose: this simple script uses the common Linux
# utilities to determine the total and unique number
# of users logged on the system
# Version unimas 1.0

WHO=/usr/bin/who
GREP=/bin/grep
AWK=/bin/awk
SORT=/bin/sort
WC=/usr/bin/wc
SED=/bin/sed
echo -n "Total unique users:"
# Filter the output of the who command using awk to
# extract the first column and then uniquely sort the columns using sort.
# Pipe the sorted output to wc for line count. Finally remove unnecessary white spaces form the output of wc using sed
$WHO | $AWK '{print $1}' | $SORT -u | $WC -l | $SED 's/ */ /g';
# Use grep to filter the output of the who command to
# find the line containing user count.
# then print out the user count using awk
$WHO -q |$GREP users | $AWK 'BEGIN{FS="=";}{printf("\nTotal user sessions: %d\n\n",$2);}';
#Exit
exit 0;


论坛徽章:
0
2 [报告]
发表于 2006-12-29 15:15 |只看该作者
我觉得如果你一定要用这种方式运行shell,可以把$部分放到eval里。

论坛徽章:
0
3 [报告]
发表于 2006-12-29 15:52 |只看该作者
这个是从一个网站上看到,原来的作者就是这么用的,但是不知道为什么,我这里就是不行啊!
楼上的能给个具体的解决方法么?

论坛徽章:
0
4 [报告]
发表于 2006-12-29 16:05 |只看该作者
尝试:

  1. sh -x who.sh
复制代码

论坛徽章:
0
5 [报告]
发表于 2006-12-29 16:10 |只看该作者
sh -x who.sh
+ $'\r'
: command not found
+ WHO=$'/usr/bin/who\r'
+ GREP=$'/bin/grep\r'
+ AWK=$'/bin/awk\r'
+ SORT=$'/bin/sort\r'
+ WC=$'/usr/bin/wc\r'
+ SED=$'/bin/sed\r'
' echo -n 'Total unique users:
+ $'/usr/bin/who\r'
: No such file or directoryho
+ $'/bin/awk\r' '{print $1}'
: No such file or directory
+ $'/bin/sort\r' -u
: No such file or directory
+ $'/usr/bin/wc\r' -l
+ $'/bin/sed\r' 's/ */ /g'
: No such file or directory
: No such file or directoryc
+ $'\r'
: command not found
+ $'/usr/bin/who\r' -q
: No such file or directoryho
+ $'/bin/grep\r' users
: No such file or directory
+ $'/bin/awk\r' 'BEGIN{FS="=";}{printf("\nTotal user sessions: %d\n\n",$2);}'
: No such file or directory
+ $'\r'
: command not found
+ exit 0

论坛徽章:
0
6 [报告]
发表于 2006-12-29 16:19 |只看该作者
你运行个

  1. dos2unix who.sh
复制代码


再看。

论坛徽章:
0
7 [报告]
发表于 2006-12-29 16:26 |只看该作者
# dos2unix who.sh
dos2unix: converting file who.sh to UNIX format ...


老大这个命令什么意思啊?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP