Results 1 to 6 of 6
  1. #1
    Creating a script (like a windows batch file)

    Member Since
    Jan 15, 2012
    Posts
    2
    Creating a script (like a windows batch file)
    Hi all,

    I reinstall alot of Macs in my job - then fully update those systems and then 'reseal' the units so the user gets the machine at the start of the 'out of box' experience.

    I use two ways to remove the user account and 'reseal' the OS :
    Both times the username is set to user*

    Boot to terminal:
    fsck -fy
    mount -uw /
    rm /var/db/.applesetupdone
    cd /users
    rm -rf user
    reboot

    OR

    Boot to terminal:
    mount -uw /
    rm -R /Users/user
    rm /var/db/dslocal/nodes/Default/users/user.plist
    rm /var/db/.applesetupdone


    My question is -

    Can either of these 'scripts' be put onto a pen drive - THEN when i boot to terminal - mount the pendrive and "execute" either 'script' to save me typing it out all the time -

    Thanks in advance for any response - and if the above makes no sense at all please let me know and i'll try and write it out better as solving this would really help me out.

    thanks again.\\

    Ed/

  2. #2
    Creating a script (like a windows batch file)
    vansmith's Avatar
    Member Since
    Oct 19, 2008
    Location
    Toronto
    Posts
    19,395
    Specs:
    2012 13" MBP (2.5 i5, 8GB)
    Making shell scripts (*nix equivalent of batch files) is very much like batch files (at its most basic). Simply put the commands one after the other into a plain text file, save it and make it executable (chmod +x <script name>).

    Note - it has to be plain text. I mention this because apps like TextEdit default to rich text which will add a bunch of text to your script which will screw it up.
    Important Links: Community Guidelines : Use the reputation system if you've been helped.
    M-F Blog :: Write for the blog
    Writing a Quality Post

  3. #3
    Creating a script (like a windows batch file)
    Dysfunction's Avatar
    Member Since
    Mar 17, 2008
    Location
    Tucson, AZ
    Posts
    6,821
    Specs:
    Way... way too many specs to list.
    Sure.. it's good practice to shebang the scripts though.

    That is...

    Code:
    #!/bin/bash
    fsck -fy
    mount -uw /
    rm /var/db/.applesetupdone
    cd /users
    rm -rf user
    reboot   #does this need to be done with elevated permissions?  If so, toss in sudo
    It would be easy, at this point to establish what user by simply doing something like...

    Code:
    #!/bin/bash
    if [ $# -ne 1 ] ; then 
    	echo "Usage: $0 username"
    	exit
    fi
    
    fsck -fy
    mount -uw /
    rm /var/db/.applesetupdone
    rm -rf /users/$1
    reboot   #does this need to be done with elevated permissions?  If so, toss in sudo
    mike
    This machine kills fascists
    Got # ? phear the command line!

  4. #4
    Creating a script (like a windows batch file)

    Member Since
    Jan 15, 2012
    Posts
    2
    Hi -

    thanks for both responses - i'm a nOOB with all this but i'll give it a go and get back to you...

    thanks.

  5. #5
    Creating a script (like a windows batch file)
    vansmith's Avatar
    Member Since
    Oct 19, 2008
    Location
    Toronto
    Posts
    19,395
    Specs:
    2012 13" MBP (2.5 i5, 8GB)
    Quote Originally Posted by Dysfunction View Post
    Sure.. it's good practice to shebang the scripts though.
    Good point. I knew there was something I was missing!
    Important Links: Community Guidelines : Use the reputation system if you've been helped.
    M-F Blog :: Write for the blog
    Writing a Quality Post

  6. #6
    Creating a script (like a windows batch file)
    Dysfunction's Avatar
    Member Since
    Mar 17, 2008
    Location
    Tucson, AZ
    Posts
    6,821
    Specs:
    Way... way too many specs to list.
    Quote Originally Posted by vansmith View Post
    Good point. I knew there was something I was missing!
    it just avoids any need to sh <filename>
    mike
    This machine kills fascists
    Got # ? phear the command line!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Like BATCH in Windows family , is anything in MAC to write script.
    By Niraj in forum OS X - Operating System
    Replies: 3
    Last Post: 02-25-2013, 04:23 AM
  2. Terminal -- shell script -- script will only read two lines of a file
    By Straitsfan in forum OS X - Apps and Games
    Replies: 0
    Last Post: 01-30-2011, 09:04 PM
  3. Terminal.app/bash: Creating An Executable Shell Script
    By ebay in forum Running Windows (or anything else) on your Mac
    Replies: 7
    Last Post: 04-28-2008, 06:43 PM
  4. Replies: 1
    Last Post: 09-30-2007, 02:38 AM
  5. creating script for system login
    By pbook24 in forum Schweb's Lounge
    Replies: 3
    Last Post: 01-30-2006, 03:14 PM

Posting Permissions

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