Solved

Start program at startup in specific tty?

Posted on 2004-10-16
6
1,271 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:GR999
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks for the help guys!

GR
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction How to create multiboot configuration with XP\Vista and Windows 7 on it? And most important question - how to do this correctly so not to have any kind of nightmares we get when system gets screwed? First of all one should realize t…
In this article we will discuss all things related to StageFright bug, the most vulnerable bug of android devices.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

763 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now