1822000 Members
3667 Online
109639 Solutions
New Discussion юеВ

scripting in unix

 
keith demingware
Occasional Advisor

scripting in unix

I am running unix 11i and what i am trying to do is convert a # into # of days. In other words in the /tcb/files/auth/? directory there is a list of users with a password expiration warning #. I am trying to write a script that will take that number and convert it to the number of days. (example)

u_pw_expire_warning#1728000

When multiplying 60 seconds x 60 minutes x 24 you get 86400 x the number of days prior to expiration in this case 20 would = 1728000.

I hope there is an answer out there somewhere. I hope that this can be done in shell scripting.
just when you thought you had the answer
7 REPLIES 7
James R. Ferguson
Acclaimed Contributor

Re: scripting in unix

Hi Keith:

# perl -le 'print scalar localtime((time+1728000))'
Wed Dec 20 11:21:06 2006

Regards!

...JRF...
Patrick Wallek
Honored Contributor

Re: scripting in unix

Relatively simple:

NUM=1728000
DAY=86400

PWEXPWARNDAYS=$(echo ${NUM}/${DAY} | bc)

echo "You will be warned the password will expire ${PWEXPWARNDAYS} days before expiration"

James R. Ferguson
Acclaimed Contributor

Re: scripting in unix

Hi (again) Keith:

Sorry, I should generalize this to be more useful to you:

# perl -le 'print scalar localtime((time+$ARGV[0]))' 1728000

Regards!

...JRF...
Steven E. Protter
Exalted Contributor

Re: scripting in unix

Shalom,

There is a good script by our point leader A. Clay Stephenson that I use on Unix and ported to Linux.

The Date Hammer
http://hpux.ws/merijn/caljd-2.25.sh

http://hpux.ws/merijn/caljd-2.2.pl

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
A. Clay Stephenson
Acclaimed Contributor

Re: scripting in unix


typeset -i SECONDS=1728000
typeset -i DAYS=0

DAYS=$(( ${DAYS} / 86400 ))
echo "${SECONDS} seconds equals ${DAYS} days."

Note: The shell can only do signed 32-bit integer math so that for example 5/2 does not equal 2.5 but rather 2.
If it ain't broke, I can fix that.
Peter Godron
Honored Contributor

Re: scripting in unix

Keith,
please read
http://forums1.itrc.hp.com/service/forums/helptips.do?#33

then review your previous threads.

A shell solution:
#!/usr/bin/sh
number=$1
days=`expr $number / 86400`
echo $days

$ ./b.sh 1728000
20
spex
Honored Contributor

Re: scripting in unix

Hi,

If you can forgo the decimal:
$ echo $(( 1728000 / 86400 ))

If not:
$ echo "scale=2; 1728000 / 86400" | bc

PCS