Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I don't know when mapfile was added to bash, I'm using this version
Code:
~/Documents $ bash --version
GNU bash, version 4.1.10(2)-release (i486-slackware-linux-gnu)
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
~/Documents $
Here's how to do it without mapfile
Code:
~ $ IFS=$'\x0A'
~ $ x=($(cat < fred.txt))
~ $ for ((i=0; i<y; i++)); do chage -l "${x[$i]}" >> cho.txt; done
chage: user 'Root' does not exist in /etc/passwd
chage: user 'q' does not exist in /etc/passwd
~ $ cat cho.txt
Last password change : Jun 04, 2012
Password expires : never
Password inactive : never
Account expires : never
Minimum number of days between password change : 0
Maximum number of days between password change : 99999
Number of days of warning before password expires : 7
~ $ IFS=$'\x20'$'\x09'$'\x0A'
~ $
IFS is bash's Input Field Separator, the value $'\x0A' makes it be only a newline, google ANSI-C quoting
x=($(cat < fred.txt)) creates the array x
you still need to set y as before to the number of items in x, but as I'm using the same terminal its still there for me.
IFS=$'\x20'$'\x09'$'\x0A' resets IFS to its default values, any one of space, tab or newline.
I think these suggestions are getting needlessly complex. The problem is the formatting in his file, as evidenced by post #14. More intricate and complicated ways of calling chage which still depend on newline-separated fields in the file aren't going to help matters, because his file is apparently not newline-separated...at least not properly.
We need to go back to the source - how was the file created, and why does it not look like what any of these scripts expect? If that can be resolved, I think almost any of the solutions already posted in this thread will work fine.
Just my thoughts on the matter...
Last edited by suicidaleggroll; 10-05-2012 at 11:15 AM.
for ((i=0; i<y; i++)); do chage -l ${x[$i]} >> test.txt; echo "Above Entry for User ${x[$i]}"; done
which produced nothing. Not even an output file. Again I appreciate your help.
Then I think you should check the format of your input file, as others have suggested. A hex editor (bpe is a command-line hex editor often installed by default) will show you explicitly how each line is terminated. In a unix type file, each line should end with the hex character '0A', e.g.
so bpe doesn't exist on my system. The file was created from an ls -l > userlist.txt and then opened in excel, deleted what I didn't want and saved as a text file. Once transferred back, I checked it with vi.
so bpe doesn't exist on my system. The file was created from an ls -l > userlist.txt and then opened in excel, deleted what I didn't want and saved as a text file. Once transferred back, I checked it with vi.
so bpe doesn't exist on my system. The file was created from an ls -l > userlist.txt and then opened in excel, deleted what I didn't want and saved as a text file. Once transferred back, I checked it with vi.
Why all those steps? The excel part is almost certainly your problem. Try not to edit linux files in windows if at all possible, Windows likes to take over and mess everything up.
In the mean time, try running "dos2unix userlist.txt", and then re-run the test you did in step 14.
Thanks everyone. I found a post by Ricky_ds that came at the problem from a different angle and I ran that to an output file and I have everything I need. Again I appreciate all your time. Still not sure why this wouldn't work, but I have what I need. Just changed the location of the users and it's all good.
if [ "$#" = "0" ]; then
echo
echo "List of user accounts with password information"
echo "==============================================="
echo `date`
echo
echo "Legend: M=Minimum password age W=Warning in days before exp"
echo " Dis=Account Disabled"
echo "------------------------------------------------------------------------------------------"
echo "Username |Full name |UID |LastChange|M|Max |W|Passwd Exp|Dis |Acct Exp "
echo "----------|-------------------------|-----|----------|-|-----|-|----------|----|----------"
fi
if [ "$#" = "1" ]; then
echo
echo "===Information for user $name==="
echo "Full name: $fullname"
echo "User ID: $uid"
echo "Password last changed: $last"
echo "Minumum password age: $b"
echo "Maximum password age: $c"
echo "Password warning age: $d"
echo "Password expires on: $pexp"
if test "$e" != "" ; then
echo "The account will be disabled *$e* days after expiration"
fi
echo "The account expires on: $exp"
echo
else
name=`padr $name 10`
c=`padl $c 4`
if test "$e" = "" ; then
e="."
fi
e=`padl $e 3`
exp=`padl $exp 9`
fullname=`padr "$fullname" 25`
uid=`padl $uid 4`
echo "$name|$fullname|$uid|$last|$b|$c|$d|$pexp|$e|$exp"
fi
fi
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.