- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Shell script: How to obtain future date
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-05-2001 03:46 AM
тАО07-05-2001 03:46 AM
Does anyone have a suggestion to an easy way of generating the following output:
THE DATE AND TIME 3 DAYS LATER THAN THE PRESENT DATE AND TIME.
I need it for producing a script, that creates a user which expires date 3 days later. One approch would be to obtain the date, via the 'date' command, but it would then be nescessary to somehow convert the string '07' (e.g. output of 'date +%m') to the integer 7.
Your help is appreciated!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-05-2001 04:17 AM
тАО07-05-2001 04:17 AM
Re: Shell script: How to obtain future date
Try this :
#
TAG_=`date +'%y%m%d'`; export TAG_
export TAG1="000000"
TAG1=`expr $TAG_ + 1`
echo $TAG1
Rgds
Alexander M. Ermes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-05-2001 04:48 AM
тАО07-05-2001 04:48 AM
Re: Shell script: How to obtain future date
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-05-2001 05:00 AM
тАО07-05-2001 05:00 AM
Re: Shell script: How to obtain future date
let TAG1=$TAG_+1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-05-2001 05:06 AM
тАО07-05-2001 05:06 AM
Re: Shell script: How to obtain future date
as date calculations sometimes can get a bit tricky, and since most standard shells (except for bash, zsh etc.) have only limited arithmetic functionality, I would suggest doing it with Perl.
(Perl should be on any decent Unix box ;-)
e.g.
$ perl -e 'printf "%s\n",scalar localtime(time + 3*86400)'
If you need some fancier formatting you would have to invoke localtime() in list context.
See the POD for what localtime returns (i.e. $ perldoc -f localtime)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-05-2001 05:09 AM
тАО07-05-2001 05:09 AM
Re: Shell script: How to obtain future date
TAG1=`expr $TAG_ + 1`
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-05-2001 05:39 AM
тАО07-05-2001 05:39 AM
Re: Shell script: How to obtain future date
TAG1=`expr $TAG_ + 1` result in syntax errors.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-05-2001 06:12 AM
тАО07-05-2001 06:12 AM
Solutionput you a C-Source at attachment.
Save it ie: under /usr/local/src/fdate.c
Compile it ie:
cc /usr/local/src/fdate.c -o /usr/local/bin/fdate
Use it ie: 3 days forward:
fdate 3
You can also compute backwards with ie:
fdate -3
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-05-2001 06:38 AM
тАО07-05-2001 06:38 AM
Re: Shell script: How to obtain future date
I has a technique that you will find very useful. It involves converting a date into a truncated Julian Day (more or less the number of days since Jan 1, 4712 BCE; it's used by astronomers to make life simple). In your case, it takes care of month,year,leap year boundaries with ease.
The script I've attached will convert a calender date into a Julian Day and also do the inverse. It also has an argument to calculate the day of the week. Invoke the script as caljd.sh -u for full usage.
In your case I would do it like this:
INC=3
JD=`caljd.sh`
JD=$((${JD} + ${INC}))
CAL_DATE=`caljd.sh ${JD}`
This will calculate 3 days after the current date. If you supply the first call to caljd.sh
with MM DD YYYY it will calculate 3 days after that date. The number of args is how caljd.sh knows to convert from calendar to julian day or julian day to calendar date.
Regards, Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-05-2001 10:32 PM
тАО07-05-2001 10:32 PM
Re: Shell script: How to obtain future date
cc: "fdate.c", line 2: error 1000: Unexpected symbol: "i".
cc: "fdate.c", line 2: error 1002: Unexpected character: 'u'.
cc: "fdate.c", line 2: error 1000: Unexpected symbol: "<".
cc: "fdate.c", line 2: error 1000: Unexpected symbol: ".".
cc: "fdate.c", line 2: error 1000: Unexpected symbol: ">".
cc: "fdate.c", line 16: error 1588: "stdout" undefined.
How come?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-06-2001 01:29 AM
тАО07-06-2001 01:29 AM
Re: Shell script: How to obtain future date
this may be a bug when putting something at attachment.
The first line of the file is inserted with tabs.
So delete the inserted tabs so that it looks like:
#include
#include
.
.
.
.
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-09-2001 02:24 AM
тАО07-09-2001 02:24 AM
Re: Shell script: How to obtain future date
#!/usr/bin/sh
#
# futuredate.sh
#
###############################################################################
NINETH=`perl -e 'printf "%s",scalar localtime(time + 5*86400)'|cut -c9`
if [ "$NINETH" = " " ]
then
NEWDATE=0`perl -e 'printf "%s",scalar localtime(time + 5*86400)'|cut -c10`
else
NEWDATE=`perl -e 'printf "%s",scalar localtime(time + 5*86400)'|cut -c9-10`
fi
MONTH=`perl -e 'printf "%s",scalar localtime(time + 5*86400)'|cut -c5-7`
case $MONTH in
Jan) NEWMONTH=01 ;;
Feb) NEWMONTH=02 ;;
Mar) NEWMONTH=03 ;;
Apr) NEWMONTH=04 ;;
May) NEWMONTH=05 ;;
Jun) NEWMONTH=06 ;;
Jul) NEWMONTH=07 ;;
Aug) NEWMONTH=08 ;;
Sep) NEWMONTH=09 ;;
Oct) NEWMONTH=10 ;;
Now) NEWMONTH=11 ;;
Dec) NEWMONTH=12 ;;
esac
NEWYEAR=`perl -e 'printf "%s",scalar localtime(time + 5*86400)'|cut -c23-24`
echo ${NEWDATE}/${NEWMONTH}/${NEWYEAR}