I'm currently working on a script that is to be run for a particular amount of time(let's say a minute), and then has to stop its execution for like 5 seconds and then start executing again(this cycle keeps on repeating), without fail. The script is in Python 3.x and runs on Ubuntu environment. So creating a Service/Daemon of the same would also work(although the execution of the script has to stop for a few seconds).
It's basically using Scapy Module for packet sniffing while capturing Live and then doing some analysis on those captured packets, before inserting the data in the database. When i stop the execution of the script by pressing Ctrl+C
it stops, and then inserts data in the DB and not in parallel. Although it'd be better if this process gets in parallel and the script never has to stop executing, but till then I need a workaround for the same.
My Approach:
import scapy
def main():
capture = LiveCapture(interface = "<some interface>", filter="<some filter>")
count = 0
for pkt in capture:
#DO SOMETHING
insert_in_DB() #--------This happens only when I stop the execution.
if count == 100:
count = 0
#back to main()
So, you get the general idea of what my code is trying to do, right? But I want this to happen after every 1 minute, where after running for 1 minute, the code execution stops so that the data can be entered into the DB and then start again after 5 or less seconds.
Thanks in advance :)