5

This is the first time I'm using cron through its /etc/cron.hourly directory to run a script once every hour.

For some reason, the script doesn't seem to run.

Here's what I did:

Added a basic test script in /etc/cron.hour:

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

Here's the 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

Here's /etc/crontab:

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

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

The Cron package was installed by default, so next, I ran /etc/init.d/cron restart, and waited until :17. Still no trace of the output in /tmp.

Any idea what else I could try?


/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, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0XX\1\0004\0\0\0"..., 512) = 512
lseek(3, 1231644, SEEK_SET)             = 1231644
read(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 1400) = 1400
lseek(3, 1231204, SEEK_SET)             = 1231204
read(3, "A'\0\0\0aeabi\0\1\35\0\0\0\0054T\0\6\2\10\1\t\1\22\4\24\1\25\1"..., 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)                           = ?
  • 1
    Run run-parts --list /etc/cron.hourly and run-parts --test /etc/cron.hourly. If it doesn't say "run-parts: executing" run strace run-parts /etc/cron.hourly. Edit your question and add the details. – Braiam Jun 20 '15 at 23:54
7

Which distribution are you using? According to Ubuntu's run-parts manual:

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.

Therefore run-parts won't run a script named test.bash. Thanks to this rule, you can avoid to accidentally run renamed scripts, for example *.old, or *.dpkg-dist *.dpkg-old by dpkg upgrades.

  • My hero! Problem solved. – Gulbahar Jun 21 '15 at 11:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.