how to autorun at startup terminal command or applescript..

czeky

Registered
does anyone know how to auto run at startup terminal command or applescript? have some terminal commands which needs to be executed on every startup, now have to launch terminal and write them again and again...

fg: I need to be executed this command

[localhost:~] root# /private/var/root/en2.sh

in file en2.sh i have some configuration commands...
 
What are you configuring? you might be able to put them in .cshrc or .login files

To run an AppleScript on startup, save it as an applet and add it to your login items
 
the problem is, that im on my user (not admin, nor root) acc, and this command needs root privilegia, as im root and admin, i can use sudo, but thats not automated, if its on login at my no admin/root acc, it cannot be executed.. u know, thats what i need, applescript worx, but only in root log, and not in my user acc...so i need something, what i can in my root acc put to system folder or.... and it will be executed on every startup... not on every login..
 
i need this few lines to be executed at every startup, not login, cos its remembered by the system and login doesnt overwite this settings (as I know)

#!/bin/tcsh
/sbin/ifconfig en2 193.218.230.244 netmask 255.255.255.248
/sbin/route add -net 0.0.0.0 193.218.230.241
/usr/sbin/named

with this script i can connect to internet over my Airport but SUpdate doesnt recognize connection, if someone has a better way, will be lucky...
 
To have something run (ie, shell script) with the other system startup items, do this (examples are for stuff I created to start egd):

  1. create a directory under /Library/StartupItems for your stuff to start (also create /Library/StartupItems if it isn't there); for example, /Library/StartupItems/egd
  2. in your new directory, create a file with the same name; this will be a script which is run on startup; for example, /Library/StartupItems/egd/egd . This file is pretty simple:


    #!/bin/sh

    . /etc/rc.common

    ##
    # Start up egd
    ##

    if [ -f /usr/local/bin/egd.pl ]; then
    ConsoleMessage "Starting egd"
    /usr/local/bin/egd.pl /tmp/entropy
    fi

  3. create a file called StartupParameters.plist also in your new directory; for example, /Library/StartupItems/egd/StartupParameters.plist . This file is also pretty simple:

    {
    Description = "Entropy Gathering Daemon";
    Provides = ("egd");
    OrderPreference = "Early";
    Messages =
    {
    start = "Starting egd";
    stop = "Stopping egd";
    };
    }

    the only thing about it is what to put in OrderPreference (options are None, Early, First, Late, and Last), and if there are dependencies. My example doesn't have any, but to see how to do it, have a look at some system ones (like /System/Library/StartupItems/Apache/StartupParameters.plist)
    [/list=1]

    After this is done, any Apple updates won't mess with it (since it's under /Library and not /System/Library), and will print out the text in the Messages piece during startup, so you can see it come up.
 
please explain "Messages pieces" (wondering its on startiup screen? like initializing network, configuring...) im new to unix world and OS X too, but Im afraid, to execute my script, have to be root, not user, so i think, is the startup script is in my user (not root) library foledr, it will be not executed, and if its in root, maybe will be, but I have no plans to login for root to execute and then like user,

oh, oh my english is pain in da ...., but Im sure U understand...
 
By "Messages piece", I was referring to the part of the StartupParameters.plist file, which are printed on the window which appears as OS X is booting up (with other messages like "Starting internet services" and "Initializing network").

And this does go under /Library, not the Library subdirectory of any user on the system; when OS X boots, it runs stuff it finds under both /System/Library/StartupItems and /Library/StartupItems (all as root).
 
is there a way to slowdown a message in "message piesces", its so fast... fg some delay command or so, so i can notice that, just to be sure... but thanx man for your help, i think i saw my msg, its not working for now, but im sure this is the way... systems finally looks for something from me at startup... maybe msg like this will be enough... "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

also is it possible to check somewhere (system log?) if my commands was executed?
 
I believe the startup text is only displayed while the script is running, so if you add a 'sleep 2' (or some other time) it should display the text for a couple more seconds.

As far as logging, I'm not sure where output from the scripts go by default, but you should be able to add some redirection to the script to go to your own log file (ie, /var/tmp/startup.log or some such).
 
Back
Top