当前位置:网站首页>Crontab pit stepping record: manual script execution is normal, but crontab timed script execution is abnormal
Crontab pit stepping record: manual script execution is normal, but crontab timed script execution is abnormal
2022-06-21 15:00:00 【I've been to places that span an hour】
One 、 introduction
Recently, I met an interesting problem in my work , The background is as follows :
I want to Linux Add a timed task to the environment , Every morning 3 Point to perform , Used to send some data files to the docking party
I am here $HOME/shell I wrote a script , then crontab Set up an execution plan , Do it manually The script , Found no problem on the happy off work .
Who knows, the next day the docking party contacted me and said , In the morning 3 I didn't get the document .
What's the situation ? I didn't check it out crontab Is the configuration of ?
I went over my script log again , Surprised to find an incredible problem :
crontab The result of execution is obviously different from that of manual execution
Why is that ?
Two 、 Explore
I checked it carefully crontab Configuration of , There are no configuration errors ; Again Do it manually The script was created , And I didn't find any problems . In the end, I can only ask for help from script logs , Finally found some clues :
1. In my script , Using a self-made executable program $HOME/bin/PushFile Program to send files , And this executable is in Do it manually When , It can be found , But in crontab When it's automatic , But I can't find it , So there is a problem of script running abnormally , Causes the file to fail to send
2. So why crontab Automatic execution can't find executable program ? because $HOME/bin There are no variables in the environment $PATH in . When our users log in , My own .profile The file added itself PATH="$HOME/bin:$PATH" The environment variable definition of , and crontab did not
in general , Namely :
because crontab Missing initialization of some environment variables , Some executable programs that are invoked in the script are $PATH Not found in , So the script execution is abnormal
therefore , That's what led to this crontab Automatic execution exception , But there is no problem with manual execution .
3、 ... and 、 solve
So how to solve this problem , There are two ways :
1. modify crontab Task allocation
0 3 * * * (. /home/wangying/.profile; sh /home/wangying/SendFile.sh)
2. modify SendFile.sh Script , Put it PushFile Call to full path /home/wangying/bin/PushFile
All in all , It is to let the script find the location of the executable program in the script , Either initialize the environment variables , Or give the full path of the executable program . such , We can solve the problems in the introduction ~~~
I hope this blog can help you :)
边栏推荐
- C language function fgets
- Niuke - real exercise-01
- Calculate subtotal of advertising business
- JS written test question: array
- ‘maxflow‘ has no attribute ‘Graph‘
- Subshell
- Shell uses arrays
- Redis5.0 installation and production startup steps
- Cool background shadow effect [second with layered feeling] [picture hover style]
- [go] time package
猜你喜欢

Chapter 2 - physical layer (I)

Vscade, open a folder or workspace... (file - > open folder) solution

Chapter 4 - network layer
![[leetcode] sum of two numbers - go language solution](/img/b8/d40cfe3efeedd816c5b81a1c939bd7.jpg)
[leetcode] sum of two numbers - go language solution
![NPM package management configuration file [package.json and node\u modules configuration details and how to develop their own packages and publish them on NPM]](/img/ff/2b92de728494542f614d4d5a57d20c.jpg)
NPM package management configuration file [package.json and node\u modules configuration details and how to develop their own packages and publish them on NPM]

New project template of punctual atom F103 based on firmware library

Teach you to stop visiting a website
![Flex layout --- detailed explanation [Blue Bridge Cup classic dice layout]](/img/9b/bb030e7b4be833051d6bc3974e4184.jpg)
Flex layout --- detailed explanation [Blue Bridge Cup classic dice layout]

2022 Hunan latest fire facility operator simulation test question bank and answers

Promotion guide for large enterprises: material preparation, PPT writing and on-site defense
随机推荐
SAP QM qs41 attempts to maintain a code group with a catalog of 3 and reports an error -you need to maintain catalog 3
Solution of difficult and miscellaneous problems in MVN packaging
Learn upward management and four questioning skills to get twice the result with half the effort
T32 add toolbar button
Numpy: basic package for high performance scientific computing & data analysis
Teach you to stop visiting a website
How is the redemption time of financial products stipulated?
ConnectionOptions. Username attribute definition
[font multi line display ellipsis] and [dialog box] implementation ----- case explanation, executable code
Connecting MySQL with C language under Windows system
JS interview question: regular expression, to be updated
Program for counting black and white pixel values in pictures
Computer shortcuts During sorting, fill in as needed
Use OpenCV to decompose the video into single frame pictures and synthesize the video with pictures
Somme factorielle
There is a PPP protocol between routers. How can there be an ARP broadcast protocol
New project template of punctual atom F103 based on firmware library
UBI error: ubi_ read_ volume_ table: the layout volume was not found
Phy336 Computational Physics
C language function fgets