We help IT Professionals succeed at work.
Get Started

Shell script to log user

dtank
dtank asked
on
509 Views
Last Modified: 2010-04-21
basically i am trying to use this file to output the date only if the user name supplied as an argument is logged in.

#!/bin/sh
set user_in = 0
set user_date = 0
user_in=`who | grep $1 | tail -1 | awk '{printf $1}'`
user_date=`who | grep $1 | tail -1 | awk '{printf $3 " " $4 " " }'`
case $user_in in
$1)
        echo $user_date > ./out
*)
        echo "$1 is not currently logged in"
esac

i get the following error messages
: Command not found.
: Command not found.
case: Too many arguments.

Thanks in advance for any assistance
Comment
Watch Question
CERTIFIED EXPERT
Top Expert 2006
Commented:
This problem has been solved!
Unlock 1 Answer and 11 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE