LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Running a script on front-ground on startup ? (https://www.linuxquestions.org/questions/linux-software-2/running-a-script-on-front-ground-on-startup-798069/)

moicpit 03-26-2010 10:52 AM

Running a script on front-ground on startup ?
 
Hi !

I would like to know how to run a BASH script on front-ground on startup of my machine.

I've installed a Damn Small Linux (DSL) on a old computer and I would like to run a script at stratup, in command-line mode. So, I've added my script in /etc/rc3.d and it's working fine except 1 thing : I would like it does not execute on background.

In facts, I would like the script take the hand immediatelly after login (my DSL is automatically login in with the DSLuser user).
The aim is that the script take the controle of the computer until it quit (the script is launching an application, wait for its stop and shutting down the PC).

Thanks !

Pit

schneidz 03-27-2010 02:09 PM

i think putting the script in ~/.profile or ~/.bash_profile would invoke it after login and as long as you dont put a & at the end, it wont background.

catkin 03-27-2010 11:51 PM

Quote:

Originally Posted by moicpit (Post 3913390)
I would like to know how to run a BASH script on front-ground on startup of my machine.

I've installed a Damn Small Linux (DSL) on a old computer and I would like to run a script at stratup, in command-line mode. So, I've added my script in /etc/rc3.d and it's working fine except 1 thing : I would like it does not execute on background.

"Foreground" means running in an interactive terminal. Boot scripts, run from the likes of the /etc/rc3.d directory are not running in an interactive terminal; they are sending their output to the console.

I think it is possible for a boot script to start a login shell running in a virtual terminal (including the one showing console output) and running a program but I do not know the details. It would probably need bash's --login and --rcfile options.

Quote:

Originally Posted by moicpit (Post 3913390)
In facts, I would like the script take the hand immediatelly after login (my DSL is automatically login in with the DSLuser user).

Do you mean you want the script to run in the logged-in session? Or simply that it should run after the automatic login?

Quote:

Originally Posted by moicpit (Post 3913390)
The aim is that the script take the controle of the computer until it quit (the script is launching an application, wait for its stop and shutting down the PC).

That is possible and does not need to be done in the foreground unless you want to interact with it.

It might be better if you tell us what you want to do rather than ask us how to implement your solution. We may be able to suggest a better solution.

moicpit 03-29-2010 12:09 PM

Hi !

Thank you for your answers !

@ schneidz : Thank you very much ! Calling my script in ~/.bash_profile was the solution ! ;-)


Quote:

Originally Posted by catkin (Post 3915057)
"Foreground" means running in an interactive terminal. Boot scripts, run from the likes of the /etc/rc3.d directory are not running in an interactive terminal; they are sending their output to the console.

OK, so I wanted to call it in "foreground", so I will move it out from /etc/rc3.d/.

Quote:

Originally Posted by catkin (Post 3915057)
Do you mean you want the script to run in the logged-in session? Or simply that it should run after the automatic login?

That is possible and does not need to be done in the foreground unless you want to interact with it.

I mean that I want it to run in the logged-in session. And I have to interact with my script.

Quote:

Originally Posted by catkin (Post 3915057)
It might be better if you tell us what you want to do rather than ask us how to implement your solution. We may be able to suggest a better solution.

The aim of my script is to launch an application that will capture the input (here, a keyboard) and make some actions regarding what key is pushed.
When we want to stop the computer, we kill the app (CTRL+C) and then the script will automatically shutdown the computer.

Here is an exemple of the script I want to use :
Code:

[Here some code to wait 5 seconds so that the user can cancel the script continuation and take the hand on the computer]
[calling of my app]
sudo shutdown now



All times are GMT -5. The time now is 12:03 PM.