kerpap Posted June 25, 2015 Share Posted June 25, 2015 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. Quote Link to comment Share on other sites More sharing options...
Sitwon Posted June 26, 2015 Share Posted June 26, 2015 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.) Quote Link to comment Share on other sites More sharing options...
i8igmac Posted June 26, 2015 Share Posted June 26, 2015 (edited) 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 June 26, 2015 by i8igmac Quote Link to comment Share on other sites More sharing options...
cooper Posted June 26, 2015 Share Posted June 26, 2015 (edited) 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 June 26, 2015 by Cooper Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.