خرید بک لینک

Hi,
I'm taking a Linux course.
One task is creating a script to check whether a user is logged in or not.
The script run with useame for argument. If there is none, it is to be prompted for.
The script is to exit 0 if user is logged in, and exit 1 if not.

Code:

#!/bin/bash

function checkUser
{
    for u in $(who | awk '{print $1}' | sort | uniq)
    do 
        if [ "$u"="$user" ]; then
            echo "User $u is logged in."
            echo "Exit status: $?"
            exit $?
        else
            "User $u is not logged in."
            echo "Exit status: $?"
            exit $?
        fi
    done
}

if [ -z $1 ]; then
    echo "User to check:"
    read user
else
    "$user"="$1"
fi
checkUser $1
There are issues however.
Executing the script with argument, there is error message:

Code:

$ ./checkuser henrix
.checkuser: line23: =henrix: command not found
User adam is logged in.
Exit status 0.
Ruing the script without argument, it doesn't even consider entered name:

Code:

$ ./checkuser
User to check: henrix
User adam is logged in.
Exit status 0.
For this script, I keep two users logged in:

Code:

$ who | awk '{print $1}' | sort | uniq
adam
henrix
I was only recently introduced to Bash, and this is my first forum post.
I've done my best to provide information. I hope someone can shed light on this.
Thanks.

This is a follow-up to http://ubuntuforums.org/showthread.php?t=2075873 (closed).

برچسب: نویسنده: استخدام کار تاريخ: شنبه 29 اسفند 1394 ساعت: 6:30

صفحه بندی