- 论坛徽章:
- 0
|
写了一个简单的查看用户登陆的脚本,命名为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;
  |
|