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 " ") |
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. |
Thanks Towheedm, I am running as a root only.
|
Are you getting the error while running as root?
|
yeup, getting the error while running as the root.
|
Try passing a username as an argument to the script. I'll pass user lfs to the script:
Code:
sudo ./user_expiry.sh lfs Code:
#! /bin/bash |
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 " ") |
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}'` Code:
uname=`cat /etc/shadow | grep -r "^$name:" | awk -F":" '{print}'` Code:
root@CW9:~# wc -l /etc/passwd EDIT2: The script could be modified to generate an error message for users not listed in /etc/shadow Code:
if [[ $uname = '' ]]; then |
What do you get from pwck ?
|
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 |
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" |
Quote:
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 {}. |
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. |
That link is malformed. It results in "Unexpected response code received". The ... appears in the underlying link as well as the displayed link.
|
All times are GMT -5. The time now is 12:13 AM. |