Apple cms scheduled task Crontab sets Apple cms automatic update script

There are several ways to update the scheduled tasks of Apple CMS. If the Apple CMS is built in Windows, you can use the scheduled task update that comes with Windows. If it is a Linux operating system, you can set up scheduled update tasks on third-party platforms, or set up custom update tasks on third-party websites such as Alibaba Cloud and Tencent Cloud. The following introduces another way to use the crontab command in the Linux system to set up scheduled tasks to automatically update the website.

How to use Crontab command to set up automatic update of scheduled tasks in Apple CMS

There are several ways to update the scheduled tasks of Apple CMS. If you are using Apple CMS built on Windows, you can use the scheduled tasks that come with Windows. If you are using the Linux operating system, you can set up scheduled update tasks on third-party platforms, or set up custom update tasks on third-party websites such as Alibaba Cloud and Tencent Cloud. The following is another way to use the crontab command to set up scheduled tasks in the Linux system..

Understand what crontab is

With the crontab command, we can execute specified system commands or shell scripts at fixed intervals. The time interval can be in minutes, hours, days, months, weeks, or any combination of the above. This command is very suitable for periodic log analysis or data backup.

Format

crontab [-u user] file crontab [-u user] [ -e | -l | -r ]

Command Parameters

-u user: used to set a user's crontab service;
file: file is the name of the command file, which means that file is used as the task list file of crontab and loaded into crontab. If this file is not specified in the command line, the crontab command will accept the commands typed on the standard input (keyboard) and load them into crontab.
-e: Edit the crontab file content of a certain user. If no user is specified, it means editing the crontab file of the current user.
-l: Displays the contents of a user's crontab file. If no user is specified, it means displaying the contents of the current user's crontab file.
-r: Delete a user's crontab file from the /var/spool/cron directory. If no user is specified, the crontab file of the current user is deleted by default.
-i: Prompt for confirmation when deleting a user's crontab file.

crontab file format

Commands to be run by day, month and week

  • Column 1: Minutes 0 to 59
  • The second column is the hour 0 to 23 (0 means midnight)
  • Day 3 1-31
  • Column 4 Month 1 to 12
  • Column 5: Day of the week 0 to 7 (0 and 7 represent Sunday)
  • Column 6 The command to be run
# .---------------- Minute, the value range is 0-59 # | .------------- Hour, the value range is 0-23 # | | .---------- Day, the value range is 1-31 # | | | .------- Month, the value range is 1-12 # | | | | .---- Day of the week, the value range is 0-7, 0 and 7 both mean Sunday# | | | | | .-- Command to be executed# | | | | | | 0 19 * * * bash /root/test.sh

Apple cms scheduled tasks

Next, configure the scheduled task of Apple CMS. First, in the background of Apple CMSsystemIn the optionsScheduled task configuration.

Apple cms scheduled task Crontab sets Apple cms automatic update script

In the operation options following the task that needs to be automatically updated,testRight-click on the mouse, then clickCopy link addressGettestURL address.

For example:

https://xxx.com/api.php/timming/index.html?enforce=1&name=lz https://xxx.com/api.php/timming/index.html?enforce=1&name=sd https://xxx.com/api.php/timming/index.html?enforce=1&name=xl https://xxx.com/api.php/timming/index.html?enforce=1&name=kc https://xxx.com/api.php/timming/index.html?enforce=1&name=gs

These URLs are opened in the browser and need to be valid links that can update the website normally.

Next, set up a scheduled task in the Linux system.

Install crontab

Generally, CentOS will install crontab by default. Execute the following command to check whether it is installed:

rpm -qa | grep crontab

If the query result is similar to the following, it means it has been installed:

Apple cms scheduled task Crontab sets Apple cms automatic update script

If the result is empty, it means it is not installed. Run the following command to install it:

dnf install -y crontabs

Crontab Common Commands

Check the crontab running status:

systemctl status crond

As shown in the figure above, if the result displayed is Active: active (running), it means it is running, and Active: inactive (dead), it means it is not running.

If crontab is not running, you can set it to start automatically at boot time using the following command.

Set crontab to start automatically at boot:

systemctl enable crond

Start crontab:

systemctl start crond

View the current user's scheduled tasks:

crontab -l

Set up scheduled tasks

First, create a vod.sh script in the root directory.

vi /root/vod.sh

Press i to enter the editing state and paste the following content:

#! /bin/bash a=$(curl -k 'https://xxx.com/api.php/timming/index.html?enforce=1&name=lz') b=$(curl -k 'https://xxx.com/api.php/timming/index.html?enforce=1&name=sd') c=$(curl -k 'https://xxx.com/api.php/timming/index.html?enforce=1&name=xl') d=$(curl -k 'https://xxx.com/api.php/timming/index.html?enforce=1&name=kc') e=$(curl -k 'https://xxx.com/api.php/timming/index.html?enforce=1&name=gs') echo $a sleep 10 echo $b sleep 10 echo $c sleep 10 echo $d sleep 10 echo $e

Press the Esc key and enter :wq to save the file.

You can also use the following writing method, the effect is the same.

#!/bin/bash func() { curl 'https://xxx.com/api.php/timming/index.html?enforce=1&name=gs' touch gs echo "gs opened" } func & sleep 5 if [ -f gs ] then echo "gs succeeded" else echo "gs failed" fi rm -f gs sleep 10 func() { curl 'https://xxx.com/api.php/timming/index.html?enforce=1&name=kc' touch kc echo "kc opened" } func & sleep 5 if [ -f kc ] then echo "kc succeeded" else echo "kc failed" fi rm -f kc sleep 10 func() { curl 'https://xxx.com/api.php/timming/index.html?enforce=1&name=sd' touch sd echo "sd opened" } func & sleep 5 if [ -f sd ] then echo "sd success" else echo "sd failure" fi rm -f sd sleep 10 func() { curl 'https://xxx.com/api.php/timming/index.html?enforce=1&name=xl' touch xl echo "xl opened" } func & sleep 5 if [ -f xl ] then echo "xl success" else echo "xl failed" fi rm -f xl sleep 10 func() { curl 'https://xxx.com/api.php/timming/index.html?enforce=1&name=lz' touch lz echo "lz opened" } func & sleep 10 if [ -f lz ] then echo "lz success" else echo "lz failed" fi rm -f lz

sleep Command Syntax Following is the syntax of the sleep command in Bash:
sleep number[suffix]
You can use positive integers or decimals as time values. The suffix is optional. You can use any of the following as a suffix:

  • s - represents seconds
  • m - represents minutes
  • h - represents the hour
  • d - for day

NOTE: If there is no suffix, the number is in seconds (by default).

If two or more parameters are specified, the total time is considered to be equal to the sum of the values. Here are some simple examples that demonstrate how to use the sleep command:

  • To sleep for 9 seconds, use:
    sleep 9 or sleep 9s
  • To sleep for 0.5 seconds, use:
    sleep 0.5 or sleep 0.5s
  • To sleep for 2 minutes and 30 seconds, use:
    sleep 2m 30s
  • Sleep 8 hours, use:
    sleep 8h
  • Sleep 2 days 9 hours 5 minutes 55 seconds, use:
    sleep 2d 9h 5m 55s

Execute the following command to edit the current user's scheduled tasks:

crontab -e

After executing the crontab -e command, a document will be opened. Press i to enter the editing state. Paste the following content into the document. Then save and exit!

0 19 * * * bash /root/vod.sh

The above code means that the /root/vod.sh script is executed at 19:00 every day.

If you want to execute the script once every hour, you can add it one by one.

Note: In the configuration file of the scheduled task, you cannot enter 24 at 24:00, but must enter 0, otherwise an error will be reported!

For example:

0 1 * * * bash /root/vod.sh 0 2 * * * bash /root/vod.sh 0 3 * * * bash /root/vod.sh 0 4 * * * bash /root/vod.sh 0 5 * * * bash /root/vod.sh 0 6 * * * bash /root/vod.sh 0 7 * * * bash /root/vod.sh 0 8 * * * bash /root/vod.sh 0 9 * * * bash /root/vod.sh 0 10 * * * bash /root/vod.sh 0 11 * * * bash /root/vod.sh 0 12 * * * bash /root/vod.sh 0 13 * * * bash /root/vod.sh 0 14 * * * bash /root/vod.sh 0 15 * * * bash /root/vod.sh 0 16 * * * bash /root/vod.sh 0 17 * * * bash /root/vod.sh 0 18 * * * bash /root/vod.sh 0 19 * * * bash /root/vod.sh 0 20 * * * bash /root/vod.sh 0 21 * * * bash /root/vod.sh 0 22 * * * bash /root/vod.sh 0 23 * * * bash /root/vod.sh 0 0 * * * bash /root/vod.sh

Issues with crontab not executing

  • Check if bash or /etc/profile;/bin/sh is added before the script path
  • Check whether the crontab service is normal
  • Check if the script path is absolute

The curl request url contains & and the request fails

In a curl request, when the URL contains multiple parameters, the URL needs to be enclosed in single quotes, otherwise the request will be truncated. Just enclose the contents of the URL in single quotes.

Three ways to open web pages using the command line in Ubuntu

The first method links command

apt install links links 'https://uzbox.com'

The second method is w3m command

apt install w3m w3m 'https://uzbox.com'

The third method is the lynx command

apt install lynx lynx 'https://uzbox.com'

 

 

5/5 - (1 vote)

Leave a Reply

Your email address will not be published. Required fields are marked *