Weird date difference problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Weird date difference problem
# 15  
Old 03-12-2008
Also, I checked the /usr/bin directory and this is what i got

Code:
retailtest:RMST90:/u01/app/rms9.0/prd/oracle/proc/bin>ls /usr/bin/en*
/usr/bin/enable  /usr/bin/env

# 16  
Old 03-12-2008
Probably you haven't installed Python. Anyways, i would not suggest installing it just because the way to solving your problem is not obvious.

Probably this is what you really need.

I hope this helps.

bakunin
# 17  
Old 03-12-2008
Hopefully you have no problem. Try running the script this way:

Code:
python scriptname.py filename.xml

That should work. If it does not, run

Code:
which python

If there is no result, then you don't have Python on that system. In which case, I will be sad.

To fix my script (assuming you can run it by calling Python explicitly), try doing this:

Code:
which env

Whatever comes up is what you should replace the first line in my file with.

ShawnMilo
# 18  
Old 03-12-2008
okay - bad news - no python on the system.
good news - there is perl on the system - so maybe we can write a perl script to do the same - right now I am sitting with a perl book in my hands...Smilie
# 19  
Old 03-12-2008
Quote:
Originally Posted by meeraKh
okay - bad news - no python on the system.
good news - there is perl on the system - so maybe we can write a perl script to do the same - right now I am sitting with a perl book in my hands...Smilie
Okay, here are the guts. See if this executes on your system:

Code:
perl -e 'use Time::Local; $fileDate = timelocal(0, 0, 0, 12, 2, 2008); $now = time(); $diff = ($now - $fileDate) / (24*60*60); print "The file is $diff days old.\n"'

Note: The month must be decremented by one, because timelocal uses months 0-11 instead of 1-12.

If that command works on your system, then you should be able to piece the rest of the Perl script together around it without too much trouble.

ShawnMilo
# 20  
Old 03-12-2008
Smilieyippeee!!!
this worked - it gave me the following output :

The file is 0.603263888888889 days old.


so i guess this was testing against 03/12/2008 00:00:00 - so I can pass my date that i extract to the file as parameters to this perl program and return the difference back to my shell script, right??

Thanks again for your help - I might bug you again if i have trouble with writing the perl program...Smilie
# 21  
Old 03-12-2008
Quote:
Originally Posted by meeraKh
Smilieyippeee!!!
this worked - it gave me the following output :

The file is 0.603263888888889 days old.


so i guess this was testing against 03/12/2008 00:00:00 - so I can pass my date that i extract to the file as parameters to this perl program and return the difference back to my shell script, right??

Thanks again for your help - I might bug you again if i have trouble with writing the perl program...Smilie
Yay!

Yes, you are correct about it comparing it to midnight.

Feel free to ask questions. You should pretty much be able to use the Python script as a framework and replace each line with Perl. I would do it myself, but today is a busier day at work than yesterday was.

I'm still bummed that you don't have Python, though. It's so much nicer to work with than Perl -- especially for a beginner. Perl rocks for the super-dense one-liners and regex-intensive short scripts, but Python is cleaner and easier to learn.

ShawnMilo
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Weird awk problem

Hi, I have a simple awk script: BEGIN{} { $a=$2-$1; print $a } END{if(NR==0){ print "0" } } to which I provide the following input 2.9 14 22.2 27 (4 Replies)
Discussion started by: jamie_123
4 Replies

2. Shell Programming and Scripting

Weird difference in script execution

Hi, So I have a very simple script which loops over 5 times and prints the iterator value. #!/bin/sh START=1 END=5 for i in $(eval echo "{$START..$END}") do echo "$i" done If I save this script in a .sh file and run it in the terminal, the output I get is {1..5} (4 Replies)
Discussion started by: jamie_123
4 Replies

3. Shell Programming and Scripting

A very weird problem about getting a random string

Hi, guys Here is my script and it's an imaginary script to recast a string randomly. #!/bin/bash # scriptname: recast_string # purpose: recast a string randomly like this "abc123" --> "21a3cb" or "a31b2c" function recast() { local original_string=$1 local... (4 Replies)
Discussion started by: franksunnn
4 Replies

4. Programming

A weird problem with POSIX function

Hi all, Sorry for the title because I didn't find a proper name for it. My question is about POSIX functions, such as timer_create(), mq_open() and pthread_create(). void test_queue() { struct mq_attr attr; attr.mq_maxmsg = 10; attr.mq_msgsize = 64; mq_unlink("/my_test_queue");... (6 Replies)
Discussion started by: bus147
6 Replies

5. Shell Programming and Scripting

awk weird problem.

awk 'BEGIN{print 1.2.3.4}' 1.20.30.4 Can anyone explain why has extra "0" in the IP address? (3 Replies)
Discussion started by: newoz
3 Replies

6. Infrastructure Monitoring

Weird dependency problem!

Hi, I want to install net-snmp-devel package but i have following dependecy problem. It's very odd, i don't get it. One of packages is depended on the other one, the other one is depended on the previous one as well. :S :S Could you help me please? Here are the steps: # ls -l total... (4 Replies)
Discussion started by: oduth
4 Replies

7. UNIX for Advanced & Expert Users

Really weird delete problem

Hi, I've Ubuntu 8.04, and it has some files that I just cannot delete. I've tried everything, inode, fsck etc. Here is what the ls -li outputs root@ubuntu:/home/luser/.local/share/Trash/files/junk# ls -l ls: cannot access TRUNK_: No such file or directory ls: cannot access 2006_output.mv:... (11 Replies)
Discussion started by: nitin
11 Replies

8. Solaris

Weird crontab problem

Greetings To All! I am running Solaris 10 in a sparc environment. Here is the deal: In /var/spool/cron/crontabs, there is a cron user named "sys". If I do a crontab -l sys, it returns: # 0 * * * 0-6 /usr/lib/sa/sa1 # 20,40 8-17 * * 1-5 /usr/lib/sa/sa1 # 5 18 * * 1-5 /usr/lib/sa/sa2... (8 Replies)
Discussion started by: RobSand
8 Replies

9. Shell Programming and Scripting

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): # Set Prompt typeset -RZ2 _x1 _x2 _x3 let SECONDS=$(date '+3600*%H+60*%M+%S')... (5 Replies)
Discussion started by: m223464
5 Replies

10. UNIX for Dummies Questions & Answers

Weird Problem???

I have a problem I don't understand... I am trying to declare a variable, and then output the results of that variable, couldn't be simpler #!/bin/ksh VAR='Oranges' if then echo "Found Lemons" elif then echo "Found Oranges" fi The output shouold clearly be "Found Oranges", but... (2 Replies)
Discussion started by: danhodges99
2 Replies
Login or Register to Ask a Question