Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with script 1

Status
Not open for further replies.

spamfree

Programmer
Oct 25, 2002
39
IE
Hi,
I want to copy a file to the web directory if it's greater than a certain size. The file size is always > 15K
The following runs without any errors, but fails to copy the file in question.
------------------------------------------------------------
file_size = os.path.getsize('cronJob.html')
if file_size > 3000:
shutil.copy('/home/cdr/Logs/cronJob.html', fileName)
else:
pass
------------------------------------------------------------

If I omit the test for file size and just run:
shutil.copy('/home/cdr/Logs/cronJob.html', fileName)

all works OK.

I have checked the data type for file_size, which is long and anything else I can think of.


Best Regards.
 
What does it show if you do:

print file_size

right before the if statement?

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
It prints

14520

Which is the same as you get when you do:
ls -l


Thanks
 
Well, without seeing more of your script, the only thing I can think of is that when you do the copy you use a fully qualified path but when you do the comparison, you use a relative path.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Bingo!
That's exactly the problem. Each time I ran the script interactively I was in the same directory as the file I was trying to size. That's why it ran from the command line, but not by cron.

Well deserved star.
Cheers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top