LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 03-24-2015, 11:42 AM   #1
linuxmantra
Member
 
Registered: Dec 2013
Posts: 110

Rep: Reputation: Disabled
Script


user="john bob randy susan"
I extracted local user list as: cat /etc/passwd | cut -d ":" -f1

Now I need to write a script to find the difference in user between these two (users defined as above and local user). I tried many ways its not working. Any help

#!/bin/bash
users="john bob randy susan"
luser=`/bin/cat /etc/passwd | cut -d ":" -f1`
......
....


Thank you
 
Old 03-24-2015, 11:56 AM   #2
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 2,308

Rep: Reputation: 816Reputation: 816Reputation: 816Reputation: 816Reputation: 816Reputation: 816Reputation: 816
So what have you written so far?

What is your expected output?
 
Old 03-24-2015, 01:09 PM   #3
linuxmantra
Member
 
Registered: Dec 2013
Posts: 110

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by TenTenths View Post
So what have you written so far?

What is your expected output?
for u in $users

do

if $(awk '/$u/' /etc/passwd )
then
false
fi
if $(awk '/$u/' /etc/passwd -eq 1)
then
echo -e $(grep $u /etc/passwd)
fi
done


my expected output is non-matched user (Defined user group - local user) should be shown.
 
Old 03-24-2015, 01:32 PM   #4
rtmistler
Moderator
 
Registered: Mar 2011
Location: Sutton, MA. USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu
Posts: 4,498
Blog Entries: 10

Rep: Reputation: 1647Reputation: 1647Reputation: 1647Reputation: 1647Reputation: 1647Reputation: 1647Reputation: 1647Reputation: 1647Reputation: 1647Reputation: 1647Reputation: 1647
What's "$u" represent? EDIT: OK I missed that, it is the var from the loop.

I need a better problem/solution description.

Sounds like you want to search the passwd file to determine if the user running the script is a user on this machine. That doesn't make much sense, they really could not be on the machine running a script if they weren't a defined user on that machine.

See my signature about how to use [code][/code] blocks.

Last edited by rtmistler; 03-25-2015 at 10:19 AM.
 
Old 03-24-2015, 04:32 PM   #5
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 2,308

Rep: Reputation: 816Reputation: 816Reputation: 816Reputation: 816Reputation: 816Reputation: 816Reputation: 816
Close.

Try:

Code:
#!/bin/bash
USERS="john bob randy susan"

for U in ${USERS} ; do
  if [ $(grep ^${U}: /etc/passwd) ] ; then
    echo "Found ${U}"
  else
    echo "Not Found ${U}"
  fi
done

Last edited by TenTenths; 03-24-2015 at 04:34 PM.
 
  


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
Shell script/Perl Script to remove the string until it finds special character '_' pooppp Programming 10 07-17-2012 10:36 AM
Shell script/Perl Script to remove the string until it finds special character '_' pooppp Programming 1 07-13-2012 02:03 AM
Shell script, Perl script, command or utility to convert Binary to text Perseus Programming 26 07-12-2012 07:00 AM
[SOLVED] bash and xterm: how make apps started by and for a script persist when script terminates porphyry5 Linux - General 4 06-15-2011 02:27 PM
[SOLVED] Script question: create a shell script in kde to log in on a server with ssh c4719929 Linux - Newbie 1 01-31-2011 04:05 AM


All times are GMT -5. The time now is 01:28 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