LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   start a program when I login, not boot (https://www.linuxquestions.org/questions/slackware-14/start-a-program-when-i-login-not-boot-407484/)

jturnbul 01-24-2006 01:39 PM

start a program when I login, not boot
 
running slackware 10
I would like to have a program run when I log in from the non GIU interface, the basic one with slack. I just dont know where to add the script. Its a program that all users have access to.
I see alot of post regarding starting a program at boot, but few regarding login, that have helped.

One post did say it does not matter to start a program at login, that you can just start it at boot, and every user will be able to access it

PS it needs an internet connection to work, so I would need it to run after my internet connection has been established

phil.d.g 01-24-2006 02:41 PM

Add your script to ~/.bash_profile. As I understand it .bash_profile is only executed when you first login, not like ~/.bashrc which is executed for every instance of bash

jturnbul 01-24-2006 06:35 PM

where do i find ./bash_profile???
I used the find -name command with no luck.

LocoMojo 01-24-2006 07:10 PM

Quote:

Originally Posted by jturnbul
where do i find ./bash_profile???
I used the find -name command with no luck.

It's in your home directory. To see it you need to issue the following command:

Quote:

ls -a (if you're in your home directory)

ls -a ~/ (if you're not in your home directory)
By the way, it is .bash_profile not ./bash_profile. There's also a systemwide file called profile in /etc.

LocoMojo

gbonvehi 01-24-2006 07:21 PM

It doesn't exists by default, just create it.

jturnbul 01-24-2006 07:27 PM

Thanks, I found it along with some other interseting things.

Is there anything I have to include in there other then the path to the program I want to run, along with the program name. cause it did not work when I logged on.

example... /directory/directory/program_to_run

thats the only line in my .bash_profile

LocoMojo 01-24-2006 07:41 PM

Quote:

Originally Posted by jturnbul
Thanks, I found it along with some other interseting things.

Is there anything I have to include in there other then the path to the program I want to run, along with the program name. cause it did not work when I logged on.

example... /directory/directory/program_to_run

thats the only line in my .bash_profile

If the program you want to run is in your path:

Quote:

echo $PATH
Then you only have to type the name of the program to call it.

If it is not in your path then you have two choices:

1. Use absolute paths to call it, i.e., /usr/local/bin/program & (use & to send it to the background so you still have access to your console/xterm).

2. Put the program in your path. For example, if the program in question is in /usr/local/bin , but /usr/local/bin is not in your path then you need to issue the follwoing:

Quote:

export PATH=$PATH:/usr/local/bin
Another way to see your PATH is to type "env" without the quotes. This will bring up all your environment variables.

LocoMojo

jturnbul 01-24-2006 08:27 PM

Quote:

Originally Posted by LocoMojo
If the program you want to run is in your path:



Then you only have to type the name of the program to call it.

If it is not in your path then you have two choices:

1. Use absolute paths to call it, i.e., /usr/local/bin/program & (use & to send it to the background so you still have access to your console/xterm).

2. Put the program in your path. For example, if the program in question is in /usr/local/bin , but /usr/local/bin is not in your path then you need to issue the follwoing:



Another way to see your PATH is to type "env" without the quotes. This will bring up all your environment variables.

LocoMojo

Thanks, I tried the commands from CLI and they worked, however I put them into my .bash_profile and nothing happens when I log on.

I'll post my script to save some time.


export PATH=$PATH:/usr/BOINC
echo $PATH run_client &

or

/usr/BOINC/run_client &

ive tried both with no luck

LocoMojo 01-24-2006 08:55 PM

Quote:

Originally Posted by jturnbul
Thanks, I tried the commands from CLI and they worked, however I put them into my .bash_profile and nothing happens when I log on.

I'll post my script to save some time.


export PATH=$PATH:/usr/BOINC
echo $PATH run_client &

or

/usr/BOINC/run_client &

ive tried both with no luck

What program are you trying to run?

Is it called "run_client"? If so, is run_client a binary?

Don't type "echo $PATH run_client &". Only type "echo $PATH" to see what directories are currently in your path. It is used for information only.

If "run_client" is a binary and if it is in your path then you will only need to type "run_client" without the quotes. If "run_client" is in a directory that is not currently in your path then you need to put the directory (not the program) in your path. For example, if "run_client" is in the /usr/bin directory then you would do "export PATH=$PATH:/usr/bin". After that you will be able to type "run_client" and the program will run.

Another way to determine whether "run_client" is in your path is to type "which run_client" without the quotes. If it is in your path it will show you the directory it is in. If it's not in your path it will say something like "no run_client found in this directory, that directory or that other directory".

If you know exactly where "run_client" is, can you type "file /path/to/run_client" and then post back here what it says?

LocoMojo

jturnbul 01-24-2006 09:17 PM

the program is called run_client
dont know how to tell if its a binary, but all i have to do to run it is cd to its directory, and type "run_client &" and it will un for me in the background.

I did use the command export PATH=$PATH:/usr/BOINC
which is the path I need. When I do that it does allow me to run run_client from my home directory without having to cd to the programs directory.

however once I logoff that directory is gone from my home path.

So would this be the script to run???

#!/bin/bash
export PATH=$PATH:/usr/BOINC
run_client &


with regards to file /usr/BOINC/run_client I get this result...
/usr/BOINC/run_client: ASCII text

jturnbul 01-24-2006 09:28 PM

Quote:

#!/bin/bash
export PATH=$PATH:/usr/BOINC
run_client &
this didnt work

LocoMojo 01-24-2006 09:36 PM

Quote:

Originally Posted by jturnbul
the program is called run_client
dont know how to tell if its a binary, but all i have to do to run it is cd to its directory, and type "run_client &" and it will un for me in the background.

I did use the command export PATH=$PATH:/usr/BOINC
which is the path I need. When I do that it does allow me to run run_client from my home directory without having to cd to the programs directory.

however once I logoff that directory is gone from my home path.

So would this be the script to run???

#!/bin/bash
export PATH=$PATH:/usr/BOINC
run_client &


with regards to file /usr/BOINC/run_client I get this result...
/usr/BOINC/run_client: ASCII text

It's a text file and it runs when you type run_client & ?

Must be a script, I guess. Still, it should say something like "Bourne again script, executable".

Anyway, if you want it to stay in your path after you log out and in then you should do this:

1. Go to your home directory and type "touch .bashrc" without the quotes.
2. Open .bashrc with your favorite editor and type the following:

# .bashrc

# myExports
export PATH=$PATH:/usr/BOINC

Then save the file. From then on every time you log in and open your xterm "run_client" will be in your path. If you ever decide to take it out of your path, for whatever reason, just comment it out by typing a "#" at the beginning of the "export" line.

One thing though...be sure that your .bash_profile says:

Quote:

if [ ! "$BASHRC" -a -f ~/.bashrc ]; then
. ~/.bashrc
fi
If it doesn't then put that in the .bash_profile file exactly as quoted.

Good luck!

LocoMojo

jturnbul 01-24-2006 09:45 PM

didnt work. input exactly as you have it, in both files.
is it possible that when I log in from the CLI (runlevel 3) that its not even looking for .bash_profile ???
I thought I read somewhere that .bash_profile was for logging in with a GUI.

gilead 01-24-2006 09:53 PM

From O'Reilly's 'Learning the Bash Shell', 3rd edition (pg 57):

.bash_profile is read and executed only by the login shell. If you start up a new shell (a subshell) by typing bash on the command line, it will attempt to read commands from the file .bashrc.

In other words, .bash_profile is run when you login at the CLI in run level 3.

jturnbul 01-24-2006 10:33 PM

how do I know if its reading it or not??
should I not get error messages for wrong paths ro anything I am doing wrong.

I have since set it up to run when I boot, by adding some script to the rc.local file.

It took a few boot attempts before I got the scipt right. However everytime I got it wrong I was able to see boot errors telling me either the path didnt exist, or couldnt find the command etc...

Should i not see errors via the login methdod like i do with the boot method???


All times are GMT -5. The time now is 07:15 AM.