I have created my first init script in a linux server (ubuntu if that adds any information) that checks for an update, downloads it and executes it in each hour. The init file is as follows:
/etc/init/updater.conf
start on (filesystem and stopped udevtrigger)
stop on runlevel [06]
console output
respawn
script
chvt 6
chvt 7
while true; do
# code to check update ...
if [ should_update ]; then
# Download the script
chmod +x /path/to/script.sh
bash /path/to/script.sh
rm /path/to/script.sh
fi
echo 'Rechecking for updates in 1h...'
sleep 1h
done
end script
The downloaded script starts as follows:
script.sh
#!/bin/bash
clear
exec > >(tee -i /var/log/update.log)
exec 2>&1
ScriptLoc=$(readlink -f "$0")
# check for root privilege
if [ "$(id -u)" != "0" ]; then
echo " This script must be run as root" 1>&2
echo
exit 1
fi
LOG_OUTPUT=/dev/tty4
(some_time_consuming_command 2>&1 > $LOG_OUTPUT) & spinner &!
The expected behavior is that after the installation of the linux finishes, the pressed will add the updater.conf
to /etc/init
which is done, then the linux reboots after the installation and shows the "Hello I will ..." message, then a spinner like this tuning [-]
while redirecting the output of the some_time_consuming_command
to TTY4
However, the current behavior is that the linux reboots in a black screen (TTY7) with nothing in it, when I switch to TTY1, I see the: "Hello I will begin installation message". I did not understand this behavior.
Can anyone guide me for achieving the expected behavior?
EDIT: After reading a bit, I found that /dev/tty7 is in general the default because of the linked /dev/console in it. Am I right? Could anyone explain why TTY7 is the default one in general? And am I looking for displaying init output to /dev/console instead of /dev/tty7?