s_ladd
1
In Redhat it is easy....
date --date="60 minutes ago"
How do you do this in Solaris?
I got creative and got the epoch time but had problems..
EPOCHTIME=`truss date 2>&1 | grep "time()" | awk '{print $3 - 900}'`
echo $EPOCHTIME
TIME=`perl -e 'print scalar(localtime("$EPOCHTIME")), "\n"'`
echo $TIME
The output from "echo $EPOCHTIME" is correct however the output from "echo $TIME" is not correct. The $EPOCHTIME variable does not carry over.
That's because nothing expands inside single quotes.
Why not just do the entire thing in perl? time() gets you current time in epoch seconds.
s_ladd
3
My perl is about nonexistent.. LOL. I will look into it though.
Right from perldoc -f time you get this:
use POSIX qw(strftime);
$str=strftime "%a %b %e %H:%M:%S %Y", localtime;
which you can adapt into this:
perl -e 'use POSIX qw(strftime); print strftime "%a %b %e %H:%M:%S %Y\n", localtime(time()+$ARGV[0]);' -- -3600
The -3600 is the number of seconds to add, negative one hour.
s_ladd
5
That is a nice one liner.. Thank you sir.
I wouldn't call anything two terminal screens wide a "one-liner", but you're welcome.