Mac Forums

Mac Forums (http://www.mac-forums.com/forums/)
-   OS X - Development and Darwin (http://www.mac-forums.com/forums/os-x-development-darwin/)
-   -   Creating a script (like a windows batch file) (http://www.mac-forums.com/forums/os-x-development-darwin/263618-creating-script-like-windows-batch-file.html)

leftcheats 01-15-2012 05:47 AM

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/

vansmith 01-15-2012 11:32 AM

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.

Dysfunction 01-15-2012 12:59 PM

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


leftcheats 01-15-2012 01:05 PM

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.

vansmith 01-15-2012 01:57 PM

Quote:

Originally Posted by Dysfunction (Post 1355736)
Sure.. it's good practice to shebang the scripts though.

Good point. I knew there was something I was missing!

Dysfunction 01-15-2012 01:59 PM

Quote:

Originally Posted by vansmith (Post 1355774)
Good point. I knew there was something I was missing!

it just avoids any need to sh <filename> ;)


All times are GMT -4. The time now is 09:35 PM.

Powered by vBulletin
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.