WWDC2004 Session 631

Transcript

Kind: captions Language: en presenting under the topic ding for system administrators applescript to shell pearl etc John Renick we actually have some people here that's exciting I we had to compete with the apple remote desktop session so nobody get up and leave because I said that we also and it's Friday afternoon so scripting for system administrators when they asked me to do this they had a huge amount of stuff that they wanted included in one session they said applescript shell and curl I said you know that's an awful lot of stuff to get done in an hour so um I don't pretend that I'm going to be able to teach you everything you need to know about Apple script shell and pearl in 60 minutes or less however hopefully i can give you enough good examples of fun exciting very interesting things that i have done with these and that you can also easily do with them all primarily be concentrating as we go through on the number of interactions that you can have between one or the other just because you have a favorite language doesn't mean that you're eliminated from using the other language for doing the other things that you want to do and so certainly the deficiencies of one language can easily be overcome by the advantages of another language so that's what i'll be concentrating a lot on got a lot of example scripts um those will all be available on my website AFP 548 com is the website if you don't know that if you don't know what that reference is that's fine look on the website you can see a you become a better geek so all these example scripts will be available but you can download take a look at hopefully you can increase your own code with it so without further ado Apple script shell pearl why you want to script in some examples because a lot of people that I'm I find a lot of it when I'm consulting on a 1 i'm training that i tell people well that's easy that's three lines a shell yeah well but i don't have to learn shell well then that's four lines of apple script well i don't want us to learn apple script well that's a couple lines of pearl with us it really isn't that big of an impediment to getting something done that you want to do how many are currently scripting great so I can get rid of that whole argument right there we don't need to convince you that you need to do that all right so some ideas about when to write a script some ideas about what language to write it in and some really cool script ideas right because that's what we're all here to learn how to do the sexy fun stuff to make our lives a lot easier three major scripting language will be talking about the camel for Pearl the apple script in the terminal 4 she'll she'll see those as we go through here so sometimes it's a hard sell why you want to do a script sometimes you need to convince yourself sometimes you need to convince your boss sometimes you need to convince someone else when you want to script so these are a couple good reasons why I want to script it's easy you can liberate admins right I think I used to have something in there about how the script was a lot less expensive than an admin but they got mad at me for that cause admins might take it sense and we don't want to put people out of work so your fingers definitely can get tired but if you have a script you never have to do it again if you ever know you're going to have to do it again script it all right it's so much more fun to write a script than it is to continue to choose the same thing over and over and over again so that shouldn't be a hard thing to have to understand no matter how old you are you're too old to do the same thing 15 times in a row there's just no reason to have that level of repetition in the administration workflow so definitely others need to be able to do it reliability a script never gets things wrong once the script has been written right it's not going to miss type something as it goes in there my biggest problem typing is bad tab completion works great for me but it can't do everything so script takes care of the rest of that and it's certainly a lot more fun to write a troubled or to write a script than it is to close out of trouble ticket so then get a script to close that out and you can just use ard or something else to push that out then you can solve some problems in that way so I came up with a little chart so amount of work accomplished by amount of admins oh man and we missed the actual the yellow line on top is admin to script the red line as admins who don't that lost in graphics but that's ok so this exciting right the more scripting you do the more efficient you are and then I gave that and they said well I can't really use those numbers because they weren't scientific and we didn't want people to think that I'd done an actual study on this so these are fake numbers but you get the idea that if you start out as an admin that scripting you've already got work that's being done for you without you having having to lift a finger alright so definitely scripting is a very good way to go when the script there's times that you should script in those times that you shouldn't script when you need to automate the process when you need to make sure it's done the same way every time and when you find scripting more fun than real work all great times the script alright I certainly don't want to encourage anyone to do work when scripting call if you have the need if you have that desire and you find it fun go start writing scripts all right don't do the real work let the scripts take care of that for you later on times that sometimes it's not a good idea to script sometimes scripts just get way too complicated all right you need to understand that there's a break point after you put too much effort into a script and it's still not going anywhere or the situation is too complicated don't script it all right lay back let somebody do it maybe yourself right and definitely leave some exciting things if you scripted everything you're going to be bored all right so nice mix of both of those is good so now we get into the religious war all right because I'm sure we have people that are all from applescript or bash or shell or zsh or any of the other ones that we might have available to us here on ls10 so which scripting language which one do you want to pick especially if you're new to scripting there's a lot of different options that you have out there which one do you want to use which one is going to be more effective for you so a couple of thoughts on that first of all these are at least this is a non-exhaustive but what I found was a little bit of poking around scripting languages that are included in hours 10 so the three that we're going to talk about here on the top apple skip shell in Perl Python Ruby TCL PHP expect all of these are scripting languages that are included in here so definitely take the one that you like the most the one that works best for you and start using it all of these can do things so I'm doing better than others but almost every script will be able to accomplish what you're looking for if you bang it hard some other ones the people like that aren't included in default install but are easily to install download package and sell or whatever else small talk f script frontier real basic and so many others / that recently had an article about comparing scripting languages back and forth and there was some 30 or 40 different options that were on there that they had run through some code see she was the fastest and all the rest important couple of points about picking a scripting languages does it do what you need it seems basic but I know a lot of people that forget this one they're convinced the script that they know the language they understand is the one all end all scripting language and they don't they don't even look at the other ones so you got to understand if your scripting language that you're using doesn't do what you need obviously you need another scripting language do you know the language if you don't know what it's going to be a lot harder scripted not that you shouldn't learn a language but just keep in mind that you know what you know will you be able to run it where you need to one of the reasons why we're talking about shell Apple script and pearl is their default on the install if you go out and create a real basic script you create a small talk script or something else you're going to have to put that scripting environment on the other machines so depending what your deployment that you're looking for is make sure that you have a scripting language that's viable for that deployment that you're looking at both scripting languages will be able to do most things don't believe the hype okay scripting languages are very powerful and if you work at it long enough the beauty of a script is that there's all kinds of possibilities that neither you nor the developers of that language ever really thought about to begin with and there's usually a lot more than one way to do things right so if you have a scripting language that you know that you're fairly confident with familiar with see if you can do it put a little work into it finally one of the most important things about scripting alright some will do it better than others some won't but to all get it done tried very hard to stay away from any kind of speed comparisons or anything else in here because scripting isn't about speed all right if we wanted to get the fastest job done as possible we'd write on actual compiled application we'd get out x co dwie write an objective c we'd compile it and it would beat the pants off of anything that we could do with the scripting for the most part that's not the object of scripting the object of scripting is to get your jobs done to make your servers work to keep things up and running and to make you have more fun if you can do that it's a successful script scripting is not a hack job it's not a band-aid scripting is very much an integral part of your system administration it's not just something that you worked up so that you could be lazy being lazy isn't a bad thing but scripting isn't a hack because of that so many scripts are more much more than full-featured applications I've run a couple shell scripts that were like 1200 lines long I go back and I try to understand what they do and I can't even remember all right but they're very complete very full functional shell scripts and they do whatever an application would do I couldn't find an application that would do that scripting was the least path of least resistance for getting that they're not a replacement for network administrator's all right you just need intelligence on the job and that's a network administrator novel script you need the ability to make decisions like that I shouldn't have that goes without saying and again not faster than an application but almost always faster to develop especially we're not programmers for the most part in here this is scripting for system administrators not for cocoa folks all right so we can write these scripts we can make them very easily readable we can make them very easily usable for our other administrators that work in our same organization it's very easy to deploy we don't have to get into the full-blown programming language again we're not going to be faster we're not going to be maybe even more complete but we're going to be able to get the jobs done that we need to get done so first off applescript one of the important underlying features of apple script is its interaction with the GUI all right pearl and she'll both have huge amounts of features but they're not going to be able to interact with the GUI in the way that Apple script does so let's take a look at some of the things here so it started off as a language to control other apps however it's completely fully functional in its own right you're going to be able to do almost anything that you want to do with an apple script that you can do with the other script right mostly because we can do a lot of interaction between them and that's what we'll get into a lot of here closest to spoken English a lot of scripters use this as their gateway language all right when you become a network administrator and you have fun of the GUI and it's exciting and man those icons are lickable and they look all great everything else but when you move on to the next step into writing your own things into being able to do your own processes and control your entire environment the way you want it Apple script as many times the entry the gateway drug into the scripting so it's a great place to start very easy to pick up we'll give you some basic ideas about how to script what scripting will be able to do for you with a minimum of effort at the beginning it's been in the OS and system seven right it's been around for a long time it's going to be there for a long time again this gets back to your deployability if you have a script and you need to cover a vast majority of the OSS Apple script is the way to go so primarily the only GUI scripting language a couple of features of that one scriptable apps if I have an app that has an apple script dictionary I can actually use it I can tell Photoshop well photoshop's not a good example of that tell quark I can tell quark to do something all right I can tell other applications to do something through my apple script I don't necessarily have to write an app or really increase the power of that script because I can have another app that can do it for me plus it's got the GUI scripting on it so that way i can go in i can create dialogues to pop up say things will show you some of that too it's easy to pick up folder action scripts or another powerful feature of applescript i can attach an apple script to a folder anytime a new object goes into that folder I can do something depending on what that is spoken English syntax means it's really easy to learn I can do things like tell this application to do this tell the application finder to display dialogue that says scripting is cool that's an apple script all right it really is that easy for a lot of places Apple script studio who uses Apple scripts to do all right i'll show you a couple examples of that but it's incredibly easy development environment a rapid application environment that you can easily get your development up and running very easily recordable alright this is maybe not as useful as it always should be but recordable Apple script will get you into the vein of things I can hit a record button I can do some actions I can look at the Apple script that's generated from that and then I can refine from there and especially for those of you who are just starting out with Apple script it's one of the greatest ways to get into Apple script just do a little recording and see how to some tax works some disadvantages to it it's a spoken english syntax you get used to the idea that i can tell application quark xpress produce next month's catalog put all the things i need to in it and make it look great obviously that's not going to work that's not in the court dictionary all right mate will make it look great isn't yeah the other stuff here so you got to be careful with it it's definitely a double-edged sword there's a lot of times that you're thinking it would sound right but it doesn't work it's single-threaded you can't do more than one thing at the same time that's just the way Apple script is we'll talk about some ways to get around that and it's only on the map if you're in a mixed environment and you're looking to deploy a scripting solution that's going to work on both the pcs in the max Apple script is not your answer not anymore starting with 10 3 you don't need to be logged on for apple support is that what's in case should be on here on the list so here's a sample applescript this is going to check for enough free space on your finder volume this might be something that you use when you log in just as kind of an idiot check to make sure that you're not overriding your drive right OS 10 gets really really cranky if you drive gets full so this is tell application finder if the free space of the startup disk is less than some really big number because the counter doing bits I think then empty the trash beep display a dialog box ack i feel full say that i need more room so i have three different i have an audible i have a verbal and i have just a beat that goes on when this happens so now i have to know that something's wrong so this is the kind of stuff that we can do with apple script obviously this is kind of a silly little example but you can see kind of the level of interaction you have here i can empty the trash i can beep i can say things i can display dialogues these are all gooey interactions that Apple script is very very good at so let me show you something who's running an OS 10 server and cool all right so let me go to the demo if I could all right so you've got to know us to in server problem in is that you need to get your users into it the only thing that you have is you got the accounting system County Department to give you 0 demo there we go you got the accounting system to give you a list of first name last name and password but man this is going to be an awful lot of pain if you have to go in by hand into workgroup manager and enter all these in so you say well no problem i'll look into the server admin guide they've got this great little utility called Diez import/export exactly who's written a diaz import export file you have to get into hex you got a lot of fields and everything else in it is really a pain so why don't I write an apple script to take care of that so now i have an import/export apple script i can double click on this says i'm about to run I can pick my import file here's my user import comma separated value file open this up it's going to ask me a couple questions what's the dns name of my home home directory server way i will just use the reverse lookup here so that works get a couple things in here default group default shell three users were imported there's three years in this list so that's a good thing a little bit of air control there now I've got a user import file that goes right into documents so i look at my documents folder here is what you would have had to have done by hand to create a working des import export file alright so this is the power of scripting once you do this once you're going to sit down you're going to read that documentation you go my lord this is not what I ever want to do again and so a script can really make this easy so I can open up this Apple script for you and show you a couple highlights in it and again all of these are going to be available on my site there's a URL in the end here so you can be able to see that so here I copied it onto the desktop import applescript open it up and script editor try it as hard as I could to put more comments in it than code and I think I did a pretty good job but if I did you can ask me questions about it so it goes into here there's a couple of things we're just we're using dialog boxes open save dialog boxes to interact with the user because we got to put some information in there all right you end up with this record we didn't have to go down to the command line I didn't have to tell you that you want to run this put a bunch of flags into it and then run it through a pearls or bash script or something else like that both of those languages would have been able to do this but now I have a much lower barrier of entry for admins to be able to use this application all right so that's one example of Apple script it can really help you out of in a system in the system administrator to go back to the slides please an incredibly cool feature of Apple script is its ability to call shell scripts from within Apple scripts and again one of the things that I was talking about is hopefully i can highlight on a lot of ways that you can take maybe existing administration tools that you already have that you've written in bash that you've written in perl that you've written in another language and use them with the other apple scripts or use them within each other right so this example here is we've got a finder intrusion detection system alright and what it's going to do is it actually runs a du shell script command if you're familiar with the last command the last command returns back who is the last person to log in all right so by running this we're going to run it into a loop it's going to constantly run the last command and if it sees that somebody new has logged in it's going to display a dialogue for me it's a really stupid intrusion detection system but it gives you an idea of how we can use the du shell script command we're not even really calling a shell script we're just calling a shell command alright just the last command we didn't have to write anything else for that but now we can easily interact with it into the GUI if I could be back on the demo again please so here is my Apple script IDs intrusion detection system and it's going to sit up here and it's going to run in the background and I'm going to open up a new Finder window or a new shell and I'll SSH localhost and type in my password and then if I look in here today the use apple just logged in all right because it's just going through and getting that last line of the last command all right so now we have an intrusion detection system hopefully highlighting the interaction with the du shell script command and stuff like that will do a lot more efficient in a couple of examples right back the slides great thanks so that's the Apple script IDs so some common examples of Apple script that you'll find on your system carbon copy cloner who's these carbon copy cloner all right that's an apple script studio application it's written an apple script it does some shell interaction will show you some examples of that a little bit when i actually i'll build an apple script studio app for you all right itunes helpers everybody likes itunes right and there's a bazillion things that will show you your word count or your song count will display the current track in your ichat status whatever else almost all those are Apple script and then finally print center repair anybody using print center repair alright it's killer for fixing printer problems it'll go through it'll raise your cups directory whatever else your temp files and all that other stuff rebuild it so that's another example of an apple scripts to view application right she'll just like the command line everybody loves the command line right Lulu command line alright so if you can do it on the command line you can do it with a shell script all right it's as much fun as much excitement as working in the terminal so it's the built-in scripting function of the shell one of the oldest forms of scripting you can really get deep into show and it's been out there for years and years and years the beautiful thing about that is there's thousands millions of example code out there alright when doing shell scripting you should have to write very little of it yourself right after having done a lot of shell scripting for the last year or 2 i've got my own library when I go in to create a script I don't even think about starting off with a blank page I start cutting and pasting from the last one that I used it's a really nice can do the same thing with Apple script and stuff like that but she'll has a much larger body of work that's outside some advantages like I said just like the command line only automated it's simple if you can use the command line interface you can use a shell script just take a copy what you're typing in you can paste that into a text file you can run that as a shell script it really is that simple it's very few terms the shell scripting language is very simple there's not a whole lot of different things that you can do with it but you can plug those together in very interesting ways relatively portable most unix shell scripts will work on I was ten with little or no modification I'm talking to somebody from developer relations that was talking about a lot of people from Cohen Solaris that wanted to migrate their Solaris scripts over 20 s 10 and we just had to swap out a few commands and that kind of stuff and everything worked all right so if you already have a body of administrative shell script those will work very well on RS 10 some disadvantages there's no guey all right we can't display dialog boxes we can't have it say things and stuff like that part of that is good part of that is bad so we can use Apple scripto to pull those things out I'll show you an example of that a little bit hard to do some shell scripts all right especially when you require interaction you have to get into expect and some of the other shell items if you want to perforate password back to the command line interface things like that it's very hard to start up an ssh session that wants to use a password through a shell command so you got to be careful with that check your shell not all shells can do the same things the default shell on 10 3 is bash bash has some slightly different functionality from some of the other shells that are out there from TCH and the other ones so be careful when you're getting deep into it however from the beginning standpoint on the entry level on the face of them they're all pretty much the same for what you're going to be looking to do when you start off it and make sure you specify the one that you actually want I'll show you what that means in just a little bit because if you think you're using bash and you end up using TCH and you're trying to do something might not work alright so I'll show you how that goes so here's a simple mail server backup you're running an LS 10-3 server you love postfix you love Cyrus but what happens when you try to back up the database well let's live well that's not such a great thing you know the backing up data bases when they're in use might lead to problems so you want to shut down the mail server you want to copy over the backup database and then you want to start the mail server back up again that's cool but you don't want to be up at three in the morning to do it shorts cooking so we've got a simple shell script like I said before be careful that you're using the one that you want to use so this is the shebang the hash bang whatever you want to call it up at the beginning that tells us what language we're actually going to be using here so here it's a pound bang bin bash so that way we know we're using the bash scripting language for it another important thing to see here is the server admin command on that third line down server admin command is a shell command that allows you to do anything that the server admin utility can do so instead of me having to worry about how I know how to stop post fix how to stop Cyrus how to stop all these other things I can just say server admin stop mail and the server admin framework does all that stuff for me so I don't need to worry about Thank You Apple all right I don't have to do that extra work now I can just kind of glue together the different pieces and make something that really works out for me so then we use rsync we sink it from one the VAR spool I map file to our x rayed because we all have one of those then we actually tore it up we tore up or Etsy post fix directory that has all the configuration files and everything else in it because maybe you've looked around the web found some articles about how to do spam and virus controls and stuff like that and then don't know where you've got those and understand how that you need to back those up in case anything happens to them so this script will be both of those for you and then we do server end and start now we're even real nice and verbose about things so we use the log or command to write commands right lines to the etsy ax or the logs for the syslog and that way we know that we started and stopped the the systems and everything else liked it one two three four five six seven lines and you won't have to wake up at three in the morning every day all right so from this base you can take this and we could do all kinds of crazy things we could set it up so that every day of the week we back up to a different folder all right now we've got incremental backups or differential backups between all of this oh man things are great we can do all kinds of cool stuff with this but this is a very easy very simple way to get into this and again this isn't a hack all right this is doing everything the way that we needed to do back the mailman ovation going from there but maybe this is an all we want so in a little bit i'll show you how to expand this into a complete mail server backup I think you go back to the demo please so I've taken that shell script that I had so if i go to my scripts folder there's a male back this one is a little more full-featured pop this up a little bit and let's see how many wines we have here show line numbers so we got about 170 outlines here I bet you over half of those or comments alright so this goes through it backs up not only the post fix full files but Cyrus pull files asks you if you want to back up the post fix backup directory plus it has a restore functionality in here too because once you back it up maybe it would be important to know how to get it back to where it should have been when you need to roll those changes back so there's a restore functionality in here and now you can feed it a bunch of switches on the command line and get through some of this stuff but again this is exciting but I don't want to have to go down to the command line to do this all the time beauty about OS 10 is max or for grandma's right even Graham our system administrators so I want to be able to let those users use this script without having to go down to the command line and mess with it so to do that I've got a little apple script studio application here get rid of some of this called mailbag GUI we open it up Scott a little setup here I can specify a backup directory I will just do / camp in here I put my admin password important to note one of the failures of Apple scripts to do currently I haven't hit some of the other sessions if they fix this what is authentication alright so when I pass my password here it actually does essentially a suit you on the command beautiful all right so this is fixed and tiger and we don't care about pants are much anymore rank is that that's the old cat so when Titus has been taken care of right now this is going to echo back on a command line which is a little bit of a security issue if you have other users logged in they can do a process listing and see that right you'll see that with carbon copy cloner a lot of the other Apple scripts to do apps that are currently out there I was working with an apple engineer to fix that and do some Coco message to put in there but we haven't gotten that working all the way yet so now I hit back up we sit for a little bit and say stop the mail system backed up the post fix pool backed up Cyrus everything else done did everything that command was going to do that shell script except I didn't have to go down to the terminal and what's even better look I got a web browser it takes a little bit to load up because I didn't do all the stuff but this is some of the cool things that you can do this is the cool mac stuff so this is eventually what the site's going to look like I think we're going to do some stuff over there but anyway so now you have a web browser so while that shell script is working on your mail back up you can check out your new webmail whatever else that you want to go through there surf the web a little bit and go from there because there's your cyrus database gets bigger maybe it takes a little bit longer so real quick you probably want to see this in Xcode and I can show you how simple this was the setup so here's the mail back dually file will pop this open into Xcode and here's the Apple script that runs at all and it's you know maybe a dozen two dozen lines of code goes in there essentially just doing the shell script command and calling that shell script I embed that shell script exactly like it came out of when I was done with it embed into the resources folder in here and then you can go into interface builder and you can set things up with that hi beautiful thing about interface builder if you don't know well WebKit let me go back here and let me show you all of the code for the web browser right what but wait there is no code so some of the fun stuff that you can get into with Xcode and stuff like that so really easy to wrap an applescript studio rapper a complete standalone application I can put this onto a disk image I can ship it off the people they can just double-click on it fill it out and go from there since I know it and it's my application I can even go into and do things like already pre set up the backup path so I don't have to type that in all the time alright change the default URL on the web browser right maybe you don't want that it's just she can go any you can set up a lot of things like that so don't be afraid this is very easy to get into use this example start doing your own stuff start taking a look at that and very quickly you'll be turning in your shell scripts into gooeys so also goes like I said before if you're migrating over a number of shell scripts that you had set up on your unix or your other platforms applescript studio will allow you to make an easy nice GUI wrapper for that right wonderful if I could go back to the slides please alright so you saw the back of you saw the GUI so we've got through there so some interaction with Apple script I've got a shell script and instead of being called by an apple script I want the shell script to call an applescript specific example of this about a year ago I was working with another gentleman to work up a FileMaker Pro startup item if you ever use FileMaker Pro 55 you wanted to launch when you started up the system all right they fix that now so don't have to worry about it but it makes a good example one of the problems with it was I could install the startup item for you no problem I can just give you a package installer would go in there everything would work the issue however was that I wouldn't know necessarily where your copy of FileMaker Pro server was maybe you put in your applications folder maybe you didn't I'm a big fan of the mac i want to be able to arrange my environment the way that I want it to be so as an admin as somebody that's producing scripts I want you to have that same functionality and I don't want to have to tell you you got to go into the startup item and you got to edit that field and figure out where your actual install is so instead if you went to the package installer session you probably learned about post install scripts these allow you to have a package that installs and then kicks off a shell script that's cool but my shell script can't display a dialogue that actually lets me know what i need to do so to get around that my shell script can call OS a script osa scripts is a command-line way of actually calling an apple script so my package installer actually installs an apple script then runs the post install script which runs that little fair enough right you with me all right so that Apple script then displays a dialog box since hey why don't you pick where your server application is for filemaker pro server easy enough once we're done with that then it passes the back to that post install script the post install script goes through and edits etsy Hadiya start apply them and make sure that it knows where it is and so you can see a quick example of this up at the top is the shell script alright says my path equals 0 s a script and then we're calling that Apple script that we installed somewhere that Apple script which is the second half says application finder activate open up a dialogue box to choose a file please select your application set the path of the POSIX path that just make sure that we convert it from the apple script way of file locations to the shell way return that which goes right back to the LSA script and then we're done so there's the OS a script command it was a scripting session we had a hard time trying to find out ways of making the graphics more exciting so you see how that turned to orange alright so that's about as much excitement if you're going to find in there alright so let me show you that if I could go back to the demo machine please I tested it on here so I need to remove the this our startup disk I need to remove the receipt from it real quick sound like a pro server there you go gone alright so I go into my scripts folder with all my stuff in it I've got a nice FileMaker server startup item we mount it nice package installer that comes up beautiful little graphics and stuff that we have in here a little RTF with the motion look at that alright i'm not a graphics guy but this was easy select the volume i'm going to install asked me for my password [Applause] so now it's actually installing the payload of the application this is the startup item this is a couple of other things all right the startup item however doesn't know the location of the application so now I've got a dialog box that pops up hey where's FileMaker Pro server I can go to my Applications folder I can pick that out it's not like a pro server isn't on here then it passes the back and it does that software we're successfully installed so now if I go back to my startup items library startup items you see there's an empty server startup item in here if I look inside here here's the actual startup items show item if I doesn't want to open there there we go that's easy enough and it went through and look at here here's a line the reference is the address book because that's what I picked in that dialog box that asked me what application I wanted to use so now the shell script and let me show you the cell shell script so if we go into the start up the package show package contents inside contents we've got resources inside resources we have the post-flight script which sha we can open up here and said gets a little ugly the first time you see it but there's a tiny little shed command said command said doesn't get you better tiny little said command in there that in my in my default item that i installed i just had a little comment that said going to be replaced by script which makes it nice and easy to find on the way back so i took the output of that Apple script that dialog box that came up set it back to the shell script shell script then goes back in and changes what I installed beautiful right I can even go in and if I go into my hard drive again I did a bad thing because I kind of left that Apple script around startup items filemaker pro server and resources here's an apple script which we actually feed 20 s a script so this is the content to the apple script so again I installed the apple script on the hard drive and the package installer is part of the payload the post-flight ran the post-flight shell script which called OS a script it's called the applescript that i knew where it was because i installed it there Apple script found out where the FileMaker Pro server application was going to live pass that back to the post-flight install script which then edited the startup item and then we're done okay [Applause] that was the most complicated way I could find of having one call the up call the other and back alright so some really fun stuff that you can do with that and now again hopefully you can see that you can easily easily easily put this kind of functionality into your own scripts migrate over your actual shell scripts that you had before put that into here and do a lot of work with it so I could go back to the slides please some common examples are shell I was looking for ones that were in the default install here so some of these might be reaching a little bit depending on what you call common examples but the NC daily weekly monthly scripts those are all shell scripts right those are the ones that go through back up your net in for database rotate your log files and stuff like that so those are in their startup items are commonly shell scripts if you look in system library startup items you're going to find that the actual executable of a startup item is almost always a shell script cuz it's nice and simple if you've ever used the disk space monitor i was just i did a grip on the system looking for anything that had been bashing it or something else like that um disk space monitor alerts are there and pre-flight and post-flight package scripts are most awful always shell scripts see a lot of pearl lately too pearl never use another scripting language again right once you lose right once you use pearl you never go back having said that I stick with shell but I understand where people come from with it i started off mostly doing applescript because it was easy it was very easy to get into once we started getting into OS 10 server especially in 10 1 and 10 to an apple script wasn't as robust as it is now in 10 3 shell scripting took care of some of those deficiencies stuff like having to be logged in and things like that so a shell script I started doing a lot of work with and have a lot of fun with the interaction between it some would say the next logical progression would be the pearl takes a different person to understand pearl so we'll go over that pearl is present I'm pretty much any unix system alright so again you have a wide range of deployable systems that you can write a Perl script for news there's many many many many pearl resources available alright there's a lot out there just like shell script there's thousands of sites devoted to this thousands of sample scripts that you'll be able to get to and an incredibly active and for the most part very nice developer community alright happy to answer questions just don't get them into Wars and you should be good so some advantages advantages of pearl it's very much multi-threaded you can do a lot of things at the same time Pearl's got a lot of resources available for that this is verging on a religious statement but I think it's the most extensible of the three languages mostly because there's thousands and thousands and thousands of modules that have been written for Pearl all right anybody again I hate to pick on carbon copy cloner but since Mike's doing the ARD session I will if you've used ard you've used p sink p sink is a pearl app that uses a bunch of modules that use it in there again you can use those same modules to increase your own pearl application so that's one of the examples that uses that all right Sipan is a pearl repository will give you a URL for that in a little bit that's got a listing of all these modules that you can easily get two runs on most systems although it's not in there by default you can get pearl environments for back as OS 8 and 4 windows so even though it's primarily installed on most UNIX systems you want to if you have a perl script that you want to use with a little bit of tweaking and some installation on the client side you can get this to running their clients incredibly good for text processing all right I've lately started getting into helping out a design firm that I was working with that needs to get rid of a bunch of files generated by their rips and stuff like that and the file path got so weird and so complicated that pearl was the best solution for that because it can easily get in there parse out that text do a lot of text manipulation without having to go through and do it by hand like you might have to encode in a shell script and if you've ever done anything with pearl one of the slogans of pearl is there's always more than one way to do it all right and as you will find out when you go looking for perl modules to do your one item that you need to do you might find 3,000 so you got to wade through that a little bit decide hey which one's better whenever else so there's a little bit of a learning curve there may be a little bit of a sense of overwhelm pneus overwhelming how those all are out there pearl disadvantages it is probably I don't think anyone would argue with me that it's the most complex of the languages that we're talking about here all right not that that means it's hard to learn it's just that there's a lot more syntax that you need to get used to there's a lot more commands there's a lot more of statements that you can get with so you need to understand that before getting into it it's not something that you can just pick up a visual quickstart guide to and be writing a lot of curl within a day or two it might take you three or four days and to get the really good stuff take you a little bit longer than that but there is going to be a bit of a learning curve right you'll actually have to think with a play i knaw with apple script we can do some recording and stuff like that we don't have that functionality with pearl so again there's a little more into it and there's more than one way to do it so when you approach a problem with pearl if you go looking on from the list and stuff like that you're going to find eighteen thousand different ways and you have to kind of filter through that a little bit and say really which one is the best way all right here's a simple perl script i wrote an application that generated ssh tunnels it was an apple script studio application problem with it was as once it calls the du shell script command it would have to wait for that du shell script command to return before the apple script studio application actually went back to being operational so one of the ways around supposed to actually wrap my shell command into a perl script that would actually demonize itself so this is one of the one of the examples I can find a pearl that I would written it did something kind of sexy so it demonizes itself it keeps that ssh tunnel open as long as it needs to and the Apple script studio application had a return because this application this perl script had spun off and it kind of gone on its own so the Apple scripts to do part was happy to go back to it there you go see that action difference between this and a shell script it's just text it's different text but it's just text is the fact that we're using user bin pearl here instead have been bash there's one of the other shells we might have had all right here we have a perl script Emma auto printer setup is Mike here in Purdue all right maybe not all right this is a shell a perl script that an admin from purdue set up and let me show you a problem i'm a user i sit down at the lab machinist oh no printers let me add a few i want to add an LPR printer it's at my house this isn't my home IP but we'll just type in something here it's going to be a generic postscript I don't want to get anything fancy there hi generic post would not add it and I at it ok cancel we have a printer in here now there you go generic postscript printer all right problem is the next user behind me is it going to want this prayer I'm in a lab situation in the University I don't have the luxury of having an OS 10 server and workgroup manager that I can push down and force users into different printers so instead I kind of got to do this myself pearl to the rescue we've got an application called printer setup will pop all these opens you can see these connect on and it is a perl script that looks inside two different files so here's the perl script again you can take a look at this and go through it and see some of the stuff and it reads in from two different files one is a printer definition file which understands what printers are available to my client machine and the other file a printer mappings file that says hey if this machine's IP address is in this range we're going to install these printers on it so two different data files both in plain text and we're just going to use the LPR commands the LP commands to set of print queues and stuff like that so let me share a quick example of that so I'm the lab admin I come to this machine if you're off why did I keep adding printers go down to the command line and you got to run this is root and volumes you know we just drag it in right this is too much work do command not found you should have no subscript want to go there see there you go beautiful now I go back to the printer setup hey it's not that 17a IP address lpr machine anymore now we've got the WWDC demo machine come on if there's something for that right it went in the perl script goes in it deletes your current folders that you have it looks in the data files finds out what printers you're supposed to have and add those printers in with the LP commands nice example of what you can do with pearl and some of the stuff that you can get done with it so I could go back to the slides please common examples of pearl part of the service setup process runs a perl script that goes through and does that if you have a website with an ssl certificate that's actually got a passphrase associated with it when you launch apache it actually calls a perl script that pulls that out of it disk space monitor does this cgi scripts on web pages right those are vast majority those are probably pearl I'll go in a little bit of lemon say that so examples of pearl that you'll find around all right some links that you can go to for more information here's the URL for the sample scripts so dub dub dub AFP 548 com etsy dub dub DC zip those are out there now she'll be able to grab those internet web documentation go to the ADC home some of the other stuff there here's some man pages for bosch pearl and others then we've got some example sample script sites that you can go to and download some stuff from notice for shell we go to Google I couldn't find one that was as conclusive as I wanted it and I didn't want to put 30 up there so literally when I go looking for shell script examples I google bash printer setup whatever else and go through there I'll be able to find that so thanks that's my site my email supposed to be up there but it's natural at AFP 548 com if you go to the site you'll find it