My Goal:
Execute a shell script after login which runs with root privileges and takes the appropriate user input from a terminal window to determine its next course of action.
The Script:
The script I'm running tells the user that a second script will automatically be initiated in 60 seconds unless the user enters s or S. A countdown displays the remaining time. If the user entered the correct exit command, the script ends and the system carries on as normal. If nothing valid is entered in 60 seconds, then the second script is initiated. The second script needs to also be executed as root (hence why the first one must be initiated as root), since it has a watchdog which executes a hard reboot of the system in the event of a hardware failure.
Bash Script:
#!/bin/bash
#Prompt user with information.
echo "Miner will begin in 60 seconds."
echo "Press s + enter to stop the process and resume normal operation."
#Declare variables.
input="a"
let seconds=60
#Await user input and countdown.
while [ $seconds -gt 0 ]; do
printf "
........."$seconds
read -s -t 1 input
let "seconds-=1"
if [ "$input" = "s" ] || [ "$input" = "S" ]; then
break
fi
done
echo
#Initiate user selection
if [ "$input" = "s" ] || [ "$input" = "S" ]; then
echo "Resuming normal operation."
sleep 2
else
echo "Starting miner."
sleep 2
./TeamRedMiner_Config.sh
fi
Purpose:
This script is meant to restart a mining program after the watchdog restarts the system in the event of a GPU failure. The user prompt gives me time to stop the miner from executing after login if I want to use the system as normal. I'm usually away from the system, so this is pretty important to keep the mining operation going. GPU failure is fairly common after running 2 + days (despite underclock, undervolt, ect.) for one of my cards as she's getting very old at this point (over 6 yrs).
I've done a good amount of research and have yet to find a solution that has worked for me. Most focus on executing a script which requires no external input or terminal window. If it does, then it's only a few commands. I need something that launches a terminal window so I can see the prompts and the countdown. Additionally, I need the terminal window to display the miner status after it launches.
What I've tried:
Initial Conditions: File is .sh, executable, and owned by root.
- Utilize systemd to execute the script as a .service file (nothing happened)
- Utilize crontab to execute the script at boot (nothing happened)
- Placing the script in
profile.d
(Lubuntu took longer to log in, though nothing happened) - Editing the
$HOME/.bashrc
and$HOME/.profile
files by adding./AutoStartMiner.sh
to the top of the files (resulted in a system hang)
Hopefully this shows I put in a good amount of effort and we can find a solution to this issue. Thanks!