Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Problem with crontab unable to run shell script

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)06/01 Report--

There are three conditions for executing a shell script using crontab:

1, must have permission

2, absolute path must be written

3, environmental variables

The format is

* / bin/sh / home/test.sh

The first *: 0: 59 minutes

The second *: 023 hours

Third *: date 1: 31

The fourth *: from January to December

The fifth *: Monday to 7

The first two conditions of crontab are relatively simple, so there is no explanation here. Here is mainly the problem of the third conditional environment variable. The reason why most crontab cannot run the script is this environment variable (to ensure the correctness of the script). This rookie also encountered the same problem today. Baidu Google has been looking for the reason for N long time, and finally confirmed that it is the problem of environment variable. Below, there is a second problem. How to set environment variables, continue Baidu, Google did not find the relevant configuration instructions, entangled with ing. This problem is really difficult for beginners.

The way to add environment variables after constant attempts is:

① executes echo $PATH on your server as follows:

/ usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

② under! / bin/bash of your script, add the following two lines:

PATH=/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

Export PATH

Save exit

Rewrite crontab-e

* / bin/sh / home/test.sh

Success!

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.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report