1

I have this in crontab:

*/6 * * * * python3 /root/projects/download.py >> /root/projects/download_errors.log 2>&1

*/10 * * * * python3 /root/projects/upload.py >> /root/projects/upload_errors.log 2>&1

which run fine (every 5 minutes and every 10 minutes)

Basically my download script downloads a file from a FTP server and the upload script uploads it to different FTP servers. Thing is, both scripts run fine 2 or 3 times, then suddenly the downloaded file becomes 0 KB (on the FTP server it is not 0 KB). Which is funny because I have this in my download script:

if ftp.size('file.txt') > 0:
    grabFile()
else:
    print("%s The file has 0 KBs..." % date)

Code snippets:

Download script:

def grabFile():

    filename = 'file.txt'

    localfile = open(filename, 'wb')
    ftp.retrbinary('RETR ' + filename, localfile.write, 1024)

    ftp.quit()
    localfile.close()

(everything else is the login part and initiating the ftplib)

Upload one:

    my_file = "/root/projects/file.txt"


    file = open(my_file,'rb')
    session = ftplib.FTP()
    session.connect(host='my_hostname', port=21)
    session.login('my_username', 'my_password')
    session.cwd('/path/to/the/file')
    session.storbinary('STOR '+ 'file.txt', file)
    session.quit()
    file.close()

The output files are empty.

nori
  • 85
  • 1
  • 12
  • 1
    The way things are configured at present, both scripts will potentially run as exactly the same time every 10 minutes. This is probably what the issue is. – Raman Sailopal Dec 17 '20 at 09:59
  • I have thought about that. I've changed the time they should run and the same thing happens. – nori Dec 17 '20 at 10:00
  • 1
    Show in your question the code of your scripts and the output files. If the scripts are too long, create a [mre]. Show the modified `crontab`. – Bodo Dec 17 '20 at 10:03
  • Done. Sorry. The output files are both empty. – nori Dec 17 '20 at 10:11
  • 1
    Every 6 and 10 mins still conflict at 30 mins. Use a different cron specification. I.e. */10 * * * * * and 5-59/10 * * * * *. Second will execute every 10 mins but 5 mins after the hour. See also: https://stackoverflow.com/questions/12786410/run-cron-job-every-n-minutes-plus-offset – stolzem Dec 17 '20 at 11:43
  • I'm dumb as hell. I still want them to run every 5 and 10 minutes, so I put a sleep 20; on the second cron. Should work. Anyways, if it won't - at least I know why now for sure. Thanks everybody! – nori Dec 17 '20 at 14:38

1 Answers1

0

I put

sleep 20;

on the second cron job and everything works fine. I still wanted them to run every 5 and 10 minutes.

nori
  • 85
  • 1
  • 12