- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: Need help with script and shell math (HPUX 11...
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
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
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
тАО02-13-2007 04:20 AM
тАО02-13-2007 04:20 AM
If the script does not specify "/usr/bin/ksh" as the first line (thus defaulting to the "sh" shell), it calculates something but the date is incorrect during julian dates through 099 because the sh shell thinks the julian date represents an octal number. Once we hit 100 and there is no leading zero, all is well.
If I do specify the "ksh" shell, the script does not appear to hold on to the variable (or maybe nothing is calculated to begin with). The script works fine (meaning the variable is populated) if it is run in *interactive mode*, but when it runs under *cron* there is nothing passed to the paragraph.
Here is an example of what I am trying to do:
S2007=14246
.
.
# Generate current date in internal format
# (We take the current year and prepend an
# "S" to get the first day of the year
# from the above table. Then we add the
# current Julian date to the first
# day of the year (minus 1 since Jan 1 is
# day 1 on the Julian calenar.)
idate=$((S$(date +%Y) + $(date +%j) -1))
Can anybody help me with this?
Solved! Go to Solution.
- Tags:
- date arithmetic
- octal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-13-2007 04:53 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-13-2007 04:53 AM
тАО02-13-2007 04:53 AM
Re: Need help with script and shell math (HPUX 11)
- I would really declare your variable(s) Snnnn as integer:
typeset -i S2007=14246
date=$((S$(date +%Y) + $(date +%j) -1))
Else there may be an additional 'eval' necessary.
- Make shure, your locale settings do not interfere; put something like that at the beginning of your scr ipt:
export LC_TIME=C LC_NUMERIC=C
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-13-2007 05:16 AM
тАО02-13-2007 05:16 AM
Re: Need help with script and shell math (HPUX 11)
# unset UNIX95
# S2007=14246
# echo $((S$(date +%Y) + $(date +%j) -1))
14289
# export UNIX95=1
# echo $((S$(date +%Y) + $(date +%j) -1))
14281
Yup, chalk up another one!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-13-2007 05:17 AM
тАО02-13-2007 05:17 AM
Re: Need help with script and shell math (HPUX 11)
Now I just need to figure out what the "-3" does...but that is purely research.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-13-2007 06:14 AM
тАО02-13-2007 06:14 AM
Re: Need help with script and shell math (HPUX 11)
In fact, to add to Bob's comments, the 'sh-posix' manpages document the UNIX95 behavior (see the section on arithmetic evaluation):
/*begin_quote*/
Arithmetic expressions given with let command, ((...)), and $((...)) will be processed according to ISOC standard with the exception of ++, --, ?:, and , operators. Integer constants beginning with 0 and 0x (or 0X) will be recognised as octal and hexadecimal numbers by these evaluators only if environment variable UNIX95 is defined.
/*end_quote*/
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-13-2007 06:35 AM
тАО02-13-2007 06:35 AM
Re: Need help with script and shell math (HPUX 11)
Any idea why adding the shell declaration at the top of the script to force "ksh" would cause the idate variable to be empty?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-13-2007 07:06 AM
тАО02-13-2007 07:06 AM
Re: Need help with script and shell math (HPUX 11)
The leading 0 = octal problem has been around for a long time. Back in the days of minicomputers with 8bit processors, almost everyone used octal notation, even dividing a 16bit front panel display into 5 groups of 3bit 'tribles' plus a single bit. So a leading zero became the defacto standard to flag octal numbers.
Unfortunately, it was not 100% implemented and octal numbers are extremely difficult to decode 8bit characters. Thus, hex numbers became much more commonplace and there is no mistaking the hex flag 0x.
All that said, the sh-posix patch PHCO_25597 (11.11) and PHCO_26789 (11.00) fixes the long-standing error in following the ISOC standard for octal number interpretation. Indeed, when the patches were released, it exposed errors in old rc start scripts that used leading zeros. Luckily, the scripts referred to 08 and 09 (both illegal octal numbers) and the scripts flagged themselves in /etc/rc.log.
This is one of the strong reasons to use typeset for numeric variables and computation, then format the result with typeset -Z when necessary.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-13-2007 10:18 AM
тАО02-13-2007 10:18 AM
Re: Need help with script and shell math (HPUX 11)
$ echo $((5 + 010))
13
$ echo $((5 + 10#010))
15