On 10/30/14 13:56, Vijay Sankar wrote:
> Quoting Alexander Hall <alexan...@beard.se>:
> 
>> On October 30, 2014 1:26:25 PM CET, Vijay Sankar <vsan...@foretell.ca>
>> wrote:
>>> I have been using a simple script
>>>
>>> # mypasswd.sh
>>> /usr/bin/passwd -l
>>> if [[ $? != 0 ]]; then
>>>         /usr/bin/logger "Unsuccessful attempt to change password"
>>> else
>>>         /usr/bin/logger "Changed login password"
>>> fi
>>>
>>> to get syslog entries whenever I change my password. I looked for a
>>> better way but could not find any solutions for this in the archives.
>>>
>>> Is there a better way to do this? Please let me know if possible.
>>
>> Unless there is any functionality you're missing, and scripting nits
>> aside, this seems fine.
>>
>> Please elaborate on why you think it shouldn't be.
>>
>> /Alexander
>>>
>>> Thanks very much,
>>>
>>> Vijay


Hi Vijay,

your script didn't work for me with /bin/sh so I modified it, and
changed the logger's to echos so that I don't pollute my logs.  I have
found a small race in your script and I'd like to address it with an
expect script I wrote for you:

#!/usr/local/bin/expect --

spawn ./vijays-mypasswd.sh
expect Changing
stty cooked
expect Old?password:
send \n
send "^C"
stty raw
expect -re ^Unsuccessful


Also I have provided to you my version of vijays-mypasswd.sh

----
#!/bin/sh

trap "" 2

/usr/bin/passwd -l
if [ $? -eq 0 ]; then
        echo "Unsuccessful attempt to change password"
else
        echo "Changed login password"
fi
----


Notice the trap, hash it out to see what doesn't happen.

Regards,

-peter

Reply via email to