step1: create a script file where write move command
touch opt/DO-NOT-TOUCH/script/save-phpmyadmin.sh
write command
#/opt/lampp/lampp stop
mv /opt/lampp/phpmyadmin /opt/lampp/phpmyadmin-bkp
#/opt/lampp/lampp restart
give permission
chmod +x /opt/DO-NOT-TOUCH/script/save-phpmyadmin.sh
step2: text editor to allow you to edit the crontab file (which contains scheduled tasks)
export EDITOR=vi
step3: open cron file
crontab -e
step 4: schedule a script file
30 * * * * /opt/DO-NOT-TOUCH/script/save-phpmyadmin.sh >> /var/log/weekly-site-backup.log 2>&1
The cron job 30 * * * * /opt/DO-NOT-TOUCH/script/save-phpmyadmin.sh >> /var/log/weekly-site-backup.log 2>&1 performs a scheduled task at a specific time and logs the output to a file. Let's break it down in detail:
Cron Timing: 30 * * * *
This represents the schedule at which the cron job runs:
Minute (30): The job will run at the 30th minute of every hour.
Hour (): The job will run every hour.
Day of the month (): The job will run every day of the month.
Month (): The job will run every month.
Day of the week (): The job will run every day of the week (i.e., no specific day is set).
Thus, 30 * * * * means this job will run at 30 minutes past every hour, every day, every month, and every day of the week.
Command to Run: /opt/DO-NOT-TOUCH/script/save-phpmyadmin.sh
This is the command/script that is executed by the cron job. Specifically:
It runs the script located at /opt/DO-NOT-TOUCH/script/save-phpmyadmin.sh.
This script likely performs some kind of backup or data save operation related to phpMyAdmin or MySQL databases.
Redirection to Log File: >> /var/log/weekly-site-backup.log 2>&1
This part handles the output of the cron job:
>> /var/log/weekly-site-backup.log:
This is output redirection. The >> operator appends the standard output (stdout) of the script to the file /var/log/weekly-site-backup.log.
If the log file doesn't exist, it will be created.
If the log file exists, the new output will be appended to the end of the file.
2>&1:
This part ensures that both standard output (stdout) and standard error (stderr) are redirected to the same log file.
2 refers to file descriptor 2, which is standard error (stderr).
&1 redirects stderr to the same location as stdout (1 refers to stdout).
In essence, 2>&1 ensures that any errors produced by the script are also logged in the /var/log/weekly-site-backup.log file.
Full Breakdown of the Cron Job:
Timing
: The job runs at the 30th minute of every hour.
Command
: It executes the script /opt/DO-NOT-TOUCH/script/save-phpmyadmin.sh
, which likely performs a backup or a similar operation.
Logging: The output of the script (both regular output and any error messages) is logged to /var/log/weekly-site-backup.log, allowing you to keep track of the job's execution and any potential issues.
Why Use This Cron Job?
Scheduled Backup
: This cron job is likely intended to run a backup script (save-phpmyadmin.sh) on a regular basis, specifically every hour at the 30-minute mark.
Logging for Troubleshooting: By redirecting both standard output and error output to a log file (/var/log/weekly-site-backup.log), you can monitor the success or failure of the backup operation. If anything goes wrong (e.g., the script fails), you can check the log file for detailed information about the error or the process.
Top comments (0)