Tonight I was working on creating some some listeners that run automatically on boot in Ubuntu. Not only should they run automatically but there should be scripts to start, stop, and watch the status of the listeners for incoming traffic. I also decided to add the items to the Ubuntu Applications menu and thought it would be neat if when the menu item was selected that it automatically launched a terminal window and ran the command automatically. Turns out that doing exactly that is really easy as explained below.
Launch Terminal Window & Run Command From Gnome Menu Item:
So once you know where new menu items go which are .desktop files located in /usr/share/applications and the basic format of what the .desktop files look like you could change the exec line to begin with gnome-terminal as shown in the below example .desktop file.
Example .desktop File That Runs Command In A Gnome Terminal Window:
- [Desktop Entry]
- Version=1.0
- Name=Watch Listeners
- Categories=Application;System;
- Exec=gnome-terminal -e /usr/local/bin/watchlisteners.sh
- Terminal=true
- Type=Application
- Name[en_US]=Watch Listeners
- GenericName[en_US]=Watch Listeners
The watchlisteners.sh script uses netstat to watch for specific open ports which indicate that inbound connections have been made as shown in the below example image.
Gnome Terminal Running Bash Script Launched From Gnome Menu Item:
Thats it! Please note that the terminal is technically useless except for this single task as when you attempt to stop the command the Gnome Terminal window will close.