LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This 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



Reply
 
Search this Thread
Old 11-11-2012, 09:47 PM   #1
gsiva
LQ Newbie
 
Registered: Apr 2007
Posts: 22

Rep: Reputation: 0
User expiry Script.


Hi Folks,

With reference to the link below,
http://www.linuxquestions.org/questi...locked-294627/

I got the below error message while executing the script.

user_expiry.sh: line 63: 15566 + : syntax error: operand expected (error token is " ")
 
Old 11-11-2012, 10:08 PM   #2
towheedm
Member
 
Registered: Sep 2011
Location: Trinidad & Tobago
Distribution: Debian Squeeze
Posts: 585

Rep: Reputation: 119Reputation: 119
That script references /etc/shadow so it must be run with root privileges.

I also got the invalid date format error as mentioned in the thread.
 
Old 11-11-2012, 10:12 PM   #3
gsiva
LQ Newbie
 
Registered: Apr 2007
Posts: 22

Original Poster
Rep: Reputation: 0
Thanks Towheedm, I am running as a root only.
 
Old 11-11-2012, 10:31 PM   #4
towheedm
Member
 
Registered: Sep 2011
Location: Trinidad & Tobago
Distribution: Debian Squeeze
Posts: 585

Rep: Reputation: 119Reputation: 119
Are you getting the error while running as root?
 
Old 11-11-2012, 10:47 PM   #5
gsiva
LQ Newbie
 
Registered: Apr 2007
Posts: 22

Original Poster
Rep: Reputation: 0
yeup, getting the error while running as the root.
 
Old 11-11-2012, 11:08 PM   #6
towheedm
Member
 
Registered: Sep 2011
Location: Trinidad & Tobago
Distribution: Debian Squeeze
Posts: 585

Rep: Reputation: 119Reputation: 119
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.
 
Old 11-12-2012, 12:21 AM   #7
gsiva
LQ Newbie
 
Registered: Apr 2007
Posts: 22

Original Poster
Rep: Reputation: 0
I am getting the exact output, while running the script has
sh user_expiry.sh test

But, still coming up with the same error message at the bottom as

user_expiry.sh: line 64: 15155 + : syntax error: operand expected (error token is " ")
 
Old 11-12-2012, 01:56 AM   #8
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,563
Blog Entries: 29

Rep: Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179
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
Code:
    c=`echo -e $uname | awk -F: '{print$5}'`
    [[ $c = '' ]] && continue
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
Code:
uname=`cat /etc/shadow | grep -r "^$name:" | awk -F":" '{print}'`
sets uname empty. On my netbook running Slackware 13.37 there are 3 such users:
Code:
root@CW9:~# wc -l /etc/passwd
28 /etc/passwd
root@CW9:~# wc -l /etc/shadow
25 /etc/shadow
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

Last edited by catkin; 11-12-2012 at 02:24 AM.
 
Old 11-13-2012, 09:04 AM   #9
linosaurusroot
Member
 
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 870
Blog Entries: 2

Rep: Reputation: 219Reputation: 219Reputation: 219
What do you get from pwck ?
 
Old 11-19-2012, 11:39 PM   #10
gsiva
LQ Newbie
 
Registered: Apr 2007
Posts: 22

Original Poster
Rep: Reputation: 0
I have fixed the problem. thanks folks.

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
 
Old 11-20-2012, 02:36 AM   #11
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.6, Centos 5.10
Posts: 16,324

Rep: Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041
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.
 
Old 11-20-2012, 04:35 AM   #12
linosaurusroot
Member
 
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 870
Blog Entries: 2

Rep: Reputation: 219Reputation: 219Reputation: 219
Quote:
Originally Posted by chrism01 View Post
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 {}.
 
Old 11-21-2012, 01:01 AM   #13
gsiva
LQ Newbie
 
Registered: Apr 2007
Posts: 22

Original Poster
Rep: Reputation: 0
Hi,

I have just following up with the same link as below for script.

With reference to the link below,
http://www.linuxquestions.org/questi...locked-294627/

I tried to change as the OUTPUT value, but the output is not being generated under the /var/log.
 
Old 11-21-2012, 10:10 AM   #14
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,563
Blog Entries: 29

Rep: Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179
That link is malformed. It results in "Unexpected response code received". The ... appears in the underlying link as well as the displayed link.
 
  


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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
LDAP Account Password Expiry Script Doknik Linux - Newbie 1 08-04-2011 05:36 AM
User login expiry date? geekgrl Linux - Security 7 07-04-2011 07:08 AM
password policy expiry in the user sammee Linux - Newbie 5 09-16-2008 09:51 AM
how to check the password expiry date of a user? binary_0011 Other *NIX 1 06-04-2008 02:37 AM
Shell script for password expiry alert bhandu Linux - General 1 06-13-2007 05:19 AM


All times are GMT -5. The time now is 07:55 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration