Run your apps in the system background

The cron utility is a job-scheduling tool found on all Linux and Unix operating systems, as well as macOS. Although cron is typically used to schedule jobs at fixed times, dates, and intervals, it can also launch jobs at system boot time. This guide explains how to use the cron utility and the crontab file to run a job or script when the system boots. Here we can use this facility to run a specific file or an entire projects like Telegram bots, applications or any dtabase operations at the time of boot up and the applications will be continue to run in backgroud, and there wont be any interfaces for the same on the desktop.


Here I'm demostrating a script that run a Telegram Bot. I'm using an Ubuntu PC for the same. You can use your VPS / any linux distros, or even small PCs like raspberry Pi too for this purpose.


1. First, I need to create a shell script and save it in any directory. Here I'm using the file name run.sh

Here in this script, you need to write the first line to change to the working directory of your original project following the remaining excecution commands.


2. Open terminal as super user (su). If you didn't set a super user password, then set it first and restart this process.

3. Chanage the directory to the script created using the commend

4. List the files in the dicrectory using command (Optional)

Then the script file that you have previously created will be listed in the terminal (along with the other files if there are files in the same directory). Note the file name you required once more. In the next step you need to make this file bootable in order to run in the cron.

5. To make the file bootable, run the command

Here I've used the file name as run.sh | You have to use the file that you previously created.

6. Now, open the crontab using the command

If you are opening the crontab fist time, then it will ask how to open the same, select your convenient method. I'd prefer to use the 'nano'. select the number and hit enter. The nano editor will open and scroll down to its bottom. The next step, add a command that can run the script in every system reboot.

7. Add the command to run the script in system background.

If you are using 'nano' hit Ctrl + O to save the file and close the nano window using Ctrl + X. This will return to the previous super user terminal. Finally, reboot the system using the command.

8. To reboot the system, use the commad

After rebooting the system, the script you have created will run in background, finally run the project that you created. When you have to update the script, just go for a code edit and reboot the pc. This is a nice and cool method to run your projects in the sytem background. Multiple projects can be run just like this we done.

Comments

Popular posts from this blog

Clonebot Technical Documentation

Self-Regulating Battery Charger Circuit