0

This question already has an answer here:

I'm sorry for creating this thread, but i cant solve this issue myself.

I want crontab to execute basic command "xrandr --auto"

I've created an test.sh file that looks like this.

#!/bin/bash
xrandr --auto

After I have added following line to crontab -e, I used default nano editor.

*/2 * * * * /home/dashboarduser/test.sh

Also tried like this

*/2 * * * * root /home/dashboarduser/test.sh

It does not work, I don't know why.

After some searching found this command grep CRON /var/log/syslog to see the contents of cron logfile.

Dec 12 14:06:01 : (dashboarduser) CMD (root /home/dashboarduser/test.sh # JOB_ID_1)
Dec 12 14:06:01 : (CRON) info (No MTA installed, discarding output)

If i run my script in terminal -> /home/dashboarduser/test.sh it works fine.

Thanks in advance.

marked as duplicate by muru command-line Dec 12 '17 at 14:12

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Oh boy.. you forgot to give sh before the location of your script.. Ex: */2 * * * * sh /home/dashboarduser/test.sh – janasaiarun Dec 12 '17 at 12:21
  • 2
    Oh boy... another user who thinks bash scripts should be run using sh. @P75 you don't need the user field (e.g. root) in jobs set up using the crontab -e command (only in those set up via /etc/crontab). Most likely if you capture the errors from your command you will see xrandr is complaining Can't open display. – steeldriver Dec 12 '17 at 12:48
0

First, check that the script is executable.

Second, try running the script yourself from the same account as cron will run it from.

The script will be executed from the user account of the crontab. So if you run crontab -e while logged in to your regular user account, all the jobs in that crontab will be run as you.

Note that if you have mail working (eg a MTA installed) on your machine you'll be emailed when a cron job emits any output (such as error messages).

0

First of all you need to install an MTA to get more input like the error message

No MTA installed, discarding output

indicates. See here on how to to this.

OR

Redirect the output of your script in some file, like it is shown here.

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