How to Make My Cron Job Print to the Terminal?

0
40
Asked By TechWiz247 On

I've been trying to get the hang of cron jobs and shell scripts, but I'm facing an issue where nothing gets printed to the terminal. Here's a quick rundown of what I'm working with:

For my shell script located at /home/user/sayhello.sh, I've got the following code:
```bash
#!/bin/bash

wall "This message prints every minute."
```
In my crontab, I've set it up like this:
```
* * * * * DISPLAY=:0 xterm -e /home/user/sayhello.sh
```
It seems like the cron job is executing every minute since I checked the cron log, but I'm not seeing any output on the terminal. Any advice?

3 Answers

Answered By DevGuru101 On

Before you go further, have you tested the `wall` command separately to see if it works on its own? The way I use it is:
```
echo "This message prints every minute." | wall
```
Try that in your terminal first. Additionally, I would suggest removing the `DISPLAY` and `xterm` references in your crontab. Cron jobs don’t usually have access to your graphical environment, which could be causing the issue. Just call the script directly in the crontab.

Answered By CodeNinja88 On

Have you tried running the script directly using `'/home/user/sayhello.sh'`? It sounds like there might be an issue with the shebang line. You might need to change it to `#!/bin/bash` instead of `!#/bin/bash`, which is why you could be getting a ‘No such file or directory’ error. Also, make sure you have execute permissions on the script through `chmod +x /home/user/sayhello.sh`. Let me know if that clears things up!

Answered By ScripterMaster On

So I tried just running the script like this in crontab:
```
* * * * * /home/user/sayhello.sh
```
but I didn't see any output either. It’s probably still a permission issue or the way you're invoking `wall`. Make sure your script runs fine outside the cron first!

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.