Add the following sentence to the second line of the script file: PATH =/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin: the following are the steps for analyzing and solving the problem: 1. the reason for not executing is the environment variable. 2. currently, the default environment variable configuration method vim/etc/crontab for cron configuration is not found.
Add the following sentence to the second line of the script file:
PATH =/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
The following describes how to solve the problem:
1. The reason for not executing is caused by environment variables.
2. No Default environment variable configuration method is found for cron configuration.
Vim/etc/crontab: The environment variables in this file are correct.
3. *****/root/test. sh> ifconfig.txt 2> & 1 & execute test. sh once every minute
The content of test. sh is as follows. The environment variable of the output result is/usr/bin:/bin.
#! /Bin/bash
# PATH =/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
Ifconfig
Echo $ PATH
Output:
/Root/test. sh: line 3: ifconfig: command not found
/Usr/bin:/bin
4. view the ifconfig location
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. The output result 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 FIG: 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.2 MB) TX bytes: 23228192 (23.2 MB)
/Usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
6. The test. sh script temporarily changes the PATH value, and takes effect only in the current script.