Running a bash script in a program launcher

I have always included a “read” command at the end of a bash script if I wanted to pause the script, and keep the terminal window open, after the pre-programmed command sequence terminated. Recently, instead of running a script by double-clicking inside the file manager, I tried to run it using a program launcher. I double-clicked on the desktop icon for the launcher, but nothing seemed to happen. The terminal window that would normally display the results of the script’s commands never opened. It turns out that one needs to take additional steps to see what is happening when using a program launcher.

The problem is that “…the terminal closes when the command run inside it has finished…” So, if the command sequence is short, the terminal will open – and immediately close – and you won’t really see anything happen. The solution is that “…you need to write a command that doesn’t terminate immediately.”

In my specific case, I was experimenting with a script to safely remove a USB drive. That other operating system has such a facility, and this gives a notification to the effect that it is “Safe to Remove Hardware”. Under Linux Mint, I right-click on the USB drive’s icon, select “Eject”, but then have to wait until the red light stops flashing, before I pull out the drive.

Some sources indicate that unmounting a USB drive is the safest way to ensure that the operating system doesn’t have any data writes pending before disconnecting the drive. My intention was to have the script issue the umount command and then provide a message that it was safe to remove the drive.

My solution, therefore, was to create a bash script with two options one to note that the USB drive (a Silicon Power 16GB USB memory stick) wasn’t mounted should the script run while this was the case, or to indicate that the USB drive could be removed under the more usual scenario. The actual code for the script is as follows:

#!/bin/bash
# Check that SILICON16GB is mounted
if grep '/media/toaster/SILICON16GB' /etc/mtab > /dev/null 2>&1; 
 then
mate-terminal -e "bash -c \"umount /media/toaster/SILICON16GB;
 echo USB drive can be removed; echo ; exec bash\""  
else
mate-terminal -e "bash -c \"echo SILICON16GB is not mounted; 
 echo ; exec bash\""
echo " "
fi

The “trick” in this script is the use of two mate-terminal commands, one for each of the above-noted scenarios, and each including an “exec bash” statement in the executable argument. This final command effectively spawns a second instance of the terminal window which remains on the screen once the executable commands have been completed. This allows the user to review the specific message that is echoed to denote the status of the USB drive.

So, if running my script from the program launcher displays “USB drive can be removed”, I know that I can safely remove the memory stick.

References:

Pausing a bash script
https://linuxnorth.wordpress.com/2015/11/10/pausing-a-bash-script/

How to safely remove a USB external drive?
http://askubuntu.com/questions/203934/how-to-safely-remove-a-usb-external-drive

Linux Mint: Make a script/shortcut that can be clicked and run and will KEEP THE TERMINAL WINDOW OPEN afterwards [closed]
http://stackoverflow.com/questions/19372469/linux-mint-make-a-script-shortcut-that-can-be-clicked-and-run-and-will-keep-the

Avoid gnome-terminal close after script execution?
http://stackoverflow.com/questions/3512055/avoid-gnome-terminal-close-after-script-execution

Posted in Bash script, Mint | Tagged , | Leave a comment

Linux at 25

Happy Birthday Linux! Today marks the 25th anniversary of the announcement of work on the Linux kernel. “I’m doing a (free) operating system (just a hobby, won’t be big and professional like gnu)…” – Linus Torvalds, 25-Aug-91.
Continue reading

Posted in General | Leave a comment

Stop application windows snapping to full screen

Do you have an issue with moving a window by dragging it across the screen and it suddenly snapping (automatically maximizing) to full screen? If so, you let the top of the window touch the top of the screen and enabled automatic “snapping”. Fortunately, in Linux Mint, it’s a really easy fix.
Continue reading

Posted in Mint, Tweaks | Tagged , | Leave a comment

Opening Local HTML Files in Firefox under Android 6.0 (Marshmallow)

I use a local HTML file on all of my computing devices which lists all my frequently-used web sites on a multi-column page, with the individual entries being organized in categories. My new smartphone runs Android 6.0 which, for some reason seems to dislike opening the local HTML file in my favourite web browser, Mozilla Firefox.
Continue reading

Posted in Android, Applications | Tagged , | Leave a comment

Xed, Gedit, and Pluma in Mint 18

The default editor in Linux Mint 18 is Xed, a package that is based on Pluma, and which, according to Mint’s web site is meant to “…use traditional user interfaces…” and “…provide the functionality users already enjoy…” At face value, this is true, but when opening a file on my system, I quickly found it not to be the case.
Continue reading

Posted in Applications, Mint | Tagged , , , | 2 Comments

Installing FreeFileSync in Linux Mint 18

My main data backup program is FreeFileSync in both Linux and Windows. However, when I attempted to install this package in Linux Mint 18 (Sarah) using the usual command to add the relevant PPA (sudo add-apt-repository ppa:freefilesync/ffs), I received the error message: Cannot add PPA: ”This PPA does not support xenial”.
Continue reading

Posted in Applications, Backup, Commands, Mint | Tagged , | Leave a comment

Verifying the Linux Mint 18 ISO file

Linux Mint 18 (Sarah) was released a few days ago and I wanted to try the new version. However, I recalled that Mint’s web site had been hacked in February and a compromised version of the ISO file for Linux Mint 17.3 Cinnamon made available for downloading. Now, while this issue was quickly fixed, and greater security measures put in place, I thought it only reasonable to check the validity of the Mint 18 ISO file. However, the instructions provided on Mint’s web site weren’t entirely clear – nor accurate.
Continue reading

Posted in Commands, Mint | Tagged , | 2 Comments