Solved

Start program at startup in specific tty?

Posted on 2004-10-16
6
1,281 Views
Last Modified: 2008-02-26
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
Comment
Question by:GR999
  • 3
  • 2
6 Comments
 
LVL 13

Assisted Solution

by:Caseybea
Caseybea earned 125 total points
ID: 12330897
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
 

Author Comment

by:GR999
ID: 12333056
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
 
LVL 2

Expert Comment

by:stokesj56
ID: 12339116
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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

Author Comment

by:GR999
ID: 12339573
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
 
LVL 2

Accepted Solution

by:
stokesj56 earned 125 total points
ID: 12340719
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
 

Author Comment

by:GR999
ID: 12452986
Thanks for the help guys!

GR
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello I read in a discussion about a person who configured a very simple mirror RAID with two hard drives; the system and data were on the same partition. He asked how to repair the system as it was not booting up anymore. In his case running …
Windows 7 does not have the best desktop search built in. This is something Windows 7 users have struggled with. You type something in, and your search results don’t always match what you are looking for, or it doesn’t actually work at all. There ar…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question