The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`" Lokesha UNIX for Dummies Questions & Answers 4 12-20-2007 01:52 AM
Debian: doubt in "top" %CPU and "sar" output jaduks Debian 0 09-12-2007 09:05 AM
a weird issue with "while" block sleepy_11 Shell Programming and Scripting 7 08-07-2007 12:33 AM
Sorting problem "sort -k 16,29 sample.txt > output.txt" ganapati Shell Programming and Scripting 3 08-01-2006 06:55 AM
Unix "at" / "Cron" Command New Problem...Need help Mohanraj UNIX for Dummies Questions & Answers 3 01-26-2006 08:08 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-09-2006
m223464 m223464 is offline
Registered User
  
 

Join Date: Mar 2005
Posts: 41
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 (permalink)  
Old 02-09-2006
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,126
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.
  #3 (permalink)  
Old 02-15-2006
m223464 m223464 is offline
Registered User
  
 

Join Date: Mar 2005
Posts: 41
Thanks for this info.

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

Gareth
  #4 (permalink)  
Old 02-15-2006
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,126
Try forcing base 10:
let SECONDS=$(date '+3600*10#%H+60*10#%M+10#%S')
  #5 (permalink)  
Old 02-16-2006
m223464 m223464 is offline
Registered User
  
 

Join Date: Mar 2005
Posts: 41
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 (permalink)  
Old 02-16-2006
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,126
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.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:07 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0