1

I create a simply script in /root/test.sh file:

#!/bin/bash
echo "hello"
mkdir newdir

next:

chmod +x /root/test.sh

We can convinced, what test.sh is owned by root:

root@ubuntu-s-1vcpu-1gb-ams3-01:~# find /root -user root /root
/root/test.sh

So, my crontab:

root@ubuntu-s-1vcpu-1gb-ams3-01:~# crontab -l
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin

* * * * * /root/test.sh

(Also i did try with run-parts:

* * * * * root run-parts /root/test.sh

)

No one method not run my script, not out "hello" and not create a newdir directory.

service cron status:

root@ubuntu-s-1vcpu-1gb-ams3-01:~# service cron status
● cron.service - Regular background program processing daemon
   Loaded: loaded (/lib/systemd/system/cron.service; enabled; vendor preset: enabled)
   Active: active (running) since Sat 2018-08-18 15:46:42 UTC; 23h ago
     Docs: man:cron(8)
 Main PID: 1340 (cron)
    Tasks: 1
   Memory: 26.8M
      CPU: 7.982s
   CGroup: /system.slice/cron.service
           └─1340 /usr/sbin/cron -f

Aug 19 15:16:01 ubuntu-s-1vcpu-1gb-ams3-01 CRON[439]: (root) CMD (root run-parts /root/test.sh)
Aug 19 15:16:01 ubuntu-s-1vcpu-1gb-ams3-01 CRON[438]: (CRON) info (No MTA installed, discarding output)
Aug 19 15:16:01 ubuntu-s-1vcpu-1gb-ams3-01 CRON[438]: pam_unix(cron:session): session closed for user root
Aug 19 15:17:01 ubuntu-s-1vcpu-1gb-ams3-01 CRON[1032]: pam_unix(cron:session): session opened for user root by (uid=0)
Aug 19 15:17:01 ubuntu-s-1vcpu-1gb-ams3-01 CRON[1031]: pam_unix(cron:session): session opened for user root by (uid=0)
Aug 19 15:17:01 ubuntu-s-1vcpu-1gb-ams3-01 CRON[1033]: (root) CMD (root run-parts /root/test.sh)
Aug 19 15:17:01 ubuntu-s-1vcpu-1gb-ams3-01 CRON[1032]: (CRON) info (No MTA installed, discarding output)
Aug 19 15:17:01 ubuntu-s-1vcpu-1gb-ams3-01 CRON[1032]: pam_unix(cron:session): session closed for user root
Aug 19 15:17:01 ubuntu-s-1vcpu-1gb-ams3-01 CRON[1034]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Aug 19 15:17:01 ubuntu-s-1vcpu-1gb-ams3-01 CRON[1031]: pam_unix(cron:session): session closed for user root

every minutes cron tries do something, but, how I see - I haved message

session closed for user root

and nothing not happens.

What more I must to do?

========================================================================

after deleting the string MAILTO=name@ukr.net script correctly creats newdir directory. But yet not printed string 'hello'. So it works, but some issue in #echo "hello" string.

  • 1
    Your script won't output anything, because although you've specified a MAILTO, you don't appear to have a mail transfer agent (MTA) running. Try redirecting its output to a log file. – steeldriver Aug 19 '18 at 16:35

1 Answers1

1

Run crontab -e and put following line in it:

*/1 * * * * /root/test.sh 1> /dev/null 2> /root/test.err

This is running every minute. The test.err file will give you output error in case the command does not succeed.

kukulo
  • 2,015