a quick script

Discussion in 'General Mac Discussion' started by Macdantheman07, Sep 11, 2004.

  1. Macdantheman07 macrumors member

    Joined:
    Jan 24, 2004
    Location:
    NYC
    #1
    i was just wondering if anyone knew how to write a script so that one does not have to type multiple things in the terminal before they get the result they want. For example:

    i run a program called iCook to overclock my ibook by 100mhz it involves a number of steps in the terminal.

    it involves two sudo commands

    sudo kextload -b net.swieskowski.iCook (it asks for a password)

    sudo sysctl -w hw.cpuspeed=1000 (this sets my new CPU speed to 1Ghz)

    I would like to automate these two steps with a simple script if that is possible because those two lines are a handful to type.
     
  2. bousozoku Moderator emeritus

    Joined:
    Jun 25, 2002
    Location:
    Gone but not forgotten.
    #2
    You can use TextEdit to enter the text but make sure you go to the Format menu and use "Make Plain Text" first.

    Enter the two lines into a text file. If you want to add comments, start the line with a #.

    Save the file. Putting it in your home directory is convenient. You can add an extension (I like .sh to show that it's a shell script) but I wouldn't suggest .txt as an extension.

    After that, open the Terminal application and type "chmod +x" (no quotation marks please), a space, and the name of the file. You can then start it with "./" and the name of the file.
     
  3. Macdantheman07 thread starter macrumors member

    Joined:
    Jan 24, 2004
    Location:
    NYC
    #3
    i think there is either more to that script than you have put there or it just doesn't work. i believe shell scripts are much more complicated than two lines of code. How would the terminal know to input the commands i want it to input?
     
  4. iJed macrumors 6502

    Joined:
    Sep 4, 2001
    Location:
    West Sussex, UK
    #4
    Start the text file with

    #!/bin/sh

    after this put your commands

    also remember to make the file executable by using "chmod 755 myscript.sh" on it
     
  5. bousozoku Moderator emeritus

    Joined:
    Jun 25, 2002
    Location:
    Gone but not forgotten.
    #5
    You can believe that if you want but it just executes what you put there. I've written hundreds of shell scripts over the years.

    How does it know which commands you want to input? You enter them into the script. Obviously, you've shown us the lines, so all you have to do is enter your administrator password when it executes. Do not even think of putting your password into a script.
     
  6. Macdantheman07 thread starter macrumors member

    Joined:
    Jan 24, 2004
    Location:
    NYC
    #6
    i believe u guys now its just that i can't get it to run. do i use

    chmod +x 755 ./filename ??
     
  7. Doctor Q Administrator

    Doctor Q

    Staff Member

    Joined:
    Sep 19, 2002
    Location:
    Los Angeles
    #7
    No, there are two ways to set a file to have execute permissions:

    Numeric: chmod 755 ./filename
    Symbolic: chmod +x ./filename

    They both give you execute permission on the file.

    Dot-slash means "in the current directory". You could also usee ~/filename if the file is in your home directory.
     

Share This Page