Freitag, 10. August 2012

Autostart a terminal at gnome startup with several tools running

The first thing i do when my linux system is up i open a new terminal and start several tools to monitor my system. Can we start the desktop environment with a shell already running these tools?

Yes we can.

I used this command line:
gnome-terminal --tab-with-profile="Default" -e "systemd-journalctl -f -a" --tab-with-profile="Default" -e htop --tab-with-profile="Default"

and added it as a gnome-session-properties autostart program.
This opens a gnome-terminal with 3 tabs. In each tab running systemd-journalctl, htop and a clear one for further tasks like updating the system. Each tab uses the "Default" profile. The --tab-with-profile="Default" uses this profile in each new tab. The -e Option specifies the program you want to start in this particular tab. Note that if you want to parse options to one of these tools you have to quote them.

You also can combine these tools with pipes and logic operators. If you want for example an autoupdate on a debian based system you could do this by using this autostart command-line:

gnome-terminal -e "sudo apt-get update && sudo apt-get upgrade && sudo apt-get clean && sudo update-command-not-found && sudo -k"

This will update your system as root,- if you have configured your /etc/sudoers file correlatively,- and will close the shell or the tab when the update is finished or cannot be issued.

One last thing that may annoy you is that every time the gnome-terminal does not start in full maximized mode by default. Using gnome-terminal --help-window-options reveals that you simply have to append --maximize to your options.

And it works perfect.

Summary gnome-terminal options:

-e "<Command>" Starts the gnome Terminal with this command executed. Using Quotes is only neccessary if you want to use options or links
several programs together with logical operators.

--tab-with-profile="<Profile>" opens a new tab with the Profile for each time this option is used. After each Option you can pass on the -e to sepcify which
program should be running in each tab.

--maximize start the gnome-terminal maximzed.