1

snailmail.sh

#!/bin/bash
echo "Test" >> /tmp/out
/usr/bin/kdialog --title "MAIL RECIEVED" --msgbox "mail recieved!!"

crontab -e

#CronJobs located in $HOME/cronjobs/*

* * * * * /home/shadyabhi/cronjobs/snailmail.sh

Its not root's crontab. The above script is a part of a bigger script. I cannot run the following script as cron job. Whereas when run as a cronjob, only "Test" gets appended to the /tmp/out file & the kdialog is not shown.

/var/log/crond.log

Oct 14 13:47:01 ArchLinux crond[1552]: FILE /var/spool/cron/shadyabhi USER shadyabhi PID 28844 /home/shadyabhi/cronjobs/snailmail.sh
Oct 14 13:47:01 ArchLinux crond[1552]: exit status 1 from user shadyabhi /home/shadyabhi/cronjobs/snailmail.sh
Oct 14 13:47:01 ArchLinux crond[28846]: mailing cron output for user shadyabhi /home/shadyabhi/cronjobs/snailmail.sh
Oct 14 13:47:01 ArchLinux crond[28846]: unable to exec /usr/sbin/sendmail: cron output for user shadyabhi /home/shadyabhi/cronjobs/snailmail.sh to /dev/null
Oct 14 13:48:01 ArchLinux crond[1552]: FILE /var/spool/cron/shadyabhi USER shadyabhi PID 28853 /home/shadyabhi/cronjobs/snailmail.sh
Oct 14 13:48:01 ArchLinux crond[1552]: exit status 1 from user shadyabhi /home/shadyabhi/cronjobs/snailmail.sh
Oct 14 13:48:01 ArchLinux crond[28855]: mailing cron output for user shadyabhi /home/shadyabhi/cronjobs/snailmail.sh
Oct 14 13:48:01 ArchLinux crond[28855]: unable to exec /usr/sbin/sendmail: cron output for user shadyabhi /home/shadyabhi/cronjobs/snailmail.sh to /dev/null
Oct 14 13:49:01 ArchLinux crond[1552]: FILE /var/spool/cron/shadyabhi USER shadyabhi PID 28858 /home/shadyabhi/cronjobs/snailmail.sh
Oct 14 13:49:01 ArchLinux crond[1552]: exit status 1 from user shadyabhi /home/shadyabhi/cronjobs/snailmail.sh
Oct 14 13:49:01 ArchLinux crond[28860]: mailing cron output for user shadyabhi /home/shadyabhi/cronjobs/snailmail.sh
Oct 14 13:49:01 ArchLinux crond[28860]: unable to exec /usr/sbin/sendmail: cron output for user shadyabhi /home/shadyabhi/cronjobs/snailmail.sh to /dev/null

Please help me solving this issue.

3
  • Ohk. I figured out. Its showing error .... kdialog: cannot connect to X server. Oct 14, 2010 at 8:40
  • How do I solve that? Oct 14, 2010 at 8:40
  • Perhaps it would help if you describe what the 'bigger script' is intended to do.
    – JRT
    Oct 14, 2010 at 9:21

2 Answers 2

3

The cron job doesn't run in the same X session that you are logged in to, so it doesn't know which X server to talk to. When you log in, the X server's address is stored in your $DISPLAY environment variable. Any process started from within X will use that variable to determine which server to use.

You need to find a way to pass the appropriate server's address to your cron job. It might be as simple as:

DISPLAY=:0 /usr/bin/kdialog --title "MAIL RECIEVED" --msgbox "mail recieved!!" &
1
  • 1
    Specifically, it doesn't run in any X session unless you tell it to via DISPLAY
    – Daenyth
    Oct 14, 2010 at 19:49
3

Cron jobs do not run in any sort of display environment, so using any GUI or TUI apps in them is generally inappropriate. Check the mail sent by the cron job for success/failure notification instead.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .