Weird problem with output from "date '+3600*%H+60*%M+%S' "


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Weird problem with output from "date '+3600*%H+60*%M+%S' "
# 1  
Old 02-09-2006
Weird problem with output from "date '+3600*%H+60*%M+%S' "

Hi,

I came across a script a few months ago that allowed you to use the following script to include the current time into your prompt (useful from auditting purposes):

Code:
# Set Prompt
typeset -RZ2 _x1 _x2 _x3
let SECONDS=$(date '+3600*%H+60*%M+%S')
_s='(_x1=(SECONDS/3600)%24)==(_x2=(SECONDS/60)%60)==(_x3=SECONDS%60)'
TIME='"${_d[_s]}$_x1:$_x2"'
export PS1=${TIME}'${ME}:${PWD}:[$QM]# '

I've just noticed a really wierd problem on one server I'm using this on which is, if the time is before 10:00 an error occurs and the prompt is set to how many minutes you've been logged on. Logging on before 10:00 I get messages like this (the numbers change depending on the time:

Code:
09+60*53+48: 0403-009 The specified number is not valid for this command.
or
09+60*59+31: 0403-009 The specified number is not valid for this command.

After 10:00 this code works fine.

Anyone know what the problem might be?

Gareth
# 2  
Old 02-09-2006
Posix, in their wisdom has decreed that a number starting with a leading zero is to be interpreted as an octal number. So in a posix compliant shell, 09 is illegal. Smilie
# 3  
Old 02-15-2006
Thanks for this info.

Is there any way to adjust the script so any leading zero is removed?

Gareth
# 4  
Old 02-15-2006
Try forcing base 10:
let SECONDS=$(date '+3600*10#%H+60*10#%M+10#%S')
# 5  
Old 02-16-2006
Thanks, that worked. What's confusing me is why this script works in its original form before 10am on some servers but not on others. What should I check to see what's different between these servers and how do I check that?

Thanks
# 6  
Old 02-16-2006
Dave Korn did not possess the wisdom of Posix and he forgot to make integers with a leading 0 to be interpreted as octal. Thank goodness Posix came along to pick up the slack! Some of your systems still have a non-posix compliant korn shell and are willing to perform arithmetic on an integer like 08 and 09. A test? Just run the script in the original form prior to 10am.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Format output from the file to extract "date" section

Hello Team , I have to extract date section from the below file output. The output of the file is as shown below. I have to extract the "" this section from the above output of the file. can anyone please let me know how can we acheive this? (4 Replies)
Discussion started by: coolguyamy
4 Replies

2. Shell Programming and Scripting

problem in understanding the output of errpt -d H -T PERM -s `date +"%m%d%H00%y"`

Its very critical and 'm in need to schedule this on my crontab so that the output can be monitored by a tool I have written the command below to redirect the error which has the output redirected to the file gincle_lol.log. echo "---" >>/gingle/gincle_lol.log date... (1 Reply)
Discussion started by: Sounddappan
1 Replies

3. AIX

Problem in understanding the output of errpt -d H -T PERM -s `date +"%m%d%H00%y"`

Its very critical and 'm in need to schedule this on my crontab so that the output can be monitored by a tool I have written the command below to redirect the error which has the output redirected to the file gincle_lol.log. Code: echo "---" >>/gingle/gincle_lol.log date... (0 Replies)
Discussion started by: Sounddappan
0 Replies

4. Shell Programming and Scripting

"Join" or "Merge" more than 2 files into single output based on common key (column)

Hi All, I have working (Perl) code to combine 2 input files into a single output file using the join function that works to a point, but has the following limitations: 1. I am restrained to 2 input files only. 2. Only the "matched" fields are written out to the "matched" output file and... (1 Reply)
Discussion started by: Katabatic
1 Replies

5. UNIX for Dummies Questions & Answers

Explanation of "total" field in "ls -l" command output

When I do a listing in one particular directory (ls -al) I get: total 43456 drwxrwxrwx 2 root root 4096 drwxrwxrwx 3 root root 4096 -rwxrwxr-x 1 nobody nobody 3701594 -rwxrwxr-x 1 nobody nobody 3108510 -rwxrwxr-x 1 nobody nobody 3070580 -rwxrwxr-x 1 nobody nobody 3099733 -rwxrwxr-x 1... (1 Reply)
Discussion started by: proactiveaditya
1 Replies

6. AIX

xx=`date +"%a %b %d"`;rsh xxx grep "^$XX" zzz ?

AIX 4.2 I am trying to do an rsh grep to search for date records inside server logs by doing this : xx=`date +"%a %b %d"` rsh xxx grep "^$XX" zzz gives : grep: 0652-033 Cannot open Jun. grep: 0652-033 Cannot open 11. But if I do : xx=`date +"%a %b %d"` grep "^$XX" zzz it works... (2 Replies)
Discussion started by: Browser_ice
2 Replies

7. UNIX for Advanced & Expert Users

A question/problem about oracle "tns listener" and "enterprise manager"

hi, I have a problem about the Oracle related components. I'm not able to find any answer yet, and waiting for your responses... Here is the configuration of my system: * an IBM P550 machine, * an AIX 5.3 running on it and * an oracle database, already installed on it. The problem (or... (1 Reply)
Discussion started by: talipk
1 Replies

8. UNIX and Linux Applications

A question/problem about oracle "tns listener" and "enterprise manager"

hi, I have * an IBM P550 machine, * an AIX 5.3 running on it and * an oracle database, already installed on it. The problem (or question of my own) is: Oracle tns listener, "CT_LISTENER", and the enterprise manager (EM) of the instance, which is uniq instance and called... (0 Replies)
Discussion started by: talipk
0 Replies

9. UNIX for Advanced & Expert Users

add seconds to: date"|"time"|"HHMMSS

Hey all, I have a shell that invokes a AWK. In this AWK i want invoke a function that receives 3 parameters: date: 20080831 time: 235901 duration: 00023 that function receive this 3 parameters and sum to this value two more seconds: 2008083123590100025 Remember that in case that... (3 Replies)
Discussion started by: anaconga
3 Replies

10. Debian

Debian: doubt in "top" %CPU and "sar" output

Hi All, I am running my application on a dual cpu debian linux 3.0 (2.4.19 kernel). For my application: <sar -U ALL> CPU %user %nice %system %idle ... 10:58:04 0 153.10 0.00 38.76 0.00 10:58:04 1 3.88 0.00 4.26 ... (0 Replies)
Discussion started by: jaduks
0 Replies
Login or Register to Ask a Question