简体   繁体   中英

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

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 .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM