Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

NEWBIE with simple question

Status
Not open for further replies.

2010noACAPS

Technical User
Mar 29, 2004
41
US
Hi, I'm running Mac OS X and I need terminal to start running a program as soon as it starts, but am not having any luck. I've never used UNIX before so just have snippets from books and such that aren't working. Is there a way to do this?

Thanks,
T
 
To start a program as soon as a user log on a terminal, simply edit one of the profile script to launch it.
If the rule is system wide, edit [tt]/etc/profile[/tt]
If on user basis, edit [tt].profile[/tt] in each relevant home directory.

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
I'm guessing that the terminal you are starting is not a new login shell.

If your default shell is Bash, try setting the [tt]BASH_ENV[/tt] environment variable to the full path and name of a script containing some commands you would like to run when you open your terminal window.

I think the other shells have something equivalent to this.

I'm not certain this will work. I don't have access to any OS X machines.

Please reply here if it works or does not.

--
-- GhodMode
 
I forgot to mention that that variable would need to be set in your .profile. [smile]

--
-- GhodMode
 
GM & PH,

Thank you both for your tips I will try them tonight to see what works and let you guys know. (I hope I don't blow-up my Mac.) :)


T
 
OK, I've looked in my book on UNIX, it's a visual quick start book, and it says that I need to add the new path statement directly below:

Code:
PATH=$PATH:$HOME/bin

But I am still not sure what the new path should look like. Am I just adding where the program is located or what I type in to start the program running,
i.e.
Code:
Applications/folder/program
or
Code:
Applications/folder/program -nice #
Let me reiterate that I am NO programmer. I'm just a basic home user that would like to have 1 simple program start up automatically when Mac Terminal is started at StartUp.

And I really do appreciate any help you guys can give.


Thanks,
T
 
I guess starting Mac OS X starts a graphical UI.
And that you use it as single-user machine.

Isn't there a 'autostart' - menu or folder?
 
The [tt]PATH[/tt] environment variable just uses the location of the program you want to find, not the program name or any arguments. However, I don't think that it's what you're looking for...

The [tt]PATH[/tt] environment variable will not start a program for you when you start the terminal. It only specifies a list of places to search when you type a command name without specifying the full path.

If you are currently able to type the command in a terminal, without typing the full path, and it will run, then the location of the command is already in your [tt]PATH[/tt].

Try typing [tt]echo $PATH[/tt] in your terminal window and see if the location of your program is already there.

Have you tried the other reccomendations?

--
-- GhodMode
 
OK, after SW mentioned the 'autostart' menu I added the program I needed to run to the Startup Items of my Accounts folder. It worked...BUT after Terminal started it 1) opened up a new Terminal window and started the program (yeah!) and 2) it put this "/Applications/folder/program; exit". What does the "; exit" do? When I manually start the program I have to put "-nice #" behind the path name. The program started fine, I just would like to know that it's not taking majority of the processor usage and to make sure this is really what I want it to do or do I need to look at another option.

And SW I'm not really sure what you mean by your post. OS X has a GUI or Terminal has a GUI? Because what I'm trying to run is a command line program.


Thanks,
T
 
I'm a linux-user, and don't know, how you handle your MacOsX - even don't know macOsX (yes, heard something about it, but never used it).
I only wanted to be sure.
I don't run a GUI every time I start my pc-linux - therefore a 'autostart-folder' wouldn't be a solution to me.

But I usually login on more than one console - so answer No.1 wouldn't fit to me.

If your program doesn't need a GUI you may start it in different ways than if not.
On linux you may start every program on the console, but few need the X-windowing-system to be up.
Let me say in other words: if you click a button on a desktop, a command is executed, and this command could be given by hand too. But some will not work in 'true-console mode' (no X running) - but I don't know if there is a 'true console mode' [(off topic:) typed: mood - which is true in some way too :) too much listening to Norah Jones I guess]
for macOsX.

Given your problem on linux, I would solve the problem with the bootup-scripts in /etc/init.d, /etc/rcX.d - but do they exist on Mac?
 
Well I think so since OS X is built on top of a UNIX subsystem. I do know that BASH is the default shell that Terminal starts in and I believe I can get to other shells. But I'd rather just stay in BASH since I know that's where my program works. (I don't really no the differnce between shells.)

So, basically OS X is just like running Windows XP, compared to Linux of course. I tried creating a crontab, or whatever it's called, with my UNIX book but I can't find it now. It never did what I wanted it to do anyway, which is to start my program running as soon as my system boots up.
 
I'm not sure whether your autostart-solution works or not.
(I don't know what this 'exit;' means.)

If your X-Autostart solution doesn't work, (can you prove it?) you may try this:
(But the bootscripts differ from distribution (soso, redhack, debil, slackwack, ...)

In my system, bootscripts are stored in

/etc/init.d
There I put my bootscripts.
Then there is a structure of similar directories:

/etc/rc0.d/
/etc/rc1.d/
...
/etc/rc6.d/
/etc/rcS.d/


well - runlevels have numbers.
There are runlevel for different states of the machine:
SingleUser 1, MultiUser 2, MultiUser with Network 3, MUN + X11 4, reboot.
But the numbers for the runlevels differ unfortunately!
Maybee you find hints in
/etc/inittab

If you start into a GUI the machine will first start single-user-mode, then multi-user, ... then X11.
So it may fallback to a less complex level, when a serious error occours on a higher level.

I guess runlevel 1 will be SingleUserMode on every distribution, since it is intuitiv 1=Single.

You might have guessed it: runlevel 1 - files match to the rc1.d/ directory.

If your program needs network-support, it should be put in the 'multi-user-with-network' runlevel- dir.
If it needed a GUI into the 'X11'-runlevel - no4 on my system.


Assumed your script runs in runlevel one.
Therefore you make a link from the script in /etc/init.d/xy.sh to rc1.d.
But you have to look for a free - two-decimal number, because the scripts are started in order of their numbers.

Some scripts depend on other scripts - for example to log warnmessages to /var/log/xy.log the filesystem containing /var/log needs to be mounted first.

Assumed you choose number 88.
Then you link your program this way:
ln -s /etc/init.d/xy.sh /etc/rc1.d/S88xy.sh

The prefix 'S' is used for starting, when entering a runlevel.
The prefix 'K' for killing when leaving the runlevel (not valid in your case).

Your script stops by itself - I guess. It's not a daemon running continously, waiting for something?
 
Yes, the program runs continuously. Once it finishes with a load it connects to another server to send the result and downloands a new load. I haven't seen rc1.d or anything like that when I look through the directories, but that doesn't necessarily mean anything.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top