Timer for a shell script command

Asked

Viewed 128 times

-2

Good afternoon, everyone,

I want to write a script with a command that captures all wireless network flow around my company and store it in a text file. Currently I do so:

airmon-ng start 'nome da placa de rede wifi'
airodump-ng -a wlan0mon 2>&1 | tee captura.txt

It happens that to interrupt the capture it is necessary to press CTRL+C and I have to capture for 10, 15 or 20 minutes, so that the file does not get gigantic!

Does anyone have any suggestions for this process to stop without pressing CTRL+C?

  • 1

    Automation and infrastructure questions should be asked in English at [su], [sf] or https://unix.stackexchange.com/ depending on the subject. Remember to read the specific rules of each community before posting there. For future issues that are on site scope worth understanding What is the Stack Overflow and read the Stack Overflow Survival Guide (summarized) in Portuguese.

  • 1

    I thought his question was valid, since it’s about programming in bash and shell script.

2 answers

1


You can use Kill -INT, which does the job of Ctrl+C

# Roda o script de captura em background
./x.sh &
# Aguarda 1 minuto (seconds)
sleep 60
# Kill 
killall -INT airodump-ng

Optionally, you can use killall -9 airodump-ng

Tested with bash 4.3

0

You can use the command timeout which is just what you need, running a program and shutting it down after a certain time.

examples:

timeout 15 ping 8.8.8.8

In your case I think it would look something like

timeout 20m ./seu_script

The nice thing about this command is that you can select what kind of Signal vc you want the program to receive, a SIG KILL or SIG TERM friendlier,

  • His option, at first seemed to me the best, but to maintain the automatic process, the colleague @Incrivel Monstro Verde Cabelud was more performative! The timeout, while actually interrupting the process, requires some action after execution.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.