In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail the reasons for the non-execution of crontab timing tasks in Linux. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.
In order to facilitate the display, put the script into the parameter, all written dead
#! / usr/bin/env bash# 1 output file To log for example: bg# 2 target file directory without the last / for example: / opt/flume/home/hdp_lbg_ectech/rawdata/xxx/web_vip_bg# 3 when executing, select the log of the previous few days, for example: 1LASTIX daylight $(date + "% Y-%m-%d"-d "1 days ago") LAST_HOUR_DAY=$ (date + "% Y%m%d"-d "1 days ago") # implementation Line jar to get the bg log java-jar / opt/script/xxx/vipbg/vip-bg-job-1.0-SNAPSHOT-shaded.jar / opt/script/xxx/vipbg/bg.log# specific to the filename SRC_FILE=/opt/script/xxx/vipbg/bg.log# specify the target directory Create a directory by date DEST_DIR_NAME=/opt/flume/home/hdp_lbg_ectech/rawdata/xxx/web_vip_bg/$LAST_HOUR_DAYDEST_FILE_NAME=$ (basename $SRC_FILE) # FLUME ignores hidden files Therefore, you can directly copy the past TMP_FILE=$DEST_DIR_NAME/.$DEST_FILE_NAMEDEST_FILE=$DEST_DIR_NAME/$DEST_FILE_NAME.$SRC_IP# to determine whether the source file is not empty, the empty file Flume will be deleted directly, and the target file does not exist. Avoid duplicating data if [- s "$SRC_FILE"] & & [!-f "$DEST_FILE"] Then # enables Flume to delete files in this directory, otherwise FLUME cannot collect mkdir-p $DEST_DIR_NAME & & chmod 777 $DEST_DIR_NAME # you must first cp to a temporary file and then mv it. Direct cp in the past will cause data loss cp $SRC_FILE $TMP_FILE & & mv $TMP_FILE $DEST_FILEfi# delete tmp transfer file rm-rf / opt/script/xxx/vipbg/bg.logecho "delete source file successfully"
Some catalogs are represented by xxx
This script can be executed separately, but it will not be executed if it is put into crontab. Baidu mostly said that it needs to use an absolute path. After taking a look at our script, there is something wrong with the following sentence:
Java-jar / opt/script/xxx/vipbg/vip-bg-job-1.0-SNAPSHOT-shaded.jar / opt/script/xxx/vipbg/bg.log
The preliminary judgment is that java needs to use the directory path of jdk. Two experiments have been done to test it.
Add a java-jar xxxx.jar scheduled task to crontab
10 16 * java-jar / opt/script/xxx/vipbg/vip-bg-job-1.0-SNAPSHOT-shaded.jar / opt/script/xxx/vipbg/bg.log
Sure enough, this was not carried out.
Add a scheduled task of jdk directory / bin/java-jar xxxx.jar to crontab
20 16 * / opt/soft/jdk/jdk1.6.0_45/bin/java-jar / opt/script/xxx/vipbg/vip-bg-job-1.0-SNAPSHOT-shaded.jar / opt/script/xxx/vipbg/bg.log
The reason for not executing this time is that when you execute jar, you need to add the path of jdk.
This is the end of the article on "what is the reason why crontab scheduled tasks are not executed in Linux". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.