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 $$))