简体   繁体   中英

Execute Interactive Script on boot and display to default tty attached monitor screen

I have configured my Centos 6 to autologin on every boot.

I have modified the /etc/init/tty.conf to achieve this, this works fine.

content of /etc/init/tty.conf

stop on runlevel [S016]

respawn
instance $TTY
#exec /sbin/mingetty $TTY
exec /sbin/mingetty --autologin root $TTY
usage 'tty TTY=/dev/ttyX  - where X is console id'

Then I have configured my ~/.bash_profile to run a script. See below the content.

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH


echo "This is one time" >/tmp/one.txt

As you can see above I have echo'd text to a file /tmp/one.txt, Expected text in the file should appear only one time. But for some reason this script is executed 3 times .

If I tail -f /tmp/one.txt following appears in /tmp/one.txt. It shows that the script is executed 3 times.

tail -f /netboot/tmp/one.txt
This is one time
tail: /netboot/tmp/one.txt: file truncated
This is one time
tail: /netboot/tmp/one.txt: file truncated
This is one time
tail: /netboot/tmp/one.txt: file truncated
This is one time

What can I do to prevent it from executing it multiple times, I just want this to run once that's all.

Thanks for reading this post

I had to remove respawn instance $TTY from /etc/init/tty.conf file.

Before fixing /etc/init/tty.conf looks like this.

stop on runlevel [S016]

respawn
instance $TTY
#exec /sbin/mingetty $TTY
exec /sbin/mingetty --autologin root $TTY
usage 'tty TTY=/dev/ttyX  - where X is console id'

After fixing the problem. /etc/init/tty.conf looks like this.

stop on runlevel [S016]


exec /sbin/mingetty --autologin root $TTY
usage 'tty TTY=/dev/ttyX  - where X is console id'

This has fix the problem I have explain above.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM