Jump to content

Recommended Posts

Posted

I've set up a cron job to clear out some old temporary files periodically, but I can't tell if it's been running -- I have the email address setup but haven't received any messages, and files haven't been getting cleaned. Is there a way to test my cron job setup without running afoul of the twice-per-day limit?

 

User: b0ardfac

Server: tommy

 

Thanks!

 

Posted (edited)

Here's his command:

0 0,12 * * * /usr/bin/env python3 /home/b0ardfac/cleanup.py

Since I know nothing about python, I'm not sure what it takes to execute a python script through cron, but with cgi/perl you only need the path:

0 0,12 * * * /home/b0ardfac/cleanup.py

And I believe you need to make sure file permissions are 755.

Edited by Byron
Posted

I'll try that particular formation.

 

Should I be receiving emails from cron job attempts even if the execution fails? So far I have not received any emails about cron job execution.

 

My account was also recently autosuspended this past weekend for resource use, I'm not sure if that may be a factor?

Posted

If your script isn't producing any output, you won't receive any emails:

 

 

You can have cron send an email every time it runs a command which produces output.

 

Just check to see if your script has cleaned your temporary files. I just set up a cron to run a cgi script and it works perfectly, but my script doesn't produce any output so i didn't get any cron emails.

Posted

Also another thing you might want to try, can you run your script from a browser? Try coping the file to your public_html folder and see if you can run it with your browser.

Posted

The first version I tried was using a script in my cgi-bin, and it was successfully executing from the browser. My first attempt at setting up the cron job had the command as "/home/b0ardfac/public_html/cgi-bin/cleanup.py" and that did not work.

 

My script always produces some output, which is why when I received no emails, I assumed the cron job was not running.

Posted

Ok when I try running your script through SSH and using this path,

 

 

/usr/bin/python /home/b0ardfac/cleanup.py

 

I get an error:

 

 

root@tommy [~]# /usr/bin/python /home/b0ardfac/cleanup.py
  File "/home/b0ardfac/cleanup.py", line 24
    print(f'Cleaning up {path}')
                              ^
SyntaxError: invalid syntax
 
So it looks like you do need this path after all:
 
/usr/bin/python /home/b0ardfac/cleanup.py
 
but since i don't know python, I can't say that error is causing you any problems since you say you can execute it through your browser ok.
Posted

That particular error is from running a different version of Python; can you try using "/usr/bin/env python3.6" in place of "/usr/bin/python"?

Posted

Seems that works:

 

 

 
root@tommy [~]# /usr/bin/env python3.6 /home/b0ardfac/cleanup.py
Beginning cleanup.
Cleaning up /home/b0ardfac/ff4hack/seed_cache/FreeEnterprise-J2KC2T4S3BF2NE3X2$Y2GWZ-31893827.zip
Cleaning up /home/b0ardfac/ff4hack/seed_cache/FreeEnterprise-J2KC2T4S4BE3X2WZ-31893941.zip
Cleaning up /home/b0ardfac/ff4hack/seed_cache/FreeEnterprise-J2KC2T4S3BF2NE3X2$Y2GWZ-31894403.zip
Cleaning up /home/b0ardfac/ff4hack/seed_cache/FreeEnterprise-J2KC2T4S3BF2NE3X2$Y2GWZ-31894579.zip
Cleaning up /home/b0ardfac/ff4hack/seed_cache/FreeEnterprise-J2KC2T4S3BF2NE3X2$Y2GWZ-31894614.zip
Cleaning up /home/b0ardfac/ff4hack/seed_cache/FreeEnterprise-J2KC2T4S3BF2NE3X2$Y2GWZ-31894858.zip
Cleaning up /home/b0ardfac/ff4hack/seed_cache/FreeEnterprise-VJ2K2PC2T4S2B2FNE3X2$Y2GW2Z-31895091.zip
Cleaning up /home/b0ardfac/ff4hack/seed_cache/FreeEnterprise-J2KC2T4S3BF2NE3X2$Y2GWZ-31895466.zip
Cleaning up /home/b0ardfac/ff4hack/seed_cache/FreeEnterprise-KC3T4S4BX2-31896640.zip
Cleaning up /home/b0ardfac/ff4hack/seed_cache/FreeEnterprise-VJ2K3C3T5S4B2F2E4X2$3Y2GW2Z-31896799.zip
Cleaning up /home/b0ardfac/ff4hack/seed_cache/FreeEnterprise-J2KC2T4S4BE3X2$3WZ-31898058.zip
Cleaning up /home/b0ardfac/ff4hack/seed_cache/FreeEnterprise-J2KC2T4S3BF2NE3X2$Y2GWZ-31898370.zip
Cleaning up /home/b0ardfac/ff4hack/seed_cache/FreeEnterprise-J2KC2T4S3BF2NE3X2$Y2GW2Z-FAIZ.zip
Cleanup done.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...