LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-27-2012, 02:32 AM   #1
ln00biel
LQ Newbie
 
Registered: Oct 2012
Posts: 3

Rep: Reputation: Disabled
AWK for logins -p


By doing logins -p, I can see a list of users with blank passwords e.g

user1 111 other 1
user2 112 other 1
user3 113 other 1

I am trying to print "yes" when there are users with blank password and "no" if there arent any users with blank passwords. I had used
Code:
logins -p | awk -F"" '{if($!="")print "yes"; else print "no"}'
and it returns me:
yes
yes
yes

So how do I make output it such that it prints one "yes" only? Thanks.
 
Old 10-27-2012, 03:29 AM   #2
Heraton
Member
 
Registered: Apr 2011
Location: Germany
Distribution: Mint 10, openSuSE
Posts: 58

Rep: Reputation: 3
Smile Try this...

Hello!

Should work this way:
Code:
if [ "$(logins -p | wc -l)" -ne 0 ]; then echo yes; else echo no; fi
Note: I could not test it, as logins is not available in my distro.

Regards, Heraton

Last edited by Heraton; 10-27-2012 at 03:30 AM. Reason: Typo
 
Old 10-27-2012, 04:45 AM   #3
ln00biel
LQ Newbie
 
Registered: Oct 2012
Posts: 3

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Heraton View Post
Hello!

Should work this way:
Code:
if [ "$(logins -p | wc -l)" -ne 0 ]; then echo yes; else echo no; fi
Note: I could not test it, as logins is not available in my distro.

Regards, Heraton
Thanks Heraton. The code keeps giving me an output of "no" when it is supposed to be "yes". May I just ask if
Code:
wc -l
returns an integer? I want to store
Code:
logins -p | wc -l
as a variable but it returns a blank when I echo it. I am writing this in a bash script.

Last edited by ln00biel; 10-27-2012 at 05:03 AM. Reason: wrong spelling
 
Old 10-28-2012, 09:36 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,411

Rep: Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397
The wc cmd can return various numbers, all integer http://linux.die.net/man/1/wc
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
running series of awk commands from an awk file oreka18 Programming 3 05-16-2012 02:13 AM
awk error awk: line 2: missing } near end of file boscop Linux - Networking 2 04-08-2012 11:49 AM
LXer: Using scponly To Allow SCP/SFTP Logins And Disable SSH Logins On Debian Squeeze LXer Syndicated Linux News 0 08-24-2011 05:20 AM
[SOLVED] call awk from bash script behaves differently to awk from CLI = missing newlines titanium_geek Programming 4 05-26-2011 10:06 PM
shell command using awk fields inside awk one71 Programming 6 06-26-2008 05:11 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:56 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration