- Start and stop application from terminal in Linux Mint 19 / Ubuntu 18.04
- Start application from terminal — Ubuntu / Linux Mint
- Schedule application start
- Build script starting application
- Stop application by id/name
- Application stop with delay
- Auto logout from Ubuntu / Linux Mint
- Bonus tip: schedule application stop
- Complete Guide for Managing Startup Applications in Ubuntu Linux: Learn to Add, Remove or Delay Startup Programs
- Managing startup applications in Ubuntu
- Remove startup applications in Ubuntu
- Delay the start up programs
- Add a program in the startup applications
- Step 1: find the command to run any application
- Step 2: Adding programs in startup
- Bonus Tip: See hidden startup programs in Ubuntu
- How to automatically run program on Linux startup
- Automatically run program on Linux startup via systemd
- Automatically run program on Linux startup via cron
- Automatically run program on Linux startup via rc.local
- Automatically run program on GNOME startup
- Automatically run program on KDE startup
- Automatically run program on new Bash session
Start and stop application from terminal in Linux Mint 19 / Ubuntu 18.04
In this article we will review several scenarios how to :
- Start application from terminal — Ubuntu / Linux Mint
- Schedule application start
- Build script starting application
- Stop application by id/name in Linux Mint / Ubuntu
- Application stop with delay
- Auto logout from Ubuntu / Linux Mint
- Bonus tip: schedule application stop
Start application from terminal — Ubuntu / Linux Mint
In order to start application from terminal you need to know the name of the application which is used in the system. Sometimes the system name can differ from the application name. For example:
- Chrome — google-chrome
- Chromium — chromium-browser
- Sublime — subl
You can find where a given application is installed by:
Also there you can search for applications.
In order to start give application you need to write it’s name in the terminal:
You can pass different parameters to the application which will be opened. For example which file to be opened for Libre office:
or what web sites to be opened with chrome:
Schedule application start
Sometimes you may want to schedule a script for opening a given application. In order to improve my performance and decrease the distractions I’m scheduling my mail to be opened two times per day: 10:00 and 16:00.
The scheduling in Linux usually is done with cron jobs:
- Open terminal
- Type: crontab -e — for current user only or sudo crontab -e
- finally add your job:
Some application can be started by their name but others will need some settings. For example in order to start thunderbird and display it you need to add this line in your crontab file:
the same way if you are using bash script to start another application. For example starting LibreOffice calc:
where libre office will be started after a csv file with data is downloaded from a website.(I’ll add new article on this topic).
Build script starting application
Building special scripts to start application can be helpful in order to automate boring stuff. I have 10 scripts which are helping me to do boring stuff like:
- reporting
- getting information from the web
- sending mails
- analysing data
- starting and stoping application — obviously from the article 🙂
Below you can find several examples below:
- the first row is going to «log» each time this scripted is executed
- the second one is opening thunderbird
A more complex example where:
this example is more complex. Here is what is done:
- activate special python virtual environment
- change to a special folder
- run a web spider in order to get information from Google
- analyze and change the data
- load the download data in calc
this script is run with a cron job every day and retrieves important information for me. If I need to do the same thing I’ll need to spend 10 to 30 minutes per day.
Stop application by id/name
To stop application from the terminal by id you will need to find the id first. This can be done by this command:
10882 10869 10831 10784 10781
Another alternative is:
10882 10869 10831 10784 10781
or the more verbose one:
user 2315 0.0 0.0 15648 1152 pts/1 S+ 18:38 0:00 grep —color=auto google-chrome
user 10781 0.3 0.4 1379564 151624 ? SLl 14:57 0:47 /usr/lib/..
and then you can extract the pid-s.
After that in order to stop the application you can use:
both do similar things but the one with -9 is more «aggressive» and forcing.
In order to stop/kill application by name you can use:
this is going to kill multiple processes by name.
Application stop with delay
Now let say that you want to stop a given application with some delay: 10 minutes, 1 hour or something else. You can do with by several different ways: cron job, script, third party software. In this case we will use simple script:
this script will wait for 1 hour and then will stop the application. So you can use a script to start a given application. This application to be executed for 1 hour and finally to be stopped.
Other times examples:
Note: You can’t use:
Auto logout from Ubuntu / Linux Mint
The final problem which we are going to cover in the article is about log out of inactive users. There is application for Ubuntu / Linux Mint which can be used — autolog. You can search in the software center and install it. Or you can install it by:
Bonus tip: schedule application stop
Let say that you work a lot google chrome, slack, zoom, pycharm or any other application in Linux Mint, Ubuntu. Most of the time is really difficult to end up your working day and leave your workplace. Automation to the rescue! Below you can find a simple script and how to use in order to schedule stop for your applications in Linux:
The script will show the current date and time. Then will wait for a given period of time ( in this case 30 minutes ) and finally will kill the application.
now you can schedule this script as a cronjob by:
Источник
Complete Guide for Managing Startup Applications in Ubuntu Linux: Learn to Add, Remove or Delay Startup Programs
Last updated October 29, 2020 By Abhishek Prakash 26 Comments
Every time you boot in to an operating system, a number of programs start running automatically. These are called ‘startup applications’ or ‘start up programs’.
I am not talking about essential programs like network manager here. I am talking about running Slack, Transmission torrent clients, Skype or other such regular programs.
Startup applications are a good way to save time and extend the usability of your Linux system. At the same time, you should not have too many startup applications. It may negatively impact the responsiveness of your system when you log in to it.
In this Ubuntu beginner’s guide, I’ll show you how to manage the startup applications. You’ll:
- Learn to add (almost) any program in the startup applications list to start them automatically at each boot.
- Learn to remove a program from the startup applications list so that you have a faster system when you boot into it.
- Learn to delay the running of a startup application so that it runs automatically but with a time delay. This way, not all startup applications consume the system resource simultaneously.
Managing startup applications in Ubuntu
By default, Ubuntu provides a Startup Applications utility that you could use. You may also use a third-party application like Stacer for managing the startup programs.
I’ll discuss the built-in utility first and then later in this tutorial, I’ll briefly touch on Stacer.
Go to the menu and look for startup applications as shown below.
Once you click on it, it will show you all the startup applications on your system:
Remove startup applications in Ubuntu
Now it is up to you to figure out what you need and what you don’t. In my case, Franz (an all-in-one messaging app) is no longer needed as a startup app. So, I’d like to disable it.
You can choose to either disable it or completely remove it from the list of startup apps.
Startup Application Preference Franz
To remove a program from startup applications list, select it and click on Remove from the right window pane.
Select And Remove
Removing unnecessary startup applications helps you speed up Ubuntu a little.
Delay the start up programs
What if you do not want to remove programs at the start up but want to optimize the system performance at the boot time?
In that case, you can add a delay in various programs so that not all the programs will be starting at the same time.
Select a program and click Edit.
This will show the command that runs this particular program.
All you need to do is to add sleep XX; before the command.
It will add a delay of XX seconds before running the actual commands to run the applications.
For example if I want to delay Sound Switcher Indicator for 2 minutes, I’ll add sleep 120; before the command like this:
Save it and close it. Reboot the system to see how it works.
Add a program in the startup applications
Some applications provide the “autostart” option in their settings. This enables you to easily add them to the list of startup applications.
But not all applications do this. For applications like Transmission or qBitTorrent torrent clients, there is no built-in option to auto start.
Fret not. I’ll show you a neat trick that you can use to autostart almost any application.
This could be tricky for beginners but it’s not rocket science. I’ll try to make it as easy as possible for you to be able to add a new program to startup applications.
Step 1: find the command to run any application
If you are using GNOME desktop environment, you can use alacarte menu editor. Other desktop environments may or may not have such utilities.
You can look for alacrte in the software center by searching ‘Main Menu’.
Alternatively, you can install it using this command:
Once installed, go to the system menu and search for Main Menu. In case Main Menu is not installed by default, then you can install it from the Software Center.
This contains all the programs that you have installed on your system.
Just look for the application you want to add and click on the Properties option on the right-side of the screen to see the command that runs this application. For example, I want to run qBittorrent client on start up. Here’s what I have to do:
When I select the target application and click on propertives, this will give me the command that runs qBittorrent:
Now I’ll use the same information to add qBittorrent in startup applications.
Step 2: Adding programs in startup
Head back to Startup Applications and click on Add. This will ask you enter a name, a command and comment (optional).
The command is the most important of all. You can use whatever name and comment (which is the description of the app) you want.
Use the command you got from previous step and click on Add.
Add Startup Program
That’s it. You’ll see it in the next boot up, running automatically. This is all you can do with startup applications in Ubuntu.
Bonus Tip: See hidden startup programs in Ubuntu
So, far we have discussed applications that are visible in startup but there are many more services, daemons and programs that are not visible to Startup applications.
In this section, you’ll see how to see hidden startup programs in Ubuntu and manage those.
To see what are the services running at startup, open a terminal and use the following command:
This is just a quick find and replace command that changes the NoDisplay=false with NoDisplay=true in all the programs that are in autostart. Once you do this, open Startup Applications again and now you shall see many more programs here:
As I’ve mentioned already, you can use Stacer to optimize your Ubuntu system. But, you can also manage the startup applications using the same.
Once you are done, head to the Startup Apps tab, and over here, you will find all the startup apps. As shown in the screenshot below, you can easily toggle, remove, and add startup apps using Stacer as well.
To add a startup app, you have to follow the same set of steps that I’ve mentioned above in order to add an application to startup.
Wrapping Up
I hope this Ubuntu tutorial helped you understand and manage startup applications. Feel free to let me know your thoughts in the comments below.
Like what you read? Please share it with others.
Источник
How to automatically run program on Linux startup
There are a few stages of Linux startup, and you can set your own autostart script or program at any of the stages where it could be a single command, a chain of commands, or an executable shell script. There could be, however, some differences in startup procedure between different Linux distributions and versions.
Modern Linux will first boot into systemd while older versions of Linux uses System V init. Both methods will run cron and rc.local before the desktop environment such as GNOME or KDE is loaded. On the other hand, server-based Linux distributions will run the default shell such as Bash after the user logged in at the console instead of loading the desktop environment.
Methods to automatically run program on Linux startup:
Automatically run program on Linux startup via systemd
systemd is the standard system and service manager in modern Linux. It is responsible for executing and managing programs during Linux startup, among many other things. Compatible programs will provide service unit files used by systemd to manage the program’s execution.
You can configure systemd to run programs automatically during Linux startup following these steps:
You’ll have to create your own service unit if it’s a custom program or if your program doesn’t come with one during installation
Related: Creating and modifying systemd unit files
enabled service unit is executed during boot
Automatically run program on Linux startup via cron
cron is a daemon to execute scheduled commands. The commands are stored in the cron job table or crontab and are unique for each user in the system. It’s started during system boot either by systemd or System V init, and you can schedule your job or program to be executed right during the system boot itself by following these steps:
You’re required to select an editor for the crontab if this is the first time the user uses the command.
A crontab will be created for the user running the command and will be executed using the privileges of the user. If you need your program to run as the root user, run crontab -e as the root user itself.
@reboot defines the job to be executed during system boot.
Use full path for your programs when possible and write your commands in a single line.
The file is saved in /var/spool/crontab/
Automatically run program on Linux startup via rc.local
rc.local is a legacy from the System V init system. It is the last script to be executed before proceeding to a login screen for the desktop environment or a login prompt at the terminal. It’s usually a Bash shell script, and you can run anything from the script.
You can configure your rc.local script following these steps:
It must start with interpreter (/bin/bash) and ends with an exit code (0 is for success)
The file will be executed as the root user during system boot
Automatically run program on GNOME startup
GNOME is the default desktop environment for Linux distributions such as Ubuntu and Red Hat. GNOME can be configured to run programs when a user logs in and can be configured by following the below article:
Automatically run program on KDE startup
KDE is another popular desktop environment for Linux and is the default in Kubuntu and openSUSE. It can easily be configured to run programs when a user logs in as detailed in the following article:
Automatically run program on new Bash session
A new shell program will be spawned when you start your terminal session. Bash is the default shell for most Linuxdistributions, and when started, it will look for the following files in the particular order and executes them.
These files contains commands and logics to set up proper environment variables and run required programs in Bash language. It’s also configured to normally execute other files such as /etc/bashrc, /etc/bash.bashrc and
You can edit any of these files to run your program when a Bash session is started. Below is a part of a typical
Comment anonymously. Login not required.
Источник