How to terminate a running python script correctly through bash?

Try this:

#!/bin/bash

if [ "$1" == "--on" ]; then
    python3 script.py --option a &  # Note: Fixed typo 'pyhton3' to 'python3'
    python3 script.py --option b &
elif [ "$1" == "--off" ]; then
    pkill -SIGINT -f "python3 script.py --option a"
    pkill -SIGINT -f "python3 script.py --option b"
fi
1 Like