Unable to convert passwd lastupdate value into scalar local format


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Unable to convert passwd lastupdate value into scalar local format
# 1  
Old 11-21-2012
Unable to convert passwd lastupdate value into scalar local format

Dear all,

I am unable to get the desired result upon executing the below script. the problem is at `perl -le 'print scalar localtime $msecage'` ouput which gives the following result "Thu Jan 1 05:00:00 1970" instead of "Tue Nov 13 10:30:56 2012" but when I run the same command from shell prompt by putting the actual value infront of perl localtime perl -le 'print scalar localtime 1352784656 it gives the correct result.

Please help



Code:
#!/usr/bin/ksh

################# This script will print the User Password Max Age, Last Change, Calculate Passwd expiry#####

mxage=`sudo lsuser -a maxage ahd11542|awk -F= '{print $2}'` 

mxlastupdate=`sudo lssec -f /etc/security/passwd -a lastupdate -s ahd11542 |awk '{print $2}'|cut -b 12-`

msec=` expr 604800 \* $mxlastupdate`

msecage=`expr $msec + $mxlastupdate`

expiredate=`perl -le 'print scalar localtime $msecage'`


#############DISPLAY OUTPUT#################

echo "Max age is:" $mxage

echo "Last Change is:" $mxlastupdate

echo "Last Change in localtime is:" `perl -le 'print scalar localtime $mxlastupdate'`

echo "Max Age in Seconds:" $msecage

echo " Expiration Date is:"$expiredate

# 2  
Old 11-21-2012
Hi

mxlastupdate is a shell variable which you are trying to access in Perl directly which will not work.

Code:
export mxlastupdate
echo "Last Change in localtime is:" `perl -le 'print scalar localtime $ENV{'mxlastupdate'}'`

Export the variable in shell, and use the ENV hash in perl to access the env variable.


Guru.
This User Gave Thanks to guruprasadpr For This Post:
# 3  
Old 11-21-2012
use double quotes

Code:
echo "Last Change in localtime is:" `perl -le "print scalar localtime $mxlastupdate"`

This User Gave Thanks to itkamaraj For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Unable to change the passwd

bash-3.00# passwd sami New Password: Re-enter new Password: Dec 14 00:07:43 hack passwd: passwdutil: crypt_gensalt Invalid argument passwd: Unexpected failure. Password database unchanged. Permission denied i got this error while i am change the user(sami) passwd. (3 Replies)
Discussion started by: samiulla
3 Replies

2. Shell Programming and Scripting

perl module to convert xlsx format to xls format

Hi Folks, I have written a perl script that reads data from excel sheet(.xls) using Spreadsheet::ParseExcel module. But the problem is this module doesn't work for excel sheets with extension .xlsx. I have gone through Spreadsheet::XLSX module with which we can read from .xlsx file directly.... (1 Reply)
Discussion started by: giridhar276
1 Replies

3. Solaris

tool to convert /etc/passwd and etc/shadow

i wonder if there is a tool to read the /etc/passwd or /etc/shadow files in order to reset user accounts to the same one. By moving (restore) all filessytem and data to another same Sun box, none of the users are able to logon to the new box which i didn't change nothing. But if i reset the user... (1 Reply)
Discussion started by: lamoul
1 Replies

4. UNIX for Advanced & Expert Users

need to convert passwd file to .htpasswd

I need to take our unix password file and make the usernames and passwords in a .htpasswd file to protect some webpages. I really dont want to type them in. Any suggestions how I do this? /---Frank----/ (4 Replies)
Discussion started by: frankkahle
4 Replies

5. UNIX for Dummies Questions & Answers

To convert multi format file to a readable ascii format

Hi I have a file which has ascii , binary, binary decimal coded,decimal & hexadecimal data with lot of special characters (like öƒ.ƒ.„İİ¡Š·œƒ.„İİ¡Š· ) in it. I want to standardize the file into ASCII format & later use that as source . Can any one suggest a way a logic to convert such... (5 Replies)
Discussion started by: gaur.deepti
5 Replies

6. UNIX for Dummies Questions & Answers

Convert UTF8 Format file to ANSI format

:confused: Hi i am trying to convert a file which is in UTF8 format to ANSI format i tried to use the function ICONV but it is throwing error Function i used it as $ iconv -f UTF8 -t ANSI filename Error iam getting is NOT Supported UTF8 to ANSI please some help me out on... (9 Replies)
Discussion started by: rajreddy
9 Replies

7. UNIX for Advanced & Expert Users

Convert UTF8 Format file to ANSI format

:) Hi i am trying to convert a file which is in UTF8 format to ANSI format i tried to use the function ICONV but it is throwing error Function i used it as $ iconv -f UTF8 -t ANSI filename Error iam getting is NOT Supported UTF8 to ANSI please some help me out on this.........Let me... (1 Reply)
Discussion started by: rajreddy
1 Replies

8. Shell Programming and Scripting

convert mmddyy date format to ccyyddd format??

hi, for reading a cobol indexed file i need to convert "mmddyy" date format to "ccyyddd" format. i checked the datecalc and other scripts but couldnt modify them to cater to my need:(... The datecalc gives an output which i believe is the total days till that date, but i want to convert it... (2 Replies)
Discussion started by: Bhups
2 Replies

9. AIX

How do I read username and lastupdate attribute values from /etc/security/passwd

Hi, How do I read username and lastupdate attribute values from /etc/security/passwd file and write the obtained data to another file. The data in the new file should be in this format as shown: avins:12345 root:45234 xyza:23423 Plese let me know this ASAP Thanks, Haroon (3 Replies)
Discussion started by: me_haroon
3 Replies

10. AIX

I want to read username and lastupdate only from /etc/security/passwd and write the s

Hi All, As i asked you in my previous post, I want to read username and lastupdate only from /etc/security/passwd and write the same data to another file: The data in /etc/security/passwd will be in this form for example: smith: password = MGURSj.F056Dj lastupdate = 623078865 flags =... (0 Replies)
Discussion started by: me_haroon
0 Replies
Login or Register to Ask a Question