python test datetime 30 minutes ago


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting python test datetime 30 minutes ago
# 1  
Old 01-05-2012
python test datetime 30 minutes ago

Hello,
RHEL5.5
PYTHON=2.4.3

I have 2 python variables using the datetime module.

Here is how I call them:
Code:
print "Current Time:       %s" % now
print "LastDownloadTime:   %s" % LastDownloadTime

Here is an example of an issue.
Code:
Current Time:       2012-01-05 14:06:09.749240
LastDownloadTime:   2012-01-05 13:06:58.710000

The logic that I am after is:
1) If ‘LastDownloadTime' is less than 30 minutes ago, everything is fine.
In my above example, I should be printing we have an issue since last download time is over 30 minutes ago.

Here is what I have tried with no luck. If any python experts can help?

Code:
if  LastDownloadTime-now < datetime.timedelta(0,30):

    print "All is ok"

    sys.exit(0)

else:

    print "We have an issue"

    sys.exit(2)

I am sure that I have the logic incorrect. Since I am unable to get my expected results.

jaysunn
# 2  
Old 01-05-2012
If you don't get any responses, you might be better off posting this at python-forum.
This User Gave Thanks to ryran For This Post:
# 3  
Old 01-05-2012
I was able to see my own mistake. I used the following in case it helps others.
Thanks

Code:
print "FilesToDownload:    %s" % FilesToDownload

print "FileSizeToDownload: %s" % FileSizeToDownload



if  now-LastDownloadTime < datetime.timedelta(0,1800):

    print "All is ok"

    sys.exit(0)

else:

    print "We have an issue"

    sys.exit(2)

Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep a log file for the last 5 minutes of contents every 5 minutes

Hi all, System Ubuntu 16.04.3 LTS i have the following log INFO 2019-02-07 15:13:31,099 module.py:700] default: "POST /join/8550614e-3e94-4fa5-9ab2-135eefa69c1b HTTP/1.0" 500 2042 INFO 2019-02-07 15:13:31,569 module.py:700] default: "POST /join/6cb9c452-dcb1-45f3-bcca-e33f5d450105... (15 Replies)
Discussion started by: charli1
15 Replies

2. UNIX for Beginners Questions & Answers

How to convert days hours minutes seconds to minutes?

Hi, please help with below time conversion to minutes. one column values: 2 minutes 16 seconds 420 msec 43 seconds 750 msec 0 days 3 hours 29 minutes 58 seconds 480 msec 11 seconds 150 msec I need output in minutes(total elapsed time in minutes) (2 Replies)
Discussion started by: ramu.badugula
2 Replies

3. UNIX for Beginners Questions & Answers

How to find a file that's modified more than 2 days ago but less than 5 days ago?

How to find a file that's modified more than 2 days ago but was modified less than 5 days ago by use of any Linux utility ? (4 Replies)
Discussion started by: abdulbadii
4 Replies

4. Shell Programming and Scripting

Ping test using python

I am issuing a reboot command to a client server from admin server using my python function. I am able to do that but now I need do a ping test every second and print if the ping is successful. With the below code I can check ping only once. import os hostname = "myclient" response =... (7 Replies)
Discussion started by: ctrld
7 Replies

5. Shell Programming and Scripting

Check how many minutes ago the last file created

Hi , I need help in getting how many minutes ago the last file, matching some pattern in file name, was created in a folder. Thanks in advance. (8 Replies)
Discussion started by: Anupam_Halder
8 Replies

6. Shell Programming and Scripting

Add minutes in Datetime Variable in Unix

Hi, New to scripting. I have datetime as a String and I need to add some hours/minutes in to that. 21/10/2009 23:00:00 After adding 180 minutes; it will look like this 22/10/2009 02:00:00 Regards, Vikas Mahajan (9 Replies)
Discussion started by: vikas482
9 Replies
Login or Register to Ask a Question