LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-27-2006, 09:30 AM   #1
jsheffie
Member
 
Registered: Dec 2004
Location: Florida, USA
Distribution: Suse 10.0, OSX.4, Solaris 10
Posts: 163

Rep: Reputation: 30
bashing my plumber...


Hi,

I am attempting to do some piping with the finger and awk commands and am having some difficulty.

I am trying to search for a user name and if it is available print something to the screen like This user name is available. Specifically, trying to get a "no", from no such user, and insert an elif statement into a script to display that the username is available.)

I've done a little research on it, but I am still having difficulty.

Here is what I have done so far. (attempting to pull a "no")

1st - several attempts:
$finger l | awk '{print $3}'
finger: l: no such user.

w/ backticks
finger joe `awk '{print $3}'`
...no feedback...

w/backticks
finger joe | `awk '{print $3}'`
finger: joe: no such user.

Am I missing something? I also tried sending a -F option to awk and specifying a ":" as a separator, but that didn't work either.

Any ideas?

Thanks
 
Old 03-27-2006, 09:53 AM   #2
ckoniecny
Member
 
Registered: Oct 2005
Posts: 162

Rep: Reputation: 30
# ./loggedon tux

Code:
#!/bin/sh

RESULT=`finger | grep $1 | wc -l | awk '{print $1}'`

if [ "$RESULT" -ne 0 ];
then
    echo "$1 is logged in!"
else
    echo "$1 is NOT logged in!"
fi
Result:
tux is logged in!

Last edited by ckoniecny; 03-27-2006 at 09:58 AM.
 
Old 04-04-2006, 12:29 PM   #3
jsheffie
Member
 
Registered: Dec 2004
Location: Florida, USA
Distribution: Suse 10.0, OSX.4, Solaris 10
Posts: 163

Original Poster
Rep: Reputation: 30
I copied and pasted the lines you provided...

#!/bin/sh

RESULT=`finger | grep $1 | wc -l | awk '{print $1}'`

if [ "$RESULT" -ne 0 ];
then
echo "$1 is logged in!"
else
echo "$1 is NOT logged in!"
fi


and received the following output...
tux@mudpie:~/Desktop/> ./test1
Usage: grep [OPTION]... PATTERN [FILE]...
Try `grep --help' for more information.
is NOT logged in!

Did I miss something here?

thanks
 
Old 04-04-2006, 01:02 PM   #4
ckoniecny
Member
 
Registered: Oct 2005
Posts: 162

Rep: Reputation: 30
When you execute the shell script, the $1 means use the first argument provided along with the script. For example.

# ./test tux

That will execute the script "test" and look for the user "tux" and display how many times tux is logged in. You have to provide an arugment with the script. Thats why you are getting that error.
 
Old 04-04-2006, 02:27 PM   #5
cramer
Member
 
Registered: Feb 2006
Distribution: Red Hat 9
Posts: 112

Rep: Reputation: 15
What does the -ne 0 mean in the script?

Does it mean if the commands in the variable RESULT return something not equal to 0 then the username exists?
 
Old 04-04-2006, 02:47 PM   #6
jsheffie
Member
 
Registered: Dec 2004
Location: Florida, USA
Distribution: Suse 10.0, OSX.4, Solaris 10
Posts: 163

Original Poster
Rep: Reputation: 30
Thanks ckoniecny,

I didn't catch the execution on the top line of your post. I am working on modifying it to fit what I am looking for.

Thanks again,
-Me
 
Old 04-04-2006, 03:22 PM   #7
ckoniecny
Member
 
Registered: Oct 2005
Posts: 162

Rep: Reputation: 30
Yes cramer, thats exactly what it means.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How To Become a Plumber? Anyone know? samizdabestdude General 21 04-23-2005 02:13 PM
Please STOP bashing! Seppel General 24 03-14-2005 01:14 PM
A little Microsoft bashing jimdaworm General 13 04-21-2004 04:06 PM
Emacs bashing guygriffiths Linux - Software 0 12-16-2003 06:20 AM
Linux Bashing lava General 2 03-26-2003 11:17 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:29 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration