Sometimes, it isn't best to do everything via Python. In my case, due to multi-factor authentication, I couldn't send emails via Python and instead was able to use bash to run the python code and send an email if it failed.
You can get the full code in the Gitlab repo here:
To execute this code, you will need to make it executable. You can right click on the run_script.sh file and click properties.
In the permissions tab, make sure to check the 'Is executable' box.
Alternately, cd to the directory this is in and run
chmod +x run_script.sh . You should not need elevated privilages if this script is in your home directory.
This section of the bash script is all about assigning some variables:
python3 $1 $2 python_status=$? current_date=`date "+%D %T"`
The important thing here is
python3 $1 $2 what that does is runs the command python3 then loads in 2 command line arguments.
In our case, we are inserting the name of the python script
hi as a second argument.
$? is special, it will receieve the status of our script. So in this case a 0 or 1. 0 means the script ran to success, 1 means it did not.
The full call for this run will be
./run_script.sh test.py hi
hi will be passed to the python script. It will be shown in the output due to line 3
print ('Argument sent:', str(sys.argv))
Since the bash script only takes 2 arguments (the first is the name of the python script) we cannot get any other command line arugments.
Here's an example of the code running as expected: