I've created quite a simple script shell script to produce an output on when a user last logged in to one of our systems, an IBM p570 running AIX 5.3 TL10, or at least I've produced a script that isn't doing what I want it to...
It goes something like this.
For USER in `cat /etc/passwd | cut -d: -f1`
do
LASTCHANGE1=`grep -p ${USER} /etc/security/passwd | grep lastupdate | awk '{print $3}'`
LASTCHANGE2=`/usr/bin/perl -le 'print scalar localtime ${LASTCHANGE1}'`
done
The problem is this only works if I don't script it. On the command line for example:
grep -p forberd /etc/security/passwd | grep lastupdate | awk '{print $3}'
returns 1252399094
Then using the 2nd part
/usr/bin/perl -le 'print scalar localtime 1252399094'
returns Tue Sep 8 09:38:14 2009
So I know the actual working of it are OK, and it's to do with my scripting. :-( Using the scripting above I get:
LASTCHANGE1=`grep -p forberd /etc/security/passwd | grep lastupdate | awk '{print $3}'`
echo $LASTCHANGE1
returns 1252399094
LASTCHANGE2=`/usr/bin/perl -le 'print scalar localtime ${LASTCHANGE1}'`
echo £LASTCHANGE2
returns Thu Jan 1 00:00:00 1970
Can anyone tell me why setting the time using a variable for this perl function fails, and even better, how to get around it?
Thanks.
It goes something like this.
For USER in `cat /etc/passwd | cut -d: -f1`
do
LASTCHANGE1=`grep -p ${USER} /etc/security/passwd | grep lastupdate | awk '{print $3}'`
LASTCHANGE2=`/usr/bin/perl -le 'print scalar localtime ${LASTCHANGE1}'`
done
The problem is this only works if I don't script it. On the command line for example:
grep -p forberd /etc/security/passwd | grep lastupdate | awk '{print $3}'
returns 1252399094
Then using the 2nd part
/usr/bin/perl -le 'print scalar localtime 1252399094'
returns Tue Sep 8 09:38:14 2009
So I know the actual working of it are OK, and it's to do with my scripting. :-( Using the scripting above I get:
LASTCHANGE1=`grep -p forberd /etc/security/passwd | grep lastupdate | awk '{print $3}'`
echo $LASTCHANGE1
returns 1252399094
LASTCHANGE2=`/usr/bin/perl -le 'print scalar localtime ${LASTCHANGE1}'`
echo £LASTCHANGE2
returns Thu Jan 1 00:00:00 1970
Can anyone tell me why setting the time using a variable for this perl function fails, and even better, how to get around it?
Thanks.