how to use crontab on linux?

Published on Aug. 22, 2023, 12:14 p.m.

To use crontab on Linux, follow these steps:

Open a terminal window.
Type crontab -e to open the crontab file in your default text editor.
Add a new line to the file with the format:
* * * * * /path/to/command arg1 arg2

The * represents the time and date that the command will be executed. Here are the values for each field from left to right:

Minute (0-59)
Hour (0-23)
Day of the month (1-31)
Month (1-12)
Day of the week (0-6, where Sunday is 0)

Replace /path/to/command arg1 arg2 with the command or script you want to run.
Save the file and exit the text editor.
The cron daemon will execute the command at the specified time and date. You can view your current crontab entries by typing crontab -l in the terminal. Note that it’s important to test your cron jobs to make sure they run correctly and produce the desired results.

how to restart chrome use cron

To restart Google Chrome at a specific time or interval using cron on Linux, you can create a simple bash script that kills all instances of Google Chrome and then starts it again. Here’s an example:

  1. Open a text editor and create a new file called chrome_restart.sh.
  2. Add the following code to the file:
#!/bin/bash
pkill -f "chrome"
google-chrome-stable &

Save and close the file.
Open the crontab editor by typing crontab -e in the terminal.
Add a new line to the crontab file with the following format:
* */2 * * * /bin/bash /path/to/chrome_restart.sh
This will restart Chrome every two hours. You can customize the time and frequency as needed. 6. Save and exit the crontab editor.

Now, the chrome_restart.sh script will be executed at the specified time and date, killing all running instances of Google Chrome and starting it anew.

Tags:

related content