New To Mac-Forums?

Welcome to our community! Join the discussion today by registering your FREE account. If you have any problems with the registration process, please contact us!

Get your questions answered by community gurus Advice and insight from world-class Apple enthusiasts Exclusive access to members-only contests, giveaways and deals

Join today!

 
Start a Discussion
 

Mac-Forums Brief

Subscribe to Mac-Forums Brief to receive special offers from Mac-Forums partners and sponsors

Join the conversation RSS
OS X - Development and Darwin Discussion and questions about development for Mac OS X.

Creating a script (like a windows batch file)


Post Reply New Thread Subscribe

 
Thread Tools
leftcheats

 
Member Since: Jan 15, 2012
Posts: 2
leftcheats is on a distinguished road

leftcheats is offline
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/
QUOTE Thanks
vansmith

 
vansmith's Avatar
 
Member Since: Oct 19, 2008
Location: Toronto
Posts: 18,050
vansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond repute
Mac Specs: 2012 13" MBP (2.5 i5, 8GB)

vansmith is offline
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
QUOTE Thanks
Dysfunction

 
Dysfunction's Avatar
 
Member Since: Mar 17, 2008
Location: Tucson, AZ
Posts: 6,638
Dysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant future
Mac Specs: 2008 and 2011 15" mbps, late 11 iMac, iPhone 4s, and too many ipods and other stuff

Dysfunction is offline
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!
QUOTE Thanks
leftcheats

 
Member Since: Jan 15, 2012
Posts: 2
leftcheats is on a distinguished road

leftcheats is offline
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.
QUOTE Thanks
vansmith

 
vansmith's Avatar
 
Member Since: Oct 19, 2008
Location: Toronto
Posts: 18,050
vansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond repute
Mac Specs: 2012 13" MBP (2.5 i5, 8GB)

vansmith is offline
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
QUOTE Thanks
Dysfunction

 
Dysfunction's Avatar
 
Member Since: Mar 17, 2008
Location: Tucson, AZ
Posts: 6,638
Dysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant future
Mac Specs: 2008 and 2011 15" mbps, late 11 iMac, iPhone 4s, and too many ipods and other stuff

Dysfunction is offline
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!
QUOTE Thanks

Post Reply New Thread Subscribe


« Bluetooth programming question | packagemaker issue »
Thread Tools

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread
Thread Starter
Forum
Replies
Last Post
Question about Bootcamp Melorock089 Switcher Hangout 12 06-29-2009 07:53 PM
Running Windows on a Mac: A Switcher's Guide UncSki1218 Running Windows (or anything else) on your Mac 80 06-10-2008 10:34 PM
Running Windows on Mac rickmahmoud Running Windows (or anything else) on your Mac 7 02-16-2008 11:31 PM

All times are GMT -4. The time now is 08:28 AM.

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

Welcome to Mac-Forums.com

Create your username to jump into the discussion!

New members like you have made this community the ultimate source for your Mac since 2003!


(4 digit year)

Already a member?