Solved

Start program at startup in specific tty?

Posted on 2004-10-16
6
1,277 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Windows 8,8.1 & 10 product key identification question 12 211
URL to download Windows 10 Home 2 151
Reusing a former RAID Member as a data drive 18 105
hp mini 3 63
Occasionally Windows/Microsoft Updates will fail to update. We have found a code that will delete all temporary files and re-register all dll's related to Windows/Microsoft Updates! This works 99% of the time to get the updates working again! The…
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…
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.

810 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