Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

doing a ps-e, I see the following on startup:

PID  TTY CMD
...
1880 ?   my_auto_script
1881 tty1 login
1882 tty2 getty

...

my_auto_script is called from /etc/rc.local. I have /etc/init.d/rc.local configured as such:

Required-Start: $all
Default-Start: 2 3 4 5

so this should run last. But it doesn't seem able to run after any tty processes. This is what I need. How do I make this work?

share|improve this question

2 Answers 2

The ttys are spawned from /etc/inittab. By default the lines that spawn them come after the lines that run the rc scripts. For example, in my (un-customized) inittab, I have:

...
l0:0:wait:/etc/init.d/rc 0
l1:1:wait:/etc/init.d/rc 1
l2:2:wait:/etc/init.d/rc 2
l3:3:wait:/etc/init.d/rc 3
l4:4:wait:/etc/init.d/rc 4
l5:5:wait:/etc/init.d/rc 5
l6:6:wait:/etc/init.d/rc 6
...
1:2345:respawn:/sbin/getty 38400 tty1
2:23:respawn:/sbin/getty 38400 tty2
3:23:respawn:/sbin/getty 38400 tty3
4:23:respawn:/sbin/getty 38400 tty4
5:23:respawn:/sbin/getty 38400 tty5
6:23:respawn:/sbin/getty 38400 tty6

So rc.local is actually sourced before your ttys are spawned. I don't believe switching the lines so they're the other way around is safe. I think you need to wait for someone more knowledgeable to confirm/refute.

If you're looking for last-minute customization before the users log in, why not drop a script in /etc/profile.d instead? This will affect shells started from a terminal emulator as well, not just the VTs.

share|improve this answer

The text mode login prompts appear after the startup programs have completed, including the ones run from /etc/rc.local. That's the point of startup programs: to be executed at startup, before users log in.

If you want to run a program when the system starts, and you want to allow users to log in before your program completes, you have two options. Many versions of cron allow you to specify @reboot instead of a running time to run a job at boot time; check the crontab(5) manual on your system to see if @reboot is supported. Alternatively, run your program from /etc/rc.local (or some other startup script), but in the background:

/path/to/my_auto_script &
share|improve this answer
    
my program has an infinite while loop and does run in the background, and that doesn't work well in my case. I tried putting in sleep commands, but that doesn't help –  mugetsu Oct 14 '13 at 17:26
    
@mugetsu If your program runs as long as the system stays up, make it a service, with its own file in /etc/init.d. What do you mean by “doesn't work well”? The program will start running just before users can log in and keep running as long as it wants even while users are logged in. –  Gilles Oct 14 '13 at 17:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.