Jump to content

Start and stop then start again aireplay within a bash script without killing the bash script


kerpap

Recommended Posts

hello

I am trying to write a bash script that basically does this:

calls aireplay-ng

runs it for 5 minutes

then stops aireplay

then sleeps for 5 minutes

I have something like this:

while [ true ] 
do
     aireplay-ng -# # -a<MAC> -h<MAC> mon0
     sleep 300
     <somehow stop aireplay>
     sleep 300
done

ive tried using kill a number of ways, ive tried calling xterm -e (aireplay) then try to close it from the script but nothing works

any ideas?

again,

start and run aireplay-ng for 5 minutes

stop aireplay-ng

sleep 5 minutes

then repeat.

Link to comment
Share on other sites

The most trivial solution would look like this:

while [ true ] 
do
     aireplay-ng -# # -a<MAC> -h<MAC> mon0 &
     PID=$!
     sleep 300
     kill $PID
     sleep 300
done

In bash (and pretty much any other derivative of 'sh'), '$!' is a special variable which holds the PID of the last command to be executed in the background (with '&'). Once we have the PID, we can use it to inspect or control that process. For example, by using the 'kill' command to send it a TERMinate signal.

If it were me, I'd write a much more sophisticated function for ensuring that the process actually terminates before the next iteration. (Eg, send a KILL signal if the PID is still active after a reasonable timeout.)

Link to comment
Share on other sites

I'm not a fan of bash scripts, I think you should explore python, perl or ruby...

while true

IO.popen3('airbase-ng wlan0'){|input,output,error,process|

if output.include?('something good')

file.write('log.txt', output)

End

If the application needs input, like reaver ask

Input.include?('Do you want to continue with old session')

input.puts('yes')

End

If error

Puts(' we have a error')

End

Puts (process information)

sleep 60*5

Kill.process

}

End

Edited by i8igmac
Link to comment
Share on other sites

Sounds like you need to explore the

 tag 

The great thing about bash is that it's (more) universal and ubiquitous than the alternatives you suggest, you don't have to learn a new language (everything there works as-is from the command prompt, obviously) and if done properly you can trivially make a nice, concise, readable program that does exactly what you want with very little fuss.

Edited by Cooper
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...