LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (http://www.linuxquestions.org/questions/slackware-14/)
-   -   Need help running cron in Slackware 12.1 (http://www.linuxquestions.org/questions/slackware-14/need-help-running-cron-in-slackware-12-1-a-646711/)

trillobyte 06-03-2008 12:04 PM

Need help running cron in Slackware 12.1
 
Hello:

I am going through a Crontab tutorial and have reached a roadblock.

I have tried the following test as a user and as root using crontab -e:

* * * * * /usr/bin/wall "Hello From Crontab"

I get no response or messages as I instructed.

I did a ps -aux | grep crond and it shows crond running:

root 2838 0.0 0.0 1912 632 ? S May30 0:00 /usr/sbin/crond -l10

I can't figure out why cron will not run as both a user and root for me.
Any help will be appreciated.

Best regards

T3slider 06-03-2008 12:18 PM

That's really nifty, I didn't know about the "wall" command. However, your syntax is incorrect. I tested `/usr/bin/wall "Hello From Crontab"` and received an error. `wall` is expecting a file to display instead of a message. There are two options. You could create a file with those contents and use `/usr/bin/wall < /path/to/file.txt`, or you could use `/usr/bin/echo "Hello From Crontab" | /usr/bin/wall`. Either one will work.

trillobyte 06-03-2008 12:30 PM

Quote:

Originally Posted by T3slider (Post 3173426)
That's really nifty, I didn't know about the "wall" command. However, your syntax is incorrect. I tested `/usr/bin/wall "Hello From Crontab"` and received an error. `wall` is expecting a file to display instead of a message. There are two options. You could create a file with those contents and use `/usr/bin/wall < /path/to/file.txt`, or you could use `/usr/bin/echo "Hello From Crontab" | /usr/bin/wall`. Either one will work.

Thanks for the reply. I tried the /usr/bin/echo "Hello From Crontab" | /usr/bin/wall and I still get no response from cron. I have also tried the getmail command to retrieve my e mail but it looks like cron is refusing to respond for some reason. Getmail works if I try it manually.

T3slider 06-03-2008 12:56 PM

I just tested it as my normal user and this seems to work:
Code:

$ crontab -l
* * * * * /path/to/script.sh

script.sh consists of the following:
Code:

$ cat /path/to/script.sh
#!/bin/sh

/usr/bin/echo "Hello From Crontab" | /usr/bin/wall

I could get cron to perform the wall command but the message wasn't carrying through with my previous suggestions (it was just a blank message), and using quotes didn't seem to help the issue. This solution works, however.

An easy way to test whether or not cron is working is to delete your current crontab (`crontab -d`) and add the following line:
Code:

$ crontab -l
* * * * * DISPLAY=:0.0 /usr/bin/xmessage "Hello"

If you are in an X session, you'll get a dialog box popping up once a minute.

trillobyte 06-03-2008 01:19 PM

Quote:

Originally Posted by T3slider (Post 3173461)
I just tested it as my normal user and this seems to work:
Code:

$ crontab -l
* * * * * /path/to/script.sh

script.sh consists of the following:
Code:

$ cat /path/to/script.sh
#!/bin/sh

/usr/bin/echo "Hello From Crontab" | /usr/bin/wall

I could get cron to perform the wall command but the message wasn't carrying through with my previous suggestions (it was just a blank message), and using quotes didn't seem to help the issue. This solution works, however.

An easy way to test whether or not cron is working is to delete your current crontab (`crontab -d`) and add the following line:
Code:

$ crontab -l
* * * * * DISPLAY=:0.0 /usr/bin/xmessage "Hello"

If you are in an X session, you'll get a dialog box popping up once a minute.

I tried that and it's not working.

trillobyte 06-03-2008 01:20 PM

I meant I tried the * * * * * DISPLAY=:0.0 /usr/bin/xmessage "Hello"
and it didn't work. I did it as root.

T3slider 06-03-2008 02:49 PM

You may wish to direct your error output to a file to see what's happening. Something like the following would do nicely:
Code:

$ crontab -l
* * * * * DISPLAY=:0.0 /usr/bin/xmessage "Hello" 2> /path/to/error.txt

That way you could see if there are any errors. You may also wish to direct standard out to a file as well. Something like the following would throw every message into a file:
Code:

$ crontab -l
* * * * * DISPLAY=:0.0 /usr/bin/xmessage "Hello" 2>&1 > /path/to/error.txt


trillobyte 06-03-2008 03:01 PM

Well I tried it and this is what the error.txt indicates:

No protocol specified
Error: Can't open display: :0.0


Best regards

T3slider 06-03-2008 03:22 PM

Well, that at least means that crond is working. I won't try to determine why the xmessage thing isn't working because it isn't relevant to the wall command (though it probably has something to do with running the crontab entry as root, or possibly something's awry if you use runlevel 4). You could try doing the same with the wall script I posted above to see why it isn't working.

trillobyte 06-03-2008 04:00 PM

I got it to work doing it as a script...* * * * * /path/to/script.sh
I'm happy knowing that Cron is working. I really appreciate the help you have given me T3slider.

Best regards


All times are GMT -5. The time now is 03:40 AM.