0

I'm new to shell scripts and all, and wanted to write a script that would automatically perform this command for me:

sudo aireplay-ng -0 (given number) -a (Router MAC Address) -c (Target MAC address) wlx000f60071636

The script would ask for user input, then perform the command with the input of the user.

So, I referenced these pages:

http://www.aircrack-ng.org/doku.php?id=deauthentication - For Aircrack Structure

http://www.tutorialspoint.com/unix/unix-shell-functions.htm - For designing functions which would allow for different numbers instead of -0, resulting in varied commands

https://stackoverflow.com/questions/226703/how-do-i-prompt-for-input-in-a-linux-shell-script - For user input

http://www.tutorialspoint.com/unix/unix-using-variables.htm - For Variables

And using these pages, I wrote this script:

#!/bin/sh
ROUTER="(my router MAC)"
echo "Perform a wifi command?"
select yn in "Yes" "No"; do
    case $yn in
        Yes ) Deauth; break;;
        No ) exit;;
    esac
done

Deauth () {
    sudo airmon-ng start wlx000f60071636
    sudo airmon-ng check kill
    echo "Please specify device MAC:"
    read dmac
    echo "Number of commands to send, with 0 being unlimited:"
    read numts
    sudo aireplay-ng -0 $numts -a $ROUTER -c $dmac wlx000f60071636
}

However, after running

chmod +x wificommand.sh

and

sh wificommand.sh

I receive an error message of

wificommand.sh: 4: wificommand.sh: select: not found
wificommand.sh: 9: wificommand.sh: Syntax error: "done" unexpected

What is wrong with my code? Is select unavailable to use? Why should done not be there? Is this the correct way to run a command with user input?

1
  • Perhaps because sh is not bash on your system? see for example DashAsBinSh Jun 10, 2016 at 0:18

1 Answer 1

1

select is a bash builtin, not a sh builtin. Change your first line to:

#!/bin/bash
7
  • Changing the first line still results in an error message upon execution
    – D4rKP01s0n
    Jun 10, 2016 at 0:36
  • 2
    @D4rKP01s0n if you are executing it as sh wificommand.sh that will override the "shebang" line and use sh anyway. Just execute it directly using the relative path ./wificommand.sh Jun 10, 2016 at 0:40
  • @steeldiver Thanks! That fixed that issue, and the rest I can figure out myself. Thank you!
    – D4rKP01s0n
    Jun 10, 2016 at 0:50
  • @steeldiver Also, if you don't mind me asking, what is the proper way to call the function Deauth from inside the Yes case?
    – D4rKP01s0n
    Jun 10, 2016 at 0:53
  • 1
    put the definitiion of Deaith() above the select stanza, and invoke with a simple Deauth (no parens) as you already have it.
    – DopeGhoti
    Jun 10, 2016 at 1:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .