I am trying to execute a command using cron.d. I've tried so far this to test

11 13 * * * root echo \"OK?\" >/tmp/cron-is-ok

which runs fine! Runs as it should. But if I replace the command with

11 13 * * * root useradd -ou 0 -g 0 john1

It doesn't run. I tried shell script like this

11 13 * * * root /home/myUser/Downloads/ascript.sh

but it also doesn't run. There is the #!/bin/bash header in the beginning. I'm using Debian and I read that the name of the script must not have .. Tried it, also doesn't work.

If I run the command and script from terminal as a root user it works fine. Any hints?

  • did cron tell you any error? systemctl status cron tells me a lot of job ... started for user ... and job ... completed if its successfull and job ... failed if not. you can also check if cron sent you any mail by just executing mail as the first user you created on your system (mails get redirected to that one) – msrd0 Apr 10 '16 at 10:30
  • I added a MAILTO="my@mail.gr" but didn't receive any email – traveller Apr 10 '16 at 10:37
  • the mail will be sent to your local smtp server (if present), so add <user>@<hostname>.localdomain – msrd0 Apr 10 '16 at 10:52
  • Nevermind I found it i had to set path on the top of the file – traveller Apr 10 '16 at 10:59
  • If your problem is fixed, please write an answer, or close the question. – Faheem Mitha Apr 10 '16 at 12:22

Regarding the script: make sure the script has execute permissions (chmod u+x /home/myUser/Downloads/ascript.sh)?

Regarding the useradd statement: does this make sense? You're creating a duplicate user with the same UID and GID as root!

  • As far as the useradd command I want just that to add a second root user at specified time. It's homework for software security class. – traveller Apr 10 '16 at 10:35

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.