I created the following script to install and then uninstall PHPmyadmin on Ubuntu 16.04...
My aim is to use this script each time I want to use PHPmyadmin, and then, after some time like 2 hours, delete it. This install-use-uninstall method is used from security reasons (keeping MySQL inaccessible as possible and accessed only locally for very short periods of time).
bash /dev/fd/15 15<< 'EOF0' #!/bin/bash -x # Install commands: sudo apt-get install phpmyadmin sudo phpenmod mcrypt sudo phpenmod mbstring cat << EOF1 >> /etc/apache2/apache2.conf Include /etc/phpmyadmin/apache.conf EOF1 sudo service apache2 restart # Unnstall commands: sleep 2h sudo phpdismod mcrypt mbstring sudo apt-get purge phpmyadmin sudo service apache2 restart sed -i 's/Include \/etc\/phpmyadmin\/apache.conf/ /g /etc/apache2/apache2.conf EOF0
As noted in the comments by Jeff (and as I edited the code example) I could use the
sleep command, but
sleep, in its classical form requires that the session will keep open, and the window might close sometimes from whatever reason, so a cannonical answer is needed that shows how to give this 2 hour suspension but in such a way that even if I mistakenly/intentionally close the window, or my PC rebooted from any reason, or there was a power outage --- The suspension and all commands after it will keep running on the VPS, without any interference from my end.
So, how could I execute the uninstall-commands 2 hours after the install-commands, but in a session-independent way?