AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / computer / 问题 / 1769156
Accepted
David Purdy
David Purdy
Asked: 2023-02-17 20:44:35 +0800 CST2023-02-17 20:44:35 +0800 CST 2023-02-17 20:44:35 +0800 CST

在命令行上运行与通过 crontab 运行时,文件列表 (ls /dev) 不同

  • 772

为什么不能ls使用我的脚本 cron /dev 中的某些文件?

从命令行运行时,该脚本可以完整列出 /dev。从任一 cron 设置运行的相同脚本无法看到 (list, ls) /dev 中的大部分文件。无论哪种方式,脚本都以 root 身份运行,具有几乎相同的 env 值,结果却大不相同。/dev 中大约有 100 个文件无法访问,包括所有磁盘,因此mount无法从 cron 进行操作。(Debian 11.6 最小网络全新安装,没有 SELinux 或 Apparmor,没有容器。)

下面是一个揭示这种令人费解的行为的诊断脚本。脚本本身除了说明和阐明这些行为外没有任何用处,但是 cron 任务查看某些关键文件(例如,挂载文件系统、使用 df 检查空间等)的能力是至关重要的。

#!/bin/bash

#  turn on some tracing, get a timestamp, printenv, whoami
set -xa
echo "timestamp: $(date)"
echo "env values:"
printenv
whoami


cd /
echo "ls -la"
ls -la
cd /dev
echo "cd to /dev, then ls -la"
ls -la
cd disk
echo "cd to /dev/disk, then ls -la"
ls -la

echo " "
echo "just because someone might ask, try to ls /dev/disk directly from /"
cd /
ls -la /dev/disk

命令行输出:

++ date
+ echo 'timestamp: Thu 16 Feb 2023 10:05:33 PM CST'
timestamp: Thu 16 Feb 2023 10:05:33 PM CST
+ echo 'env values:'
env values:
+ printenv
SHELL=/bin/bash
PWD=/usr/local/bin
LOGNAME=root
TEMPDIR=/tmp/user/0
HOME=/root
LANG=en_US.UTF-8
TMPDIR=/tmp/user/0
TERM=xterm-256color
USER=root
TEMP=/tmp/user/0
SHLVL=2
TMP=/tmp/user/0
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
MAIL=/var/mail/root
OLDPWD=/
_=/usr/bin/printenv
+ whoami
root
+ cd /
+ echo 'ls -la'
ls -la
+ ls -la
total 68
drwxr-xr-x  18 root root  4096 Feb 16 21:19 .
drwxr-xr-x  18 root root  4096 Feb 16 21:19 ..
lrwxrwxrwx   1 root root     7 Feb  7 19:48 bin -> usr/bin
drwxr-xr-x   4 root root  4096 Feb 12 20:57 boot
drwxr-xr-x  17 root root  3300 Feb 16 16:53 dev
drwxr-xr-x  99 root root  4096 Feb 16 17:09 etc
drwxr-xr-x   4 root root  4096 Feb  9 18:58 home
lrwxrwxrwx   1 root root    31 Feb  7 19:51 initrd.img -> boot/initrd.img-5.10.0-21-amd64
lrwxrwxrwx   1 root root    31 Feb  7 19:49 initrd.img.old -> boot/initrd.img-5.10.0-20-amd64
lrwxrwxrwx   1 root root     7 Feb  7 19:48 lib -> usr/lib
lrwxrwxrwx   1 root root     9 Feb  7 19:48 lib32 -> usr/lib32
lrwxrwxrwx   1 root root     9 Feb  7 19:48 lib64 -> usr/lib64
lrwxrwxrwx   1 root root    10 Feb  7 19:48 libx32 -> usr/libx32
drwx------   2 root root 16384 Feb  7 19:48 lost+found
drwxr-xr-x   3 root root  4096 Feb  7 19:49 media
drwxr-xr-x   7 root root  4096 Feb 16 20:42 mnt
drwxr-xr-x   2 root root  4096 Feb  7 19:48 opt
dr-xr-xr-x 182 root root     0 Feb 16 16:53 proc
drwx------   5 root root  4096 Feb 16 21:05 root
drwxr-xr-x  24 root root   780 Feb 16 16:58 run
lrwxrwxrwx   1 root root     8 Feb  7 19:48 sbin -> usr/sbin
drwxr-xr-x   2 root root  4096 Feb  7 19:48 srv
dr-xr-xr-x  13 root root     0 Feb 16 16:53 sys
drwxrwxrwt  11 root root  4096 Feb 16 22:04 tmp
drwxr-xr-x  14 root root  4096 Feb  7 19:48 usr
drwxr-xr-x  12 root root  4096 Feb  7 20:14 var
lrwxrwxrwx   1 root root    28 Feb  7 19:51 vmlinuz -> boot/vmlinuz-5.10.0-21-amd64
lrwxrwxrwx   1 root root    28 Feb  7 19:49 vmlinuz.old -> boot/vmlinuz-5.10.0-20-amd64
+ cd /dev
+ echo 'cd to /dev, then ls -la'
cd to /dev, then ls -la
+ ls -la
total 4
drwxr-xr-x 17 root root        3.3K Feb 16 16:53 .
drwxr-xr-x 18 root root        4.0K Feb 16 21:19 ..
crw-r--r--  1 root root     10, 235 Feb 16 16:53 autofs
drwxr-xr-x  2 root root         200 Feb 16 16:53 block
drwxr-xr-x  2 root root          80 Feb 16 16:53 bsg
crw-------  1 root root     10, 234 Feb 16 16:53 btrfs-control
drwxr-xr-x  3 root root          60 Feb 16 16:53 bus
drwxr-xr-x  2 root root        3.1K Feb 16 16:53 char
crw--w----  1 root tty       5,   1 Feb 16 16:53 console
lrwxrwxrwx  1 root root          11 Feb 16 16:53 core -> /proc/kcore
crw-------  1 root root     10,  62 Feb 16 16:53 cpu_dma_latency
crw-------  1 root root     10, 203 Feb 16 16:53 cuse
drwxr-xr-x  7 root root         140 Feb 16 16:53 disk
drwxr-xr-x  3 root root         100 Feb 16 16:53 dri
crw-------  1 root root    246,   0 Feb 16 16:53 drm_dp_aux0
lrwxrwxrwx  1 root root          13 Feb 16 16:53 fd -> /proc/self/fd
crw-rw-rw-  1 root root      1,   7 Feb 16 16:53 full
crw-rw-rw-  1 root root     10, 229 Feb 16 16:53 fuse
crw-------  1 root root     10, 228 Feb 16 16:53 hpet
drwxr-xr-x  2 root root           0 Feb 16 16:53 hugepages
crw-------  1 root root     10, 183 Feb 16 16:53 hwrng
lrwxrwxrwx  1 root root          12 Feb 16 16:53 initctl -> /run/initctl
drwxr-xr-x  3 root root         280 Feb 16 16:53 input
crw-r--r--  1 root root      1,  11 Feb 16 16:53 kmsg
crw-rw----  1 root kvm      10, 232 Feb 16 16:53 kvm
lrwxrwxrwx  1 root root          28 Feb 16 16:53 log -> /run/systemd/journal/dev-log
crw-rw----  1 root disk     10, 237 Feb 16 16:53 loop-control
drwxr-xr-x  2 root root          60 Feb 16 16:53 mapper
crw-------  1 root root    249,   0 Feb 16 16:53 mei0
crw-r-----  1 root kmem      1,   1 Feb 16 16:53 mem
drwxrwxrwt  2 root root          40 Feb 16 16:53 mqueue
drwxr-xr-x  2 root root          60 Feb 16 16:53 net
crw-rw-rw-  1 root root      1,   3 Feb 16 16:53 null
crw-------  1 root root     10, 144 Feb 16 16:53 nvram
crw-r-----  1 root kmem      1,   4 Feb 16 16:53 port
crw-------  1 root root    108,   0 Feb 16 16:53 ppp
crw-------  1 root root     10,   1 Feb 16 16:53 psaux
crw-rw-rw-  1 root tty       5,   2 Feb 16  2023 ptmx
drwxr-xr-x  2 root root           0 Feb 16 16:53 pts
crw-rw-rw-  1 root root      1,   8 Feb 16 16:53 random
crw-rw-r--  1 root netdev   10, 242 Feb 16 16:53 rfkill
lrwxrwxrwx  1 root root           4 Feb 16 16:53 rtc -> rtc0
crw-------  1 root root    252,   0 Feb 16 16:53 rtc0
brw-rw----  1 root disk      8,   0 Feb 16 16:53 sda
brw-rw----  1 root disk      8,   1 Feb 16 16:53 sda1
brw-rw----  1 root disk      8,   2 Feb 16 16:53 sda2
brw-rw----  1 root disk      8,   3 Feb 16 16:53 sda3
brw-rw----  1 root disk      8,  16 Feb 16 16:53 sdb
brw-rw----  1 root disk      8,  17 Feb 16 16:53 sdb1
brw-rw----  1 root disk      8,  18 Feb 16 16:53 sdb2
brw-rw----  1 root disk      8,  19 Feb 16 16:53 sdb3
crw-rw----  1 root disk     21,   0 Feb 16 16:53 sg0
crw-rw----  1 root disk     21,   1 Feb 16 16:53 sg1
drwxrwxrwt  2 root root          40 Feb 16 16:53 shm
crw-------  1 root root     10, 231 Feb 16 16:53 snapshot
drwxr-xr-x  3 root root         320 Feb 16 16:53 snd
lrwxrwxrwx  1 root root          15 Feb 16 16:53 stderr -> /proc/self/fd/2
lrwxrwxrwx  1 root root          15 Feb 16 16:53 stdin -> /proc/self/fd/0
lrwxrwxrwx  1 root root          15 Feb 16 16:53 stdout -> /proc/self/fd/1
crw-------  1 root root     10, 224 Feb 16 16:53 tpm0
crw-rw-rw-  1 root tty       5,   0 Feb 16 21:13 tty
crw--w----  1 root tty       4,   0 Feb 16 16:53 tty0
crw--w----  1 root tty       4,   1 Feb 16 16:53 tty1
crw--w----  1 root tty       4,  10 Feb 16 16:53 tty10
crw--w----  1 root tty       4,  11 Feb 16 16:53 tty11
crw--w----  1 root tty       4,  12 Feb 16 16:53 tty12
crw--w----  1 root tty       4,  13 Feb 16 16:53 tty13
crw--w----  1 root tty       4,  14 Feb 16 16:53 tty14
crw--w----  1 root tty       4,  15 Feb 16 16:53 tty15
crw--w----  1 root tty       4,  16 Feb 16 16:53 tty16
crw--w----  1 root tty       4,  17 Feb 16 16:53 tty17
crw--w----  1 root tty       4,  18 Feb 16 16:53 tty18
crw--w----  1 root tty       4,  19 Feb 16 16:53 tty19
crw--w----  1 root tty       4,   2 Feb 16 16:53 tty2
crw--w----  1 root tty       4,  20 Feb 16 16:53 tty20
crw--w----  1 root tty       4,  21 Feb 16 16:53 tty21
crw--w----  1 root tty       4,  22 Feb 16 16:53 tty22
crw--w----  1 root tty       4,  23 Feb 16 16:53 tty23
crw--w----  1 root tty       4,  24 Feb 16 16:53 tty24
crw--w----  1 root tty       4,  25 Feb 16 16:53 tty25
crw--w----  1 root tty       4,  26 Feb 16 16:53 tty26
crw--w----  1 root tty       4,  27 Feb 16 16:53 tty27
crw--w----  1 root tty       4,  28 Feb 16 16:53 tty28
crw--w----  1 root tty       4,  29 Feb 16 16:53 tty29
crw--w----  1 root tty       4,   3 Feb 16 16:53 tty3
crw--w----  1 root tty       4,  30 Feb 16 16:53 tty30
crw--w----  1 root tty       4,  31 Feb 16 16:53 tty31
crw--w----  1 root tty       4,  32 Feb 16 16:53 tty32
crw--w----  1 root tty       4,  33 Feb 16 16:53 tty33
crw--w----  1 root tty       4,  34 Feb 16 16:53 tty34
crw--w----  1 root tty       4,  35 Feb 16 16:53 tty35
crw--w----  1 root tty       4,  36 Feb 16 16:53 tty36
crw--w----  1 root tty       4,  37 Feb 16 16:53 tty37
crw--w----  1 root tty       4,  38 Feb 16 16:53 tty38
crw--w----  1 root tty       4,  39 Feb 16 16:53 tty39
crw--w----  1 root tty       4,   4 Feb 16 16:53 tty4
crw--w----  1 root tty       4,  40 Feb 16 16:53 tty40
crw--w----  1 root tty       4,  41 Feb 16 16:53 tty41
crw--w----  1 root tty       4,  42 Feb 16 16:53 tty42
crw--w----  1 root tty       4,  43 Feb 16 16:53 tty43
crw--w----  1 root tty       4,  44 Feb 16 16:53 tty44
crw--w----  1 root tty       4,  45 Feb 16 16:53 tty45
crw--w----  1 root tty       4,  46 Feb 16 16:53 tty46
crw--w----  1 root tty       4,  47 Feb 16 16:53 tty47
crw--w----  1 root tty       4,  48 Feb 16 16:53 tty48
crw--w----  1 root tty       4,  49 Feb 16 16:53 tty49
crw--w----  1 root tty       4,   5 Feb 16 16:53 tty5
crw--w----  1 root tty       4,  50 Feb 16 16:53 tty50
crw--w----  1 root tty       4,  51 Feb 16 16:53 tty51
crw--w----  1 root tty       4,  52 Feb 16 16:53 tty52
crw--w----  1 root tty       4,  53 Feb 16 16:53 tty53
crw--w----  1 root tty       4,  54 Feb 16 16:53 tty54
crw--w----  1 root tty       4,  55 Feb 16 16:53 tty55
crw--w----  1 root tty       4,  56 Feb 16 16:53 tty56
crw--w----  1 root tty       4,  57 Feb 16 16:53 tty57
crw--w----  1 root tty       4,  58 Feb 16 16:53 tty58
crw--w----  1 root tty       4,  59 Feb 16 16:53 tty59
crw--w----  1 root tty       4,   6 Feb 16 16:53 tty6
crw--w----  1 root tty       4,  60 Feb 16 16:53 tty60
crw--w----  1 root tty       4,  61 Feb 16 16:53 tty61
crw--w----  1 root tty       4,  62 Feb 16 16:53 tty62
crw--w----  1 root tty       4,  63 Feb 16 16:53 tty63
crw--w----  1 root tty       4,   7 Feb 16 16:53 tty7
crw--w----  1 root tty       4,   8 Feb 16 16:53 tty8
crw--w----  1 root tty       4,   9 Feb 16 16:53 tty9
crw-rw----  1 root dialout   4,  64 Feb 16 16:53 ttyS0
crw-rw----  1 root dialout   4,  65 Feb 16 16:53 ttyS1
crw-rw----  1 root dialout   4,  66 Feb 16 16:53 ttyS2
crw-rw----  1 root dialout   4,  67 Feb 16 16:53 ttyS3
crw-------  1 root root     10, 239 Feb 16 16:53 uhid
crw-------  1 root root     10, 223 Feb 16 16:53 uinput
crw-rw-rw-  1 root root      1,   9 Feb 16 16:53 urandom
crw-rw----  1 root tty       7,   0 Feb 16 16:53 vcs
crw-rw----  1 root tty       7,   1 Feb 16 16:53 vcs1
crw-rw----  1 root tty       7,  10 Feb 16 16:53 vcs10
crw-rw----  1 root tty       7,   2 Feb 16 16:53 vcs2
crw-rw----  1 root tty       7,   3 Feb 16 16:53 vcs3
crw-rw----  1 root tty       7,   4 Feb 16 16:53 vcs4
crw-rw----  1 root tty       7,   5 Feb 16 16:53 vcs5
crw-rw----  1 root tty       7,   6 Feb 16 16:53 vcs6
crw-rw----  1 root tty       7, 128 Feb 16 16:53 vcsa
crw-rw----  1 root tty       7, 129 Feb 16 16:53 vcsa1
crw-rw----  1 root tty       7, 138 Feb 16 16:53 vcsa10
crw-rw----  1 root tty       7, 130 Feb 16 16:53 vcsa2
crw-rw----  1 root tty       7, 131 Feb 16 16:53 vcsa3
crw-rw----  1 root tty       7, 132 Feb 16 16:53 vcsa4
crw-rw----  1 root tty       7, 133 Feb 16 16:53 vcsa5
crw-rw----  1 root tty       7, 134 Feb 16 16:53 vcsa6
crw-rw----  1 root tty       7,  64 Feb 16 16:53 vcsu
crw-rw----  1 root tty       7,  65 Feb 16 16:53 vcsu1
crw-rw----  1 root tty       7,  74 Feb 16 16:53 vcsu10
crw-rw----  1 root tty       7,  66 Feb 16 16:53 vcsu2
crw-rw----  1 root tty       7,  67 Feb 16 16:53 vcsu3
crw-rw----  1 root tty       7,  68 Feb 16 16:53 vcsu4
crw-rw----  1 root tty       7,  69 Feb 16 16:53 vcsu5
crw-rw----  1 root tty       7,  70 Feb 16 16:53 vcsu6
drwxr-xr-x  2 root root          60 Feb 16 16:53 vfio
crw-------  1 root root     10,  63 Feb 16 16:53 vga_arbiter
crw-------  1 root root     10, 137 Feb 16 16:53 vhci
crw-------  1 root root     10, 238 Feb 16 16:53 vhost-net
crw-------  1 root root     10, 241 Feb 16 16:53 vhost-vsock
crw-------  1 root root     10, 130 Feb 16 16:53 watchdog
crw-------  1 root root    247,   0 Feb 16 16:53 watchdog0
prw-r-----  1 root adm            0 Feb 16 16:53 xconsole
crw-rw-rw-  1 root root      1,   5 Feb 16 16:53 zero
+ cd disk
+ echo 'cd to /dev/disk, then ls -la'
cd to /dev/disk, then ls -la
+ ls -la
total 0
drwxr-xr-x  7 root root  140 Feb 16 16:53 .
drwxr-xr-x 17 root root 3300 Feb 16 16:53 ..
drwxr-xr-x  2 root root  280 Feb 16 16:53 by-id
drwxr-xr-x  2 root root  100 Feb 16 16:53 by-partlabel
drwxr-xr-x  2 root root  100 Feb 16 16:53 by-partuuid
drwxr-xr-x  2 root root  280 Feb 16 16:53 by-path
drwxr-xr-x  2 root root  140 Feb 16 16:53 by-uuid
+ echo ' '
 
+ echo 'just because someone might ask, try to ls /dev/disk directly from /'
just because someone might ask, try to ls /dev/disk directly from /
+ cd /
+ ls -la /dev/disk
total 0
drwxr-xr-x  7 root root  140 Feb 16 16:53 .
drwxr-xr-x 17 root root 3300 Feb 16 16:53 ..
drwxr-xr-x  2 root root  280 Feb 16 16:53 by-id
drwxr-xr-x  2 root root  100 Feb 16 16:53 by-partlabel
drwxr-xr-x  2 root root  100 Feb 16 16:53 by-partuuid
drwxr-xr-x  2 root root  280 Feb 16 16:53 by-path
drwxr-xr-x  2 root root  140 Feb 16 16:53 by-uuid

crontab 条目:(尝试不带 env 变量,然后逐渐添加它们)

SHELL=/bin/bash
BASH_ENV="/root/.bashrc"
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
USER=root
* * * * * /usr/local/bin/problem > /var/log/backup/problem.log 2>&1

crontab 的输出:(注意与大多数命令行输出的相似性,除了 /dev 内容)

++ date
+ echo 'timestamp: Fri 17 Feb 2023 08:48:01 AM CST'
timestamp: Fri 17 Feb 2023 08:48:01 AM CST
+ echo 'env values:'
env values:
+ printenv
SHELL=/bin/bash
PWD=/root
LOGNAME=root
TEMPDIR=/tmp/user/0
HOME=/root
LANG=en_US.UTF-8
TMPDIR=/tmp/user/0
USER=root
TEMP=/tmp/user/0
SHLVL=2
BASH_ENV=/root/.bashrc
TMP=/tmp/user/0
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
_=/usr/bin/printenv
+ whoami
root
+ cd /
+ echo 'ls -la'
ls -la
+ ls -la
total 60
drwxr-xr-x  18 root root  4096 Feb 17 00:17 .
drwxr-xr-x  18 root root  4096 Feb 17 00:17 ..
lrwxrwxrwx   1 root root     7 Feb  7 19:48 bin -> usr/bin
drwxr-xr-x   4 root root  4096 Feb 12 20:57 boot
drwxr-xr-x   7 root root   400 Feb 16 16:53 dev
drwxr-xr-x  99 root root  4096 Feb 16 17:09 etc
d---------   2 root root    40 Feb 16 16:53 home
lrwxrwxrwx   1 root root    31 Feb  7 19:51 initrd.img -> boot/initrd.img-5.10.0-21-amd64
lrwxrwxrwx   1 root root    31 Feb  7 19:49 initrd.img.old -> boot/initrd.img-5.10.0-20-amd64
lrwxrwxrwx   1 root root     7 Feb  7 19:48 lib -> usr/lib
lrwxrwxrwx   1 root root     9 Feb  7 19:48 lib32 -> usr/lib32
lrwxrwxrwx   1 root root     9 Feb  7 19:48 lib64 -> usr/lib64
lrwxrwxrwx   1 root root    10 Feb  7 19:48 libx32 -> usr/libx32
drwx------   2 root root 16384 Feb  7 19:48 lost+found
drwxr-xr-x   3 root root  4096 Feb  7 19:49 media
drwxr-xr-x   7 root root  4096 Feb 16 20:42 mnt
drwxr-xr-x   2 root root  4096 Feb  7 19:48 opt
dr-xr-xr-x 192 root root     0 Feb 16 16:53 proc
d---------   2 root root    40 Feb 16 16:53 root
drwxr-xr-x  25 root root   800 Feb 17 00:18 run
lrwxrwxrwx   1 root root     8 Feb  7 19:48 sbin -> usr/sbin
drwxr-xr-x   2 root root  4096 Feb  7 19:48 srv
dr-xr-xr-x  13 root root     0 Feb 16 16:53 sys
drwxrwxrwt  11 root root  4096 Feb 17 08:47 tmp
drwxr-xr-x  14 root root  4096 Feb  7 19:48 usr
drwxr-xr-x  12 root root  4096 Feb  7 20:14 var
lrwxrwxrwx   1 root root    28 Feb  7 19:51 vmlinuz -> boot/vmlinuz-5.10.0-21-amd64
lrwxrwxrwx   1 root root    28 Feb  7 19:49 vmlinuz.old -> boot/vmlinuz-5.10.0-20-amd64
+ cd /dev
+ echo 'cd to /dev, then ls -la'
cd to /dev, then ls -la
+ ls -la
total 4
drwxr-xr-x  7 root root  400 Feb 16 16:53 .
drwxr-xr-x 18 root root 4096 Feb 17 00:17 ..
drwxr-xr-x  2 root root  180 Feb 16 16:53 char
lrwxrwxrwx  1 root root   11 Feb 16 16:53 core -> /proc/kcore
lrwxrwxrwx  1 root root   13 Feb 16 16:53 fd -> /proc/self/fd
crw-rw-rw-  1 root root 1, 7 Feb 16 16:53 full
drwxr-xr-x  2 root root    0 Feb 16 16:53 hugepages
lrwxrwxrwx  1 root root   28 Feb 16 16:53 log -> /run/systemd/journal/dev-log
drwxrwxrwt  2 root root   40 Feb 16 16:53 mqueue
crw-rw-rw-  1 root root 1, 3 Feb 16 16:53 null
crw-rw-rw-  1 root root 5, 2 Feb 16 16:53 ptmx
drwxr-xr-x  2 root root    0 Feb 16 16:53 pts
crw-rw-rw-  1 root root 1, 8 Feb 16 16:53 random
drwxrwxrwt  2 root root   40 Feb 17 00:17 shm
lrwxrwxrwx  1 root root   15 Feb 16 16:53 stderr -> /proc/self/fd/2
lrwxrwxrwx  1 root root   15 Feb 16 16:53 stdin -> /proc/self/fd/0
lrwxrwxrwx  1 root root   15 Feb 16 16:53 stdout -> /proc/self/fd/1
crw-rw-rw-  1 root root 5, 0 Feb 16 16:53 tty
crw-rw-rw-  1 root root 1, 9 Feb 16 16:53 urandom
crw-rw-rw-  1 root root 1, 5 Feb 16 16:53 zero
+ cd disk
/usr/local/bin/problem: line 17: cd: disk: No such file or directory
+ echo 'cd to /dev/disk, then ls -la'
cd to /dev/disk, then ls -la
+ ls -la
total 4
drwxr-xr-x  7 root root  400 Feb 16 16:53 .
drwxr-xr-x 18 root root 4096 Feb 17 00:17 ..
drwxr-xr-x  2 root root  180 Feb 16 16:53 char
lrwxrwxrwx  1 root root   11 Feb 16 16:53 core -> /proc/kcore
lrwxrwxrwx  1 root root   13 Feb 16 16:53 fd -> /proc/self/fd
crw-rw-rw-  1 root root 1, 7 Feb 16 16:53 full
drwxr-xr-x  2 root root    0 Feb 16 16:53 hugepages
lrwxrwxrwx  1 root root   28 Feb 16 16:53 log -> /run/systemd/journal/dev-log
drwxrwxrwt  2 root root   40 Feb 16 16:53 mqueue
crw-rw-rw-  1 root root 1, 3 Feb 16 16:53 null
crw-rw-rw-  1 root root 5, 2 Feb 16 16:53 ptmx
drwxr-xr-x  2 root root    0 Feb 16 16:53 pts
crw-rw-rw-  1 root root 1, 8 Feb 16 16:53 random
drwxrwxrwt  2 root root   40 Feb 17 00:17 shm
lrwxrwxrwx  1 root root   15 Feb 16 16:53 stderr -> /proc/self/fd/2
lrwxrwxrwx  1 root root   15 Feb 16 16:53 stdin -> /proc/self/fd/0
lrwxrwxrwx  1 root root   15 Feb 16 16:53 stdout -> /proc/self/fd/1
crw-rw-rw-  1 root root 5, 0 Feb 16 16:53 tty
crw-rw-rw-  1 root root 1, 9 Feb 16 16:53 urandom
crw-rw-rw-  1 root root 1, 5 Feb 16 16:53 zero
+ echo ' '
 
+ echo 'just because someone might ask, try to ls /dev/disk directly from /'
just because someone might ask, try to ls /dev/disk directly from /
+ cd /
+ ls -la /dev/disk
ls: cannot access '/dev/disk': No such file or directory
linux
  • 1 1 个回答
  • 42 Views

1 个回答

  • Voted
  1. Best Answer
    user1686
    2023-02-18T07:16:27+08:002023-02-18T07:16:27+08:00

    听起来有人有一个好主意来启用PrivateDevices=crond 服务。

    用于findmnt从 cron 作业的外部和内部验证实际安装在 /dev 上的内容。(不能保证两者相同!)

    Use systemctl cat on your cron service (however it's named in Debian) to take a look at the options it has configured. On a standard Debian system, this should only output a single file from /lib, without the PrivateDevices= option being mentioned.

    If the output shows files in /etc, those were a local override and can be removed. It might be that someone edited cron.service directly in /lib, though, in which case undo the changes manually or reinstall the cron package using apt --reinstall to (hopefully) revert the local modifications.

    If you see other 'Private' or 'Protect' options, you may have to remove them too, as quite a few of them cause the process to be put in a private mount namespace, making all mounts done by the process invisible to the outside world. (Though, your cronjob shouldn't be setting up any mounts that are meant to be visible to the outside world – use /etc/fstab for that – but that's a different topic.)

    • 1

相关问题

  • 如何让我的 Linux 机器看起来像是在运行 Windows?

  • 对于 cp 或 mv,是否有等同于 cd - 的东西?

  • 以 root 身份运行 docker 容器

  • 如何在域和 Linux 活动目录中启用指纹传感器

  • 如何在CentOS 7 中将Ctrl+C 永久更改为Ctrl+K?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何减少“vmmem”进程的消耗?

    • 11 个回答
  • Marko Smith

    从 Microsoft Stream 下载视频

    • 4 个回答
  • Marko Smith

    Google Chrome DevTools 无法解析 SourceMap:chrome-extension

    • 6 个回答
  • Marko Smith

    Windows 照片查看器因为内存不足而无法运行?

    • 5 个回答
  • Marko Smith

    支持结束后如何激活 WindowsXP?

    • 6 个回答
  • Marko Smith

    远程桌面间歇性冻结

    • 7 个回答
  • Marko Smith

    子网掩码 /32 是什么意思?

    • 6 个回答
  • Marko Smith

    鼠标指针在 Windows 中按下的箭头键上移动?

    • 1 个回答
  • Marko Smith

    VirtualBox 无法以 VERR_NEM_VM_CREATE_FAILED 启动

    • 8 个回答
  • Marko Smith

    应用程序不会出现在 MacBook 的摄像头和麦克风隐私设置中

    • 5 个回答
  • Martin Hope
    Vickel Firefox 不再允许粘贴到 WhatsApp 网页中? 2023-08-18 05:04:35 +0800 CST
  • Martin Hope
    Saaru Lindestøkke 为什么使用 Python 的 tar 库时 tar.xz 文件比 macOS tar 小 15 倍? 2021-03-14 09:37:48 +0800 CST
  • Martin Hope
    CiaranWelsh 如何减少“vmmem”进程的消耗? 2020-06-10 02:06:58 +0800 CST
  • Martin Hope
    Jim Windows 10 搜索未加载,显示空白窗口 2020-02-06 03:28:26 +0800 CST
  • Martin Hope
    andre_ss6 远程桌面间歇性冻结 2019-09-11 12:56:40 +0800 CST
  • Martin Hope
    Riley Carney 为什么在 URL 后面加一个点会删除登录信息? 2019-08-06 10:59:24 +0800 CST
  • Martin Hope
    zdimension 鼠标指针在 Windows 中按下的箭头键上移动? 2019-08-04 06:39:57 +0800 CST
  • Martin Hope
    jonsca 我所有的 Firefox 附加组件突然被禁用了,我该如何重新启用它们? 2019-05-04 17:58:52 +0800 CST
  • Martin Hope
    MCK 是否可以使用文本创建二维码? 2019-04-02 06:32:14 +0800 CST
  • Martin Hope
    SoniEx2 更改 git init 默认分支名称 2019-04-01 06:16:56 +0800 CST

热门标签

windows-10 linux windows microsoft-excel networking ubuntu worksheet-function bash command-line hard-drive

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve