LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 01-31-2003, 09:38 AM   #1
j-me
Member
 
Registered: Jan 2003
Location: des moines, ia
Distribution: suse RH
Posts: 129

Rep: Reputation: 17
Question shell script to find user(s) profile


i'm toying around with shell script. my plan is to read the /etc/passwd file extracting the usernames and feeding the usernames to chage to find out how all users are set up. i've got a count of the entire file just for grins. i can cat the file to awk and get the names but i cannot get the names to pipe to chage -l and display each users profile.

script as of now:
#!/bin/sh
n=`cat /etc/passwd |wc -l `
echo $n "number of users"
cat /etc/passwd | awk -F: '{print $1}'

any ideas?
 
Old 01-31-2003, 09:59 AM   #2
rockdw
Member
 
Registered: Nov 2002
Location: Chicago, IL
Distribution: Rasbian, Debian, Gentoo, RHEL
Posts: 65

Rep: Reputation: 21
Use xargs to take the output of the awk command. I don't know what change itself is capable of, but I assume change -l lists profile info. xargs takes the resulting wordlist and does the next command against each item one at a time:

cat /etc/passwd | awk -F: '{print $1}' | xargs change -l
 
Old 01-31-2003, 11:16 AM   #3
masinick
Member
 
Registered: Apr 2002
Location: Greenville, SC
Distribution: Debian, antiX, MX Linux
Posts: 636
Blog Entries: 16

Rep: Reputation: 104Reputation: 104
Some thoughts about awk, chage, and xargs

Quote:
Originally posted by rockdw
Use xargs to take the output of the awk command. I don't know what change itself is capable of, but I assume change -l lists profile info. xargs takes the resulting wordlist and does the next command against each item one at a time:

cat /etc/passwd | awk -F: '{print $1}' | xargs change -l

From the man command:

NAME
chage - change user password expiry information

SYNOPSIS
chage [-m mindays] [-M maxdays] [-d lastday] [-I inactive]
[-E expiredate] [-W warndays] user

chage -l user

DESCRIPTION
chage changes the number of days between password changes and the date
of the last password change. This information is used by the system to
determine when a user must change her password. The chage command is
restricted to the root user, except for the -l option, which may be
used by an unprivileged user to determine when her password or account
is due to expire.

So who can use the command may be affecting what's going on.

Typing in

awk -F: '{print $1}' /etc/passwd

is sufficient to list ALL accounts in the passwd file, but I'm not really sure that's what you'd want to do. Many of the accounts are really interfaces to special purpose events, like shutdown, bin, daemon, and other accounts specifically intended not as login accounts, but to serve as interfaces to specific functions. In fact, on my system, there are only really two login accounts that I know of, root and masinick, yet there are

wc -l /etc/passwd
24 /etc/passwd

24 entries in the file.

So a good solution to this problem, in my estimation, would be to weed out the unnecessary accounts. Run whatever shell you develop from root, then it should work properly with chage - 'change age'... hmm, should I run chage on myself? LOL
 
  


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
Shell script to find a particular string Prasun1 Linux - General 5 08-30-2005 09:23 AM
find shell script help liren Linux - Newbie 3 05-02-2005 03:05 PM
How to find out kernel version in a shell script? ta0kira Slackware 3 10-05-2004 04:54 AM
how to find the pid of a perl script from shell script toovato Linux - General 1 12-19-2003 06:25 PM
Linux can't find a shell script?? jt1020 Linux - General 4 04-27-2003 08:27 AM

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

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