OS X script question

 
Thread Tools Search this Thread
Operating Systems OS X (Apple) OS X script question
# 1  
Old 03-24-2011
OS X script question

EDIT: Sorry, just realized there is an OS X forum on here - feel free to move this post if someone feels the need!

Maybe this is a stupid question, because 90 views on OS X Hints forum and no replies :P

But, really appreciate you reading!

I am curious what the command(s) would look like, if it is even possible to:
A)
Script that would reboot into single-user mode and execute the rest of the script/different one.

B)
Script that would log out of OS X into console and execute the rest of itself or another script. Or would you just have to log out to login window and user >console and execute the script. But, I know that would only work with the right login window options...

Basically, I have a script that we use (we are an AASP) to delete the temporary user and .AppleSetupDone type files so when we return a machine to a customer they get the startup video and setup assistant.
But, we manually have to boot into single-user mode and execute the script.

Not that the process is all that bad, but I'm just curious (since I'd really enjoy some scripting) what this would look like.

Cheers!
# 2  
Old 03-28-2011
Since - i think - Mac OS X is (historically) based on FreeBSD, maybe you should get some documentation about that one and/or check the corresponding man page that are on your current OS.
Maybe this could be a start
Maybe also read this
# 3  
Old 03-28-2011
About the only thing I can think of is a logout hook. Login and logout hooks run as root, so it should technically be possible.
I have only one question though, do logout hooks run on shutdown?

logout hook's script steps:
1. delete home folder of the temp account (presumably you are logged in as that temp user, so your script can just reference "$1")
2. delete the user account from /Users and /Groups/admin
3. delete the logout hook entry from com.apple.loginwindow
4. delete the applesetupdone thingee
5. delete the logout hook script

Make a backup of the script somewhere off of the machine.
Create the logout hook preference in com.apple.loginwindow pointing to the logout script.
Choose Shutdown to test the process, then reboot to see if all is well.

If all is well, then you only need to create an installer package (including an install script that creates the logout hook preference) to install the hook, and logout script.

With this tested installer package on a thumb drive, you could just run it, and
shutdown.

Some good info here:
http://discussions.apple.com/thread....sageID=6891519

That is of course, if the logout hook is run on shutdowns...

That's all I gots.

Last edited by [MA]Flying_Meat; 03-28-2011 at 04:16 PM..
# 4  
Old 03-28-2011
MySQL

Thanks for the replies guys!
Not sure when I'll have a chance to read/process them, but wanted to say thanks in case this fades to gray :P

At least I have some fresh places to look and experiment with once I get some free time!
# 5  
Old 04-05-2011
You mean this thread?

Script/Command question - The macosxhints Forums

For one, your method will not work for a few key reasons. In SUM directory services is not even running, there for no dscl support. Also, with all the rebooting, it would be a scheduling nightmare to have launchd continue running scripts.

What I would do is take that script I wrote on the other forum and package it up with a couple of managed preferences and my script in an installer, set a log out hook to have it finish the job. The workflow would look something like this:

1) Create local admin account on Mac you are servicing, and do all the work you need to
2) When done, run the PKG installer which payloads the managed preferences to set the log out hook to my scirpt and copies the script to the proper folders
3) At log out, manage preferences kicks off the script, deletes the user, deletes the .AppleSetupDone, and deletes the managed pref and the script itself so it is like it never existed.

This whole SUM business won't work the way you want it to.
# 6  
Old 04-06-2011
Hah, I had given up/forgotten about that thread I think; thanks for the reminder.

I still haven't had a chance to go any further with it, but it does sound like a logout hook is my best option. I'll dig back into the other thread here in a minute.

Truely appreciate the help!
# 7  
Old 04-06-2011
If you package up an installer (PKG file) with the script, the loginwindow.plist file enabling the logout hook you can install it and then on shutdown the script will run.

The script I posted should probably be modified to also delete the loginwindow settings for the logout hook and the script itself.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

C first Script Question

Gents for 2013 I have embarked on learning C and just wrote my first script and need some help. In the learning process, I am trying to understand where I went wrong with my script. The flow of the script is as such: Enter a number --> check if it is a number --> if it is not a number,print what... (4 Replies)
Discussion started by: metallica1973
4 Replies

2. Shell Programming and Scripting

Script question

I know some tricks like this : echo " E"; sleep 0.1; clear; echo " Er"; sleep 0.1; clear; echo " Err"; sleep 0.1; clear; echo " Erro"; sleep 0.1; clear; echo " Error ";... (2 Replies)
Discussion started by: hakermania
2 Replies

3. UNIX for Dummies Questions & Answers

Script Question

I have a script that will calculate some information about the current directory that I run the script in. How can I have it where it gets an argument from the user(such as a directory) and the script calculate the information for the given directory? Any help is greatly appreciated. (8 Replies)
Discussion started by: tr32
8 Replies

4. Shell Programming and Scripting

Script question

I am trying to write a script to check the STIG our unix boxes. I want to put in checks to determine if certain files or directories are there. For example: If /opt/SUNWexplo exists echo "Sun Explorer exists" else echo "Sun Explorer is not installed" I am sure I could write... (2 Replies)
Discussion started by: rkruck
2 Replies

5. Shell Programming and Scripting

Script Question

Here is my problem. I have a txt file with a list of user names in both upper case and lower case. I need to remove the names from the passwd file. I want to be able to run a script that looks at my txt list and then removes those names from the passwd file. It would be nice if it backed up the... (3 Replies)
Discussion started by: wgartin
3 Replies

6. Shell Programming and Scripting

script question

Anyone know why this won't work? #!/usr/bin/ksh for db in `cat /etc/oratab|egrep ':N|:Y' | grep -v \* | cut -f1 -d":"` do echo "************************" echo "database is $db" echo "************************" done I am getting an error on the line... (7 Replies)
Discussion started by: ace2000
7 Replies

7. UNIX for Dummies Questions & Answers

Script question

Can anyone help with these scripts? Im new to this and struggling. Thank you for your help. Pre-requisites Create a file with x amount of lines in it, the content of your choice. (Have already done this) Script 1 Write a script that takes two arguments. The first being a line of text,... (3 Replies)
Discussion started by: beginner1
3 Replies

8. Shell Programming and Scripting

script question

I'm using solaris and i have an old script that an ex employee wrote but i can't seem to get it working. well is just one part of the script if ($?MC_PROD_DIR == 0) setenv MC_PROD_DIR $HOME/PRODUCTION source $MC_PROD_DIR/scripts/localenv ** i understand what this part of the script is... (1 Reply)
Discussion started by: fusionjd
1 Replies

9. UNIX for Dummies Questions & Answers

script question

Correct me if i'm wrong, but by adding "#!/bin/ksh" at the start of a script will force it to run in the korn shell no matter which shell you are currently using?? (2 Replies)
Discussion started by: shad0w75
2 Replies

10. UNIX for Dummies Questions & Answers

Another script question.

Hi, First off I usually script in the bash shell. Ok, in my script I am checking to see if the filename has a .txt extension. So I was trying: if then echo "Must contain a valid .txt extension" fiandif ] then echo "Must contain a valid .txt extension" fiBut no go the first... (5 Replies)
Discussion started by: Astudent
5 Replies
Login or Register to Ask a Question