Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to solve the problem that ubuntu crontab does not execute

Shulou Source: shulou.com Published: 2022-06-01 17:10:34 09月25日 Update

This article mainly explains "how to solve the problem of non-implementation of ubuntu crontab". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to solve the problem of non-implementation of ubuntu crontab".

Add the following sentence to the second line of the script file

The code is as follows:

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

Here are the steps to analyze and solve the problem:

1. The reason for non-execution is caused by environment variables.

two。 Currently, no default environment variable configuration method for configuring cron has been found

Vim / etc/crontab can see that the environment variables in this file are correct

3. * / root/test.sh > ifconfig.txt 2 > & 1 & test.sh is executed every minute

The content of test.sh is as follows. You can see that the output environment variable is / usr/bin:/bin.

The code is as follows:

#! / bin/bash

# PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

Ifconfig

Echo $PATH

Output:

The code is as follows:

/ root/test.sh: line 3: ifconfig: command not found

/ usr/bin:/bin

4. View the location of ifconfig

The code is as follows:

Root@ubuntu:~# whereis ifconfig

Ifconfig: / sbin/ifconfig / usr/share/man/man8/ifconfig.8.gz

5. Comment out the second line of the test.sh script and you can see that the output is as follows

The code is as follows:

Eth0 Link encap:Ethernet HWaddr aa:00:04:00:0a:04

Inet addr:192.168.1.60 Bcast:0.0.0.0 Mask:255.255.255.0

Inet6 addr: fe80::20c:29ff:fef8:73b6/64 Scope:Link

UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

RX packets:2093659 errors:0 dropped:0 overruns:0 frame:0

TX packets:1532815 errors:0 dropped:0 overruns:0 carrier:0

Collisions:0 txqueuelen:1000

RX bytes:519122457 (519.1 MB) TX bytes:447226592 (447.2 MB)

Lo Link encap:Local Loopback

Inet addr:127.0.0.1 Mask:255.0.0.0

Inet6 addr: 1/128 Scope:Host

UP LOOPBACK RUNNING MTU:16436 Metric:1

RX packets:433596 errors:0 dropped:0 overruns:0 frame:0

TX packets:433596 errors:0 dropped:0 overruns:0 carrier:0

Collisions:0 txqueuelen:0

RX bytes:23228192 (23.2MB) TX bytes:23228192 (23.2MB)

/ usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

The 6.test.sh script only temporarily changes the value of PATH. It only takes effect on the current script.

Thank you for your reading, the above is the content of "how to solve the problem of non-implementation of ubuntu crontab". After the study of this article, I believe you have a deeper understanding of how to solve the problem of non-implementation of ubuntu crontab, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Problems code variables environment scripts content learning output files results configuration location reason just that is ideas situations articles methods more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Linux NVidia MariaDB Redmi