Visit Our UNIX and Linux User Community

Easy Script, just to find the given username if is it online or not

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Easy Script, just to find the given username if is it online or not
# 1  
Old 10-13-2009
Easy Script, just to find the given username if is it online or not

hey guys plz help me..with shell script.

i must find the given(the user types a username) username if is it login or not..

i know how to do it logically, but i think that i can't in scripting.

Thank you all
# 2  
Old 10-13-2009
A simple thing could be, in bash.
$ cat
echo -n "Enter the username: "
read a
w | grep $a >> /dev/null
if [ $? -eq 0 ]; then
    echo "User $a is logged in..";
    echo "User $a is not logged in.";

# 3  
Old 10-14-2009
i think that one will help me alot...i will post you tomorrow if everything was ok...because i dont have unix system right now.

thank you a lot!

---------- Post updated 10-14-09 at 09:59 AM ---------- Previous update was 10-13-09 at 06:42 PM ----------

everything is ok, but i get an error in line 1 about the $ it says that $: not found, any ideas?
# 4  
Old 10-14-2009
this is not part of the script... "cat file" just shows what is inside the file.
# 5  
Old 10-14-2009
ok so i need to delete the line 1?
i did it and everything is that correct?

Thank you all
# 6  
Old 10-14-2009
Ya, you are right.

Exclude the first line, and have all the remaining lines in the script. Execute the script, which would ask you a user name and finds out whether that persons is logged in or not.

Previous Thread | Next Thread
Test Your Knowledge in Computers #829
Difficulty: Medium
The JSON standard supports object references.
True or False?

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using grep with 'who' to find online users

solved (3 Replies)
Discussion started by: subway69
3 Replies

2. IP Networking

iptables - most easy way to find rule and remove it?

I have situation where I have rules in iptables with comments. Now... I can for example enter rule like "iptables -A FORWARD -s xxx -j ACCEPT" and delete it with "iptables -D FORWARD -s xxx -j ACCEPT".. but if that rule contain some random comment (-m comment) then ... ? I can find with scripting... (2 Replies)
Discussion started by: darkman_hr
2 Replies

3. UNIX and Linux Applications

grep file to find unique instances of username

hello - A SystemOut.log file has recurring entries that follow this format: Principal: Over the course of a day thousands of lines similar to this are produced, with each username represented hundreds of times. I need to create a new file that shows... (4 Replies)
Discussion started by: 1075FJ40
4 Replies

4. UNIX for Advanced & Expert Users

how to find any device online/offline

what is the command for checking which device active and which is not active (1 Reply)
Discussion started by: RahulJoshi
1 Replies

5. Shell Programming and Scripting

To find the username in /etc/passwd file

Hi, I need to a shell script to list out only the username in the /etc/passwd file. Regards Siva (7 Replies)
Discussion started by: gsiva
7 Replies

6. Shell Programming and Scripting

Find username of user running the script

Hello All, If I have a simple cgi script and want to find the name of the person accessing the page, is it possible? How do I get the name of this user? Please help. I was trying a vague method but it doesn't seem to work with all browsers and versions ... $val=$ENV{'HTTP_COOKIE'}; $name... (1 Reply)
Discussion started by: garric
1 Replies

7. UNIX for Dummies Questions & Answers

Need help on installing an EASY to use and easy to install command line text editor

Hi again. Sorry if it seems like I'm spamming the boards a bit, but I figured I might as well ask all the questions I need answers to at once, and hopefully at least get some. I have installed Solaris 10 on a server. The default text editors are there (vi, ex, ed, maybe others, I know emacs is... (4 Replies)
Discussion started by: EugeneG
4 Replies

8. UNIX for Dummies Questions & Answers

Find, make and move file based on username

hi there, i'm new to UNIX( just 3month used), i found my new box contained alot of files and directories in /home/box/ i've tried to search script in tis forum and found many of them but, i don't know how to combine them to make a script, although using pipes. my tasks are: 1) to scan user... (5 Replies)
Discussion started by: Helmi
5 Replies

9. UNIX for Dummies Questions & Answers

How to find who fingered my username

Hi Everyone, Whenever someone uses the finger command against my username, he.she gets my info. Is there a way to find who ran the command against my username, somewhat like a log file for the finger command. I would be greatful if someone to clear my query. Regards Anirudh Koul... (3 Replies)
Discussion started by: anirudhkoul
3 Replies

Featured Tech Videos