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

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.

| improve this answer | |
  • file created, but empty. – Valentyn Hruzytskyi Aug 19 '18 at 16:41
  • Then your script / command is successful. If you run the script from terminal, is the directory created? – kukulo Aug 19 '18 at 16:45
  • I already have create directory. Thank you. But some issue with #echo command. – Valentyn Hruzytskyi Aug 19 '18 at 16:48
  • If you want to mail the output of the command use this line: – kukulo Aug 19 '18 at 16:52
  • echo "mail content" | mail -s "mail subject" your@email.com – kukulo Aug 19 '18 at 16:52

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.