Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1309
  • Last Modified:

Start program at startup in specific tty?

Hello all,

I would like to know how I can start a program at (or after) start up in a specific console (anything above 1). I am running FC2 and just want to make sure this program starts back up after reboot.

Thanks,
GR
0
GR999
Asked:
GR999
  • 3
  • 2
2 Solutions
 
CaseybeaCommented:
In the directory /etc/init.d, you want to create a script called "fred-run" (or whatever).

"fred-run" should look something like this:

#!/bin/sh
# chkconfig: 2345 20 80
# description: Start FRED
#! /bin/sh
# /sbin/init.d/nfs-export

case "$1" in
  start)
    COMMAND THAT START YOUR PROGRAM GO HERE
       ;;
  stop)
    COMMAND THAT STOPS YOUR PGRAMN GOES HERE
    ;;
esac
# End




The commented lines that say "chkconfig" help redhat add the script to the various start levels (2,3, etc).


Once the script above is written, and lives in /etc/init.d, then use "chkconfig" to enable using it in startup/boot.


# chkconfig fred-run on

Here's some information on chkconfig:

http://www.rt.com/man/chkconfig.8.html

Besides reading that and learning how chkconfig runs, the next thing to do is to learn from the other startup scripts that are on your system - use them as examples.

The scripts are all in /etc/init.d.    

Hope this helps!


0
 
GR999Author Commented:
Ok that would definately work, but I need it to run in a console (tty). Would that mean I would have to automatically login in to a tty then execute the program in that tty? It is a small server program that has a console to query status and issue other commands. Also on line 4 "#! /bin/sh" does that need to be in there? Wouldn't the script error out on this?

Thanx
GR
0
 
stokesj56Commented:
About the #!/bin/sh (notice no space), this is not strictly needed but should be included. This tells the system which command interpreter to use to execute the script. In this case use /bin/sh (bourne shell). If you did not include this the system would use it's default shell (most Linux distributions use BASH, some systems use Korn shell, etc.) Some commands act differently in different shells.

If you want a commant to run whenever you login on certain terminals then put this in your .profile (or other startup script depending on your defaul shell):

TTY=`tty`
TT1=`basename $TTY`
TT2=`echo $TT1 | sed 's/[^0-9]//g'`
if [ "$TT2" -gt 1 ]
then
    # Insert your command here.
fi

This will run everytime you login. If you only want it to run the first time you login you will need to add some further checks.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
GR999Author Commented:
I'm sorry if I was not clear before, but what I need is to start a program after a reboot in a console (tty5). This would need to be done without any user intervention. I can run the program after start up, but would like to run it in a console. I appreciate all your help.

Thanks,
GR
0
 
stokesj56Commented:
If it is strictly output messages then just redirect the stdout and errout to tty5. I.E.

  my_command 2>&1 >/dev/tty5

Use the init file like Caseybea suggested above.

If this is all that you use tty5 for then you may want to turn off getty for that port to disallow logins on that terminal.
0
 
GR999Author Commented:
Thanks for the help guys!

GR
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now