Is it possible to close the parent terminal window once an application has been loaded?
I have a program I need to run using root privileges to work properly and currently I have made a script file which checks if the user is root if not then they are asked to confirm the root password before the application is loaded.
Original
Here is the contents of my script file:
#!/bin/bash
if [ "$EUID" -ne 0 ]
then
echo "You need root privileges to run this utility"
echo "Do you want to continue? (y/n):"
read userInput
if [ $userInput == "y" ] || [ $userInput == "Y" ]
then
sudo ./myGuiProgram
exit
elif [ $userInput == "n" ] || [ $userInput == "N" ]
then
echo "Exiting now..."
exit
fi
exit
elif [ "$EUID" -eq 0 ]
then
./myGuiProgram
exit
fi
Is there anything I can add to this that will close the terminal window and not myGuiProgram ?
On my Centos 7 machine I have a desktop config file which executes the script file which in turns runs myGuiProgram
2nd Attempt
I've modified my script since, but still no luck. This method allows me to exit the terminal window manually without closing my program
#!/bin/bash
if [ "$EUID" -ne 0 ]
then
echo "You need root privileges to run this utility"
echo "Do you want to continue? (y/n):"
read userInput
if [ $userInput == "y" ] || [ $userInput == "Y" ]
then
sudo nohup ./myGuiProgram > /dev/null & disown && kill $PPID
elif [ $userInput == "n" ] || [ $userInput == "N" ]
then
echo "Exiting now..."
fi
elif [ "$EUID" -eq 0 ]
then
nohup ./myGuiProgram > /dev/null & disown && kill $PPID
fi
MARco Working Solution
New changes made based on @MARco response. This method works well.
#!/bin/bash
if [ "$EUID" -ne 0 ]
then
echo "You need root privileges to run this utility"
echo "Do you want to continue? (y/n):"
read userInput
if [ $userInput == "y" ] || [ $userInput == "Y" ]
then
sudo -b nohup ./myGuiProgram 2>&1> /dev/null
elif [ $userInput == "n" ] || [ $userInput == "N" ]
then
echo "Exiting now..."
sleep 1
exit 0
fi
elif [ "$EUID" -eq 0 ]
then
nohup ./myGuiProgram > /dev/null 2>&1> /dev/null &
fi
kill $(ps -ho ppid -p $(ps -ho ppid -p $$))
myGuiProgramto error out if it's not being started byroot? – Panki Dec 03 '20 at 11:00command not founderror in my terminal window – hymcode Dec 03 '20 at 11:08root, but I want to at least inform the user and give them the ability to try confirmingrootprivileges for me. Think of it like Windows UAC control maybe. My script file will be loaded from a desktop config file which then loads the program – hymcode Dec 03 '20 at 11:27nohup ./myGuiProgram > /dev/null & disown && kill -9 $PPID– hymcode Dec 03 '20 at 11:33exitthe shell after nohuping or disowning or similar. – thanasisp Dec 03 '20 at 11:36exitstatement somewhere in my script? – hymcode Dec 03 '20 at 11:54