0

I have few independent projects written in Python that I would like to have executed daily. I'm going to use crontab on an Ubunutu server but I would like to write a script to manage these projects and at the end send a report with information on what scripts failed, what errors they produced, if they were successful, time to execute etc.

I have 2 ideas, please help me decide which one is better or provide me a better solution?

1: crontab will execute a bash file and this bash file will launch each script and calculate the time they took to run.

2: crontab will execute a python script which will execute all the others scripts and calculate the time they use to run etc.

Sorry english is not my main language.

1
  • Why do some people downvote without any reasons ? Commented Nov 2, 2017 at 9:26

2 Answers 2

1

Good question! Both of these solutions are quite feasible, but it's probably going to be easier to write a script in python (solution #2).

Bash scripts are great, but if you make a bash script here you'd need to write another script that was passed the result of all your other scripts. It would look something like this:

##results.sh
first_result = python script1.py
second_result = python script2.py
python email_results.py $first_result $second_result

With this methodology it will be difficult to time the scripts and is generally a little unwieldly.

If you used python, you could use time.time() to time things and it would generally be a little neater.

##python
import time
import script1

start = time.time()
result = script1()
end = time.time()

time_elapsed = (end - start)

email_results(result, time_elapsed)

Hopefully this helps! Good luck!

Sign up to request clarification or add additional context in comments.

Comments

1

Hey I I used python to do it! It's so flexible! But to call my script I decided to use the "os" command:

folderList=next(os.walk('.'))[1]
    for folder in folderList:
        os.chdir(folder)
        res =subprocess.Popen(["venv/bin/python", "main.py"],stdout=subprocess.PIPE,stderr=subprocess.PIPE)
    os.chdir("..")

It works well and executes all my scripts! Off course I added an exception handler etc. Thank for your answer! :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.