Results 1 to 8 of 8

Thread: Making a small script

Hybrid View

  1. #1
    Member imported_vvpalin's Avatar
    Join Date
    Apr 2009
    Posts
    442

    Default Making a small script

    Here is what id like to do.

    I have a text file and in it i keep commands that i use often. Each of the commands typically has a variable to it .. i.e the MAC addy

    I have multiple routers so everytime i switch to another one i need to copy in the mac for each command. Thats like 20 different times i need to paste each MAC

    How would i write a small script that would ask me for variableA, VariableB etc... and then paste my input into the text file where i put [VariableA] .. [VariableB] .. then save

    Yes i have different docs saved with the separate mac so honestly this is rather pointless but im more or less using it as a learning experience. Then hopefully using that knowledge to make a couple automated tools so if you also know how to run a command as a separate process ... or wait for a command to finish before executing another one that would be a big help

    Before you go yelling at me about searching .. yes i have for well over an hour ... but i think im searching for the wrong thing

    Thank You

  2. #2
    Developer
    Join Date
    Mar 2007
    Posts
    6,126

    Default

    yes i have for well over an hour
    A whole hour! wow. First of all you need to decide on a script language to use. The default shell language is bash so searching for some things like......

    bash , script, tutorial , variable, noob


    Will probably get you some results.

  3. #3
    Senior Member streaker69's Avatar
    Join Date
    Jan 2010
    Location
    Virginville, BlueBall, Bird In Hand, Intercourse, Paradise, PA
    Posts
    3,535

    Default

    Way back when I started playing around with Linux, I learned early on that you look at someone else's scripts, see how they're doing it, and then mess around with it.

    I'm sure if you try real hard, you can find a bash script that takes variables as inputs and does something with them.

    As Yoda said, there is no 'try' only 'do'.
    A third party security audit is the IT equivalent of a colonoscopy. It's long, intrusive, very uncomfortable, and when it's done, you'll have seen things you really didn't want to see, and you'll never forget that you've had one.

  4. #4

    Default

    Before you go yelling at me about searching .. yes i have for well over an hour ... but i think im searching for the wrong thing
    Your search button must be broken.

    Google for the terms: bash script user input variable

    The first hit had the info you are looking for.

  5. #5
    Member imported_blackfoot's Avatar
    Join Date
    Jun 2007
    Posts
    386

    Default google

    google
    search term: learn bash
    return value line 2:
    http://www.w3reference.com/bashprogramming.html

    or buy a book

    As sure as eggs are eggs you shouldn't be using backtrack!
    Lux sit

  6. #6
    Senior Member streaker69's Avatar
    Join Date
    Jan 2010
    Location
    Virginville, BlueBall, Bird In Hand, Intercourse, Paradise, PA
    Posts
    3,535
    A third party security audit is the IT equivalent of a colonoscopy. It's long, intrusive, very uncomfortable, and when it's done, you'll have seen things you really didn't want to see, and you'll never forget that you've had one.

  7. #7
    My life is this forum thorin's Avatar
    Join Date
    Jan 2010
    Posts
    2,629

    Default

    Assume the following is the content of test.sh (and that test.sh is executable, in your path, etc):
    Code:
    #/bin/bash
    
    mac=$1
    
    echo $mac
    So now if you run test.sh as:
    Code:
    test.sh somestringlikeamacaddress
    The echo command is passed the string you specified on the commandline for test.sh and is echoed to the screen (so you should see "somestringlikeamacaddress" on a blank line). Obviously you would use any command and variable sequence etc (this was just a quick example).

    $0 is the name of the script/command being run (handy if you add a parameter check and usage screen).
    $1 is the first variable, $2 the second etc.
    Of course you can get really complicated and do parameter name/value pairs (i.e.: test.sh mac=somestringlikeamacaddress) on the script commandline and then parse them in any order (so that the user doesn't have to memorize order etc) but that's probably overkill for you.
    I'm a compulsive post editor, you might wanna wait until my post has been online for 5-10 mins before quoting it as it will likely change.

    I know I seem harsh in some of my replies. SORRY! But if you're doing something illegal or posting something that seems to be obvious BS I'm going to call you on it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •