user2998726
user2998726

Reputation: 3

Bash crontab doesn't output products of shell script file

Hi I'm a first year game programing student learning Unix Bash, I have run into a problem trying to understand crontab. I'm trying to do some rather simple things, checking to see if I am online, getting information about a given website, and ping another website to verify it is online. My script file does all of this without fail, however when I try to perform these tasks through crontab I get emails telling me absolutely nothing but jibberish. The output basically just tells me that I am trying to do all these things, but it doesn't output the results. I'm not sure where I am going wrong. Just to verify I do have permission on the system to use crontab, and I have the script running every minute while I am trying to get it working. I'm hoping someone can point me in the right direction, all of my research online has really just led me astray.

This is my crontab

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
HOME=/
LOGNAME=username

* * * * * /bin/bash /home/students/~/online.sh

30 23 1 * * rm online.log

this is my script

touch online.log
who | grep username >> online.log ; whois yahoo.ca >> online.log ; ping -c 1 www.google.com >> online.log

Upvotes: 0

Views: 384

Answers (2)

devnull
devnull

Reputation: 123608

You need to use absolute paths in your scripts if you want to execute those using cron.

Note that cron executes in a different environment from what you get while executing a script on the command line. For example, changes lines like

touch online.log

to include the absolute path to online.log.

Upvotes: 1

Robin Green
Robin Green

Reputation: 33083

The output is being redirected into online.log, so you need to look there, not in your emails. If you want the output to be in the emails as well, you should look into using tee instead of a redirection.

Upvotes: 0

Related Questions