当前位置:网站首页>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 :)
边栏推荐
- HSV color model and color component range in opencv
- Nmap scan port tool
- Interview - difference between pointer and reference
- Office operation sorting notes
- Online keyboard key detection tool
- Invisible characters encountered \u200b
- So many statistical charts? This visualizer is great~~
- Calculate subtotal of advertising business
- For the first time in China, Tsinghua and other teams won the wsdm2022 only best paper award, and Hong Kong Chinese won the "time test Award"
- [untitled] fish pond forwarding command
猜你喜欢

Select everything between matching brackets in vs Code - select everything between matching brackets in vs Code

Usage of SED (replacement, deletion of text content, etc.)

Summary of the most basic methods of numpy
![[leetcode] sum of two numbers - go language solution](/img/b8/d40cfe3efeedd816c5b81a1c939bd7.jpg)
[leetcode] sum of two numbers - go language solution

Gensim error attributeerror: type object 'word2vec' has no attribute 'load_ word2vec_ format‘

Leetcode hot topic Hot 100, to be updated

Niuke - real exercise-01

Win10 installation and configuration mongodb

Fluent encapsulates an immersive navigation bar with customizable styles NavigationBar

Route add add route
随机推荐
Kubeneters installation problems Collection
LINQ extension methods - any() vs. where() vs. exists() - LINQ extension methods - any() vs. where() vs. exists()
Talk about MySQL's locking rule "hard hitting MySQL series 15"
Subshell
Operator Tour (I)
Is it safe to open an account online? Can a novice open an account
[go] time package
Win10 installation and configuration mongodb
Link storage structure of simulated design disk file
C language to achieve three chess (detailed explanation)
Promotion guide for large enterprises: material preparation, PPT writing and on-site defense
ConnectionOptions. Username attribute definition
Application GDB debugging
Shell uses arrays
Solution of difficult and miscellaneous problems in MVN packaging
T32 add toolbar button
Why do you want to be naked with a router
Small case of throttling function
JS written test question: array
ARP interaction process