Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
    
Ohk. I figured out. Its showing error .... kdialog: cannot connect to X server. –  shadyabhi Oct 14 '10 at 8:40
    
How do I solve that? –  shadyabhi Oct 14 '10 at 8:40
    
Perhaps it would help if you describe what the 'bigger script' is intended to do. –  JRT Oct 14 '10 at 9:21
add comment

2 Answers

up vote 1 down vote accepted

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!!" &
share|improve this answer
1  
Specifically, it doesn't run in any X session unless you tell it to via DISPLAY –  Daenyth Oct 14 '10 at 19:49
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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