Everyone,
I know ... this sounds like an easy one, but I have done my homework and tried tons of stuff. It doesn't work. This is not a typical "kill $pid" solution.
I want a script to run when the machine is booted, which will prompt the user to make some initial config settings. However, the user may only do this once - during installation, and the server will likely be headless after that. So, I need the script to timeout.
Here is my approach:
1. A script called launch.sh is executed from rc.local on each boot. All it does, is launch prompt.sh, grab its process ID and kill it after 5 seconds.
2. The prompt.sh script simply asks the user if they want to run a setup utility (called test.sh). If they don't respond in 5 seconds, the prompt.sh script is killed by launch.sh. If they respond with a 'Yes', then the prompt.sh script executes test.sh and then terminates. In this case, when launch.sh tries to terminate prompt.sh, it shouldn't be running anymore - so it doesn't matter.
3. The test.sh script should now be running if the user answered 'Yes' to the prompt.sh script.
Now, here is where things go wrong. When launch.sh terminates prompt.sh, it messes up the screen and the ability of the user to interact with the test.sh dialog.
Why?
The scripts are very short and simple. See below. Just edit the few paths and give it a whirl to see what I mean.
Thanks in advance to anyone who can help!
Eric
-----------------launch.sh---------------------------------------------------------------------
Code:
#!/bin/bash
# -----------------------------------------------------------
# This launch.sh script will be executed by rc.local on boot.
# -----------------------------------------------------------
# -------------------------------------------
# Execute prompt.sh and grab it's process ID:
# -------------------------------------------
/root/test/prompt.sh &
pid=$!
#----------------------------------------------------
# Give the user 5 seconds to interact with prompt.sh:
# ---------------------------------------------------
sleep 5
# --------------------------------------
# Kill prompt.sh if it is still running:
# --------------------------------------
kill $pid
exit 0
---------------------------prompt.sh-----------------------------------------------------------
Code:
#!/bin/bash
#
# ---------------------------------------------------------------------
# This script is executed by launch.sh. If the user has not responded
# to the yes/no prompt in the set time, then launch.sh will terminate
# this script so that the normal boot may continue.
# ---------------------------------------------------------------------
dialog --backtitle "Setup Utility" \
--title "Setup" \
--clear \
--yesno "\nDo you wish to execute the setup utility? \n\nNormal boot will continue in 5 seconds." 12 30
case $? in
0)
/root/test/test.sh;;
esac
exit 0
---------------------------test.sh-----------------------------------------------------------
Code:
#!/bin/bash
#
# ----------------------------------------------------------------------------
# This script is launched by the prompt.sh script if the user answers 'yes'.
# ----------------------------------------------------------------------------
# ----------------------------------------------------------------------------
# FUNCTIONS
# ----------------------------------------------------------------------------
function main {
HOST_IP_ADDRESS=""
HOST_NET_MASK=""
HOST_GATEWAY=""
HOST_DNS_1=""
HOST_DNS_2=""
GUEST_IP_ADDRESS=""
GUEST_NET_MASK=""
GUEST_GATEWAY=""
GUEST_DNS_1=""
GUEST_DNS_2=""
dialog --backtitle "CIMonitor Setup Utility" \
--title "Network Settings" \
--form "Enter the IP address for each field:" 17 42 10 \
"Server IP Address: " 1 1 "$HOST_IP_ADDRESS" 1 22 15 0 \
"Server Net Mask : " 2 1 "$HOST_NET_MASK" 2 22 15 0 \
"Server Gateway : " 3 1 "$HOST_GATEWAY" 3 22 15 0 \
"Server DNS 1 : " 4 1 "$HOST_DNS_1" 4 22 15 0 \
"Server DNS 2 : " 5 1 "$HOST_DNS_2" 5 22 15 0 \
"Manager IP Address: " 6 1 "$GUEST_IP_ADDRESS" 6 22 15 0 \
"Manager Net Mask : " 7 1 "$GUEST_NET_MASK" 7 22 15 0 \
"Manager Gateway : " 8 1 "$GUEST_GATEWAY" 8 22 15 0 \
"Manager DNS 1 : " 9 1 "$GUEST_DNS_1" 9 22 15 0 \
"Manager DNS 2 : " 10 1 "$GUEST_DNS_2" 10 22 15 0
}
# ----------------------------------------------------------------------------
# MAIN
# ----------------------------------------------------------------------------
main
exit 0