Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Start program at startup in specific tty?

Posted on 2004-10-16
6
Medium Priority
?
1,304 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 13

Assisted Solution

by:Caseybea
Caseybea earned 375 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
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.

 

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 375 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

Technology Partners: 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!

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 …
I don't know if many of you have made the great mistake of using the Cisco Thin Client model with the management software VXC. If you have then you are probably more then familiar with the incredibly clunky interface, the numerous work arounds, and …
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.

730 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