Problem with time


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem with time
# 1  
Old 04-14-2005
Problem with time

(let me re-edit my question)

This works
Code:
#!/bin/sh
awk 'BEGIN {print mktime("2005 07 01 34 30")}

This doesnt
Code:
#!/bin/sh
TIME="2005 07 01 34 30"
awk 'BEGIN {print mktime($TIME)}

what could be the problem? arent they the same thing?

Last edited by strike; 04-14-2005 at 10:15 AM..
# 2  
Old 04-14-2005
Neither will run as you present it. Adding a closing quote and a file, I tried this on SunOS:
awk 'BEGIN {print mkzzzime("2005 07 01 34 30")}' < /dev/null
and I got:
2005 07 01 34 30

There is no such thing as mkzzzime in awk, but there is no mktime either. awk on SunOS is ignoring a bogus function. On HP-UX, I get:
awk: Function mktime is not defined.
The source line number is 1.

Your sh knows about a variable called TIME, but your awk does not. Even if it did, that's not how you use a variable in awk. You might try something like:
p=987
awk -v p=$p 'BEGIN {print p}' < /dev/null

See the faq section, specificly,
Passing variables/arguments/parameters to commands.
# 3  
Old 04-14-2005
hmmz strange, im using SunOS as well and mktime is defined,

the first code returns "1102738530" (which is correct)

where the second code returns "-1"

strange indeed. Smilie
# 4  
Old 04-14-2005
Quote:
Originally Posted by strike
hmmz strange, im using SunOS as well and mktime is defined,

the first code returns "1102738530" (which is correct)

where the second code returns "-1"

strange indeed. Smilie
what awk are you using on SunOS: awk, nawk, /usr/xpg4/bin/awk, gawk?

''mktime' is only supported by gawk - check your ${PATH} and make sure your 'awk' is not linked to gawk.
# 5  
Old 04-14-2005
oh yes, it is linked to gawk i just checked ...
but the result still remains the same.
# 6  
Old 04-14-2005
Quote:
Originally Posted by man gawk
mktime(datespec)
Rurns datespec into a time stamp of the same form
as returned by systime(). The datespec is a
string of the form YYYY MM DD HH MM SS[ DST].
Code:
#!/bin/sh
TIME="2005 07 01 34 30 10"
gawk -v t="${TIME}" 'BEGIN {print mktime(t)}'

# 7  
Old 04-15-2005
ahhh BINGO!
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem with epoch time

Hi All, I have a weird problem. I have a session log which is in .bin format. I am converting the .bin file to xml format using Informatica(it is an ETL tool) and unix functionality called "convertLogFiles" . All this is working fine. The session log has a date column. After converting the log... (3 Replies)
Discussion started by: galaxy_rocky
3 Replies

2. AIX

NTP time problem

I got an ntp time problem on AIX server. os version is AIX7.1 OS LEVEL 7.1.0.0 i got below output,when i run the below command bash-3.2# ntpdate -dv XXXXXXXXXXXXXXXXXXXXXXXX 4 Dec 12:50:49 ntpdate: 3.4y transmit(xxxxxxxxx) receive(xxxxxxxxx) transmit(xxxxxxxx) receive(xxxxxxxxx)... (9 Replies)
Discussion started by: murali969
9 Replies

3. Shell Programming and Scripting

Solaris Time Problem

Hi all, I am printing yesterday date in solaris using command: TZ=GMT+24 date +%b_%d_%Ybut at 01:00 AM on jan 11, it is printing: Anyone please explain. (1 Reply)
Discussion started by: anand2308
1 Replies

4. Emergency UNIX and Linux Support

Time delay problem in asking password

Hi All, I have solaris-11 global and multiple non-global zones running, which all are on same network. They are not in NIS. When we open putty session and give user-name, it takes long time in asking password (around 40-50 seconds) on Global zone. While on non-global zones, it is working... (9 Replies)
Discussion started by: solaris_1977
9 Replies

5. UNIX for Advanced & Expert Users

problem with converting time using perl

Hello, I have an AIX 5.3 system and i created a script to get the last login of users. The script goes like this: LAST_LOGIN=`lsuser -a time_last_login $cur_user` TIME_LOGIN=`perl -e 'print scalar localtime("$LAST_LOGIN")'` Actually what i do in these two lines is to set a variable... (2 Replies)
Discussion started by: omonoiatis9
2 Replies

6. Programming

problem with real-time

hello every1, i'm very hope so anyone here have experience with lib rt like aio linux based. In first I've a problem with receiving data from aio_buf, i.e. I have received it, but if the next data size less then pervious I've got a noise from a socket. I've tried to fix it by different ways, but... (0 Replies)
Discussion started by: quant
0 Replies

7. Shell Programming and Scripting

Date time problem

Hi Guys, I have a file a.txt Start Date/Time End Date/Time from Prob_Dura. ----------------- ----------------- ----- ------ 20090525 23:58:59 20090526 00:00:00 machine1 000051 20090525 23:58:09 20090526 00:00:11 machine2 000150 The perl or shell script can: 1. remove... (4 Replies)
Discussion started by: jimmy_y
4 Replies

8. Shell Programming and Scripting

cron problem for getting the time

Grateful if anyone could answer my question The script called time.sh try to retrive the server time on another server and write into a files named "abc.123" as show below. time.sh #!/bin/sh telnet 10.122.38.109 13 | tail -1 >/tmp/abc.123 The result when run on console or any active... (4 Replies)
Discussion started by: darkrainbow
4 Replies

9. Shell Programming and Scripting

problem doing the time calculations in shell.

I am trying to do a shell script to monitor if any files went through in the last hour. There is a script in cron that runs every sec checking to see if a file is there and ftp the file out of this folder. Now I just want to add a block of code that will check to see no files went in the last... (3 Replies)
Discussion started by: jonathan184
3 Replies
Login or Register to Ask a Question