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

How to solve the problem that ubuntu crontab does not execute

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

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!

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

Servers

Wechat

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

12
Report