LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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, 08: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, 09:08 PM   #2
towheedm
Member
 
Registered: Sep 2011
Location: Trinidad & Tobago
Distribution: Debian Stretch
Posts: 612

Rep: Reputation: 125Reputation: 125
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, 09: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, 09:31 PM   #4
towheedm
Member
 
Registered: Sep 2011
Location: Trinidad & Tobago
Distribution: Debian Stretch
Posts: 612

Rep: Reputation: 125Reputation: 125
Are you getting the error while running as root?
 
Old 11-11-2012, 09: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, 10:08 PM   #6
towheedm
Member
 
Registered: Sep 2011
Location: Trinidad & Tobago
Distribution: Debian Stretch
Posts: 612

Rep: Reputation: 125Reputation: 125
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-11-2012, 11:21 PM   #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, 12:56 AM   #8
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
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 01:24 AM.
 
Old 11-13-2012, 08:04 AM   #9
linosaurusroot
Member
 
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 982
Blog Entries: 2

Rep: Reputation: 244Reputation: 244Reputation: 244
What do you get from pwck ?
 
Old 11-19-2012, 10: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, 01:36 AM   #11
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,369

Rep: Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753
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, 03:35 AM   #12
linosaurusroot
Member
 
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 982
Blog Entries: 2

Rep: Reputation: 244Reputation: 244Reputation: 244
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, 12: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, 09:10 AM   #14
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

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


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 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 04:36 AM
User login expiry date? geekgrl Linux - Security 7 07-04-2011 06:08 AM
password policy expiry in the user sammee Linux - Newbie 5 09-16-2008 08:51 AM
how to check the password expiry date of a user? binary_0011 Other *NIX 1 06-04-2008 01:37 AM
Shell script for password expiry alert bhandu Linux - General 1 06-13-2007 04:19 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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