Por que o cron não executa um script de teste do /etc/cron.hourly?

5

Esta é a primeira vez que estou usando o cron através de seu diretório /etc/cron.hourly para executar um script uma vez a cada hora.

Por algum motivo, o script não parece ser executado.

Veja o que eu fiz:

Adicionado um script de teste básico em /etc/cron.hour:

/etc/cron.hourly# ll
-rwxr-xr-x  1 root root  152 Jun 20 23:26 test.bash*

Aqui está o script:

/etc/cron.hourly# cat test.bash
#!/bin/bash

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

echo "This line from test.bash" > /tmp/from.test.script

Aqui está o / etc / crontab:

/etc/cron.hourly# cat /etc/crontab

# m h dom mon dow user  command
17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly

O pacote Cron foi instalado por padrão, então, em seguida, corri /etc/init.d/cron restart e esperei até: 17. Ainda não há vestígios da saída em / tmp.

Alguma ideia do que mais eu poderia experimentar?

/etc/cron.hourly# run-parts --list /etc/cron.hourly

/etc/cron.hourly# run-parts --test /etc/cron.hourly

/etc/cron.hourly# strace run-parts /etc/cron.hourly

execve("/bin/run-parts", ["run-parts", "/etc/cron.hourly"], [/* 16 vars */]) = 0
brk(0)                                  = 0x7f8000
uname({sys="Linux", node="sheevaplug", ...}) = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb6efe000
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY)      = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=17282, ...}) = 0
mmap2(NULL, 17282, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb6ef9000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/arm-linux-gnueabi/libc.so.6", O_RDONLY) = 3
read(3, "7ELF
/etc/cron.hourly# ll
-rwxr-xr-x  1 root root  152 Jun 20 23:26 test.bash*
/etc/cron.hourly# cat test.bash
#!/bin/bash

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

echo "This line from test.bash" > /tmp/from.test.script
/etc/cron.hourly# cat /etc/crontab

# m h dom mon dow user  command
17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly
execve("/bin/run-parts", ["run-parts", "/etc/cron.hourly"], [/* 16 vars */]) = 0
brk(0)                                  = 0x7f8000
uname({sys="Linux", node="sheevaplug", ...}) = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb6efe000
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY)      = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=17282, ...}) = 0
mmap2(NULL, 17282, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb6ef9000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/arm-linux-gnueabi/libc.so.6", O_RDONLY) = 3
read(3, "7ELF%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%(%pre%%pre%%pre%%pre%XX%pre%04%pre%%pre%%pre%"..., 512) = 512
lseek(3, 1231644, SEEK_SET)             = 1231644
read(3, "%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%"..., 1400) = 1400
lseek(3, 1231204, SEEK_SET)             = 1231204
read(3, "A'%pre%%pre%%pre%aeabi%pre%%pre%%pre%%pre%%pre%54T%pre%\t"..., 40) = 40
fstat64(3, {st_mode=S_IFREG|0755, st_size=1233044, ...}) = 0
mmap2(NULL, 1275160, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb6da3000
mprotect(0xb6ecd000, 32768, PROT_NONE)  = 0
mmap2(0xb6ed5000, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x12a) = 0xb6ed5000
mmap2(0xb6ed8000, 9496, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0xb6ed8000
close(3)                                = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb6ef8000
set_tls(0xb6ef86d0, 0xb6ef8da7, 0xb6ef8da8, 0xb6ef86d0, 0xb6f00000) = 0
mprotect(0xb6ed5000, 8192, PROT_READ)   = 0
mprotect(0x12000, 4096, PROT_READ)      = 0
mprotect(0xb6eff000, 4096, PROT_READ)   = 0
munmap(0xb6ef9000, 17282)               = 0
umask(022)                              = 022
brk(0)                                  = 0x7f8000
brk(0x819000)                           = 0x819000
rt_sigaction(SIGCHLD, {0x931c, [], SA_NOCLDSTOP|0x4000000}, NULL, 8) = 0
rt_sigprocmask(SIG_BLOCK, [CHLD], NULL, 8) = 0
open("/etc/cron.hourly", O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC) = 3
fcntl64(3, F_GETFD)                     = 0x1 (flags FD_CLOEXEC)
getdents(3, /* 6 entries */, 32768)     = 128
getdents(3, /* 0 entries */, 32768)     = 0
close(3)                                = 0
exit_group(0)                           = ?
%pre%%pre%%pre%%pre%%pre%%pre%(%pre%%pre%%pre%%pre%XX%pre%04%pre%%pre%%pre%"..., 512) = 512 lseek(3, 1231644, SEEK_SET) = 1231644 read(3, "%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%"..., 1400) = 1400 lseek(3, 1231204, SEEK_SET) = 1231204 read(3, "A'%pre%%pre%%pre%aeabi%pre%%pre%%pre%%pre%%pre%54T%pre%\t"..., 40) = 40 fstat64(3, {st_mode=S_IFREG|0755, st_size=1233044, ...}) = 0 mmap2(NULL, 1275160, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb6da3000 mprotect(0xb6ecd000, 32768, PROT_NONE) = 0 mmap2(0xb6ed5000, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x12a) = 0xb6ed5000 mmap2(0xb6ed8000, 9496, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0xb6ed8000 close(3) = 0 mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb6ef8000 set_tls(0xb6ef86d0, 0xb6ef8da7, 0xb6ef8da8, 0xb6ef86d0, 0xb6f00000) = 0 mprotect(0xb6ed5000, 8192, PROT_READ) = 0 mprotect(0x12000, 4096, PROT_READ) = 0 mprotect(0xb6eff000, 4096, PROT_READ) = 0 munmap(0xb6ef9000, 17282) = 0 umask(022) = 022 brk(0) = 0x7f8000 brk(0x819000) = 0x819000 rt_sigaction(SIGCHLD, {0x931c, [], SA_NOCLDSTOP|0x4000000}, NULL, 8) = 0 rt_sigprocmask(SIG_BLOCK, [CHLD], NULL, 8) = 0 open("/etc/cron.hourly", O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC) = 3 fcntl64(3, F_GETFD) = 0x1 (flags FD_CLOEXEC) getdents(3, /* 6 entries */, 32768) = 128 getdents(3, /* 0 entries */, 32768) = 0 close(3) = 0 exit_group(0) = ?
    
por Gulbahar 21.06.2015 / 01:34

1 resposta

7

Qual distribuição você está usando? De acordo com o manual de peças de execução do Ubuntu :

If neither the --lsbsysinit option nor the --regex option is given then the names must consist entirely of ASCII upper- and lower-case letters, ASCII digits, ASCII underscores, and ASCII minus-hyphens.

Portanto, run-parts não executará um script chamado test.bash . Graças a essa regra, você pode evitar a execução acidental de scripts renomeados, por exemplo, *.old ou *.dpkg-dist *.dpkg-old pelos upgrades do dpkg.

    
por 21.06.2015 / 11:09

Tags