Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then 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.
Try passing a username as an argument to the script. I'll pass user lfs to the script:
Code:
sudo ./user_expiry.sh lfs
date: invalid date ` 99846 day'
===Information for user lfs===
Full name:
User ID: 1001
Password last changed: 14.04.2013
Minumum password age: 0
Maximum password age: 99999
Password warning age: 7
Password expires on:
The account expires on: NEVER
If that works set the script to trace and post the output:
Code:
#! /bin/bash
set -x
.
.
.
This will expose lines from your /etc/passwd and /etc/shadow file in the trace output.
The error occurs when the 5th field, maximum password age, of /etc/shadow is empty. Assuming that means there is no point in processing users for which this data does not exist, the script can be fixed by
Another problem discovered with the script was that it fails on line 53 for users that are listed in /etc/password but not in /etc/shadow. In this case
EDIT: all three users have been added since OS installation. Two have not had a password set. The other changed its own password using the passwd command; its passwd is in /etc/passwd, encrypted. Not ideal!
EDIT2:
The script could be modified to generate an error message for users not listed in /etc/shadow
Code:
if [[ $uname = '' ]]; then
echo "ERROR: $name is not listed in /etc/shadow" >&2
continue
fi
Now, how can I set the password output to be save in the file name "chk_users_expiry.HOSTNAME.log" under /var/log. I tried with below, that doesn't work.
HOST=`hostname`
# create output file name
OUTPUT="/var/log/chk_users_expiry.$HOST.log"
and I want to grep two users like test1 and test2, where their output should be like below.
Password for test will expire on Thu Dec 20 00:22:17 2012
Can you show the current version of your script?
In any case, for embedded vars, you should really use {} thus
Code:
OUTPUT="/var/log/chk_users_expiry.${HOST}.log"
so the parser can tell when the varname starts/stops.
The variable name starts at $ and ends at the first character that's not legal in a variable name - in this case the dot. Supposing the next character after the variable had been [a-zA-Z0-9_] then you'd need the {}.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.