View previous topic :: View next topic |
Author |
Message |
dufeu l33t
Joined: 30 Aug 2002 Posts: 924 Location: US-FL-EST
|
Posted: Wed May 29, 2013 9:16 pm Post subject: What am I doing wrong in crontab? [SOLVED - bsakb] |
|
|
I haven't used crontab for years and when I did, it was the SysV version.
Assuming I read the man (5) crontab instructions correctly, the following should work: Code: | # crontab -u root -l
# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (/tmp/crontab.XXXXIktbij installed on Wed May 29 07:22:48 2013)
# (Cron version V5.0 -- $Id: crontab.c,v 1.12 2004/01/23 18:56:42 vixie Exp $)
# we don't need mail
MAILTO=""
# send current APC time and date
0-59/2 * * * * apcaccess status | grep "DATE " >> /root/crontab.jobs/linevolts.log
# send current APC line volts
0-59/2 * * * * apcaccess status | grep LINEV >> /root/crontab.jobs/linevolts.log |
The idea is to run 'apcaccess' every two minutes and get the current utility provided line voltage. When I run the commands directly from the prompt, everything works as expected and the /root/crontab.jobs/linevolts.log is updated with the desired lines.
So .. what am I doing wrong or not understanding about executing commands in cron?
I did try different variations on the commands I want to execute with the same negative results: Code: | # send current APC time and date
*/2 * * * * apcaccess status | grep "DATE " >> /root/crontab.jobs/linevolts.log |
_________________ People whom think M$ is mediocre, don't know the half of it.
Last edited by dufeu on Fri May 31, 2013 12:24 am; edited 1 time in total |
|
Back to top |
|
|
mike155 Advocate
Joined: 17 Sep 2010 Posts: 4438 Location: Frankfurt, Germany
|
Posted: Wed May 29, 2013 9:47 pm Post subject: |
|
|
The environment is different for programs started from shell and started from cron. Most probably, cron doesn't find your program, because it uses a different PATH variable. Therefore, use the full path to your program in crontab, eg. "/usr/bin/apcaccess" instead of "apcaccess".
Also execute "export > /tmp/export.shell" from your command shell and execute "export > /tmp/export.crontab" started from cron. Compare the two files - you will see the difference.
In most cases I don't start programs directly from crontab - I start a shell script from cron which first sets all required environment variables and then executes the program I really want to start. |
|
Back to top |
|
|
swathe n00b
Joined: 04 Jul 2011 Posts: 73
|
Posted: Thu May 30, 2013 5:55 am Post subject: |
|
|
I agree I only point crontab to scripts. It's a lot easier to mange in my opinion. |
|
Back to top |
|
|
dufeu l33t
Joined: 30 Aug 2002 Posts: 924 Location: US-FL-EST
|
Posted: Fri May 31, 2013 12:23 am Post subject: |
|
|
bug_report wrote: | The environment is different for programs started from shell and started from cron. Most probably, cron doesn't find your program, because it uses a different PATH variable. Therefore, use the full path to your program in crontab, eg. "/usr/bin/apcaccess" instead of "apcaccess".
Also execute "export > /tmp/export.shell" from your command shell and execute "export > /tmp/export.crontab" started from cron. Compare the two files - you will see the difference.
In most cases I don't start programs directly from crontab - I start a shell script from cron which first sets all required environment variables and then executes the program I really want to start. |
Thank you for reminding me of the environment issue. I had completely and totally forgotten that.
The actual path for apcaccess is '/sbin/apcaccess'. Just noting.
I was more interested in 'proof of concept. The intent is to have a set of scripts to include log rotation on either day end or week end boundries.
I've become a 'housemate' in a relatively rural house. There is a history of motorized equipment {for example: 5 vacuum cleaners in 8 years} burning out after warranty but much sooner than expected. So I want to use my APC BackUPS units to record incoming line voltage over time. So far, the voltage range has been from 122-126 volts. For those that don't know, 126 volts is the maximum legal over voltage {5%} on a nominal 120 volt line.
Since I have two BackUPS, I'm going to hook one unit to each incoming 'hot' line {we appear to have 240 volt (weye) service} and monitor them.
Given the fact we seem to have continuous over voltage {never less than 122 volts} on each incoming 'hot' line, I suspect the local transformer is due for replacement. But I can't call them and complain unless I have something I can show them. Hence the logs.
I want to let the logs accumulate for awhile to see if there are any notable patterns before I call though - i.e. - consistent times when the over voltage is higher. That kind of thing.
The last neighbourhood I lived in consistently had a solid 120 volt service at all times. The only time the voltage wasn't 120 was when power went out completely {hurricanes do that}. _________________ People whom think M$ is mediocre, don't know the half of it. |
|
Back to top |
|
|
mike155 Advocate
Joined: 17 Sep 2010 Posts: 4438 Location: Frankfurt, Germany
|
Posted: Fri May 31, 2013 1:26 am Post subject: |
|
|
That's very interesting! Thanks for sharing your ideas!
Do you know rrdtool? Maybe its a bit oversized for your project - but someone seems to have measured and recorded outlet voltage using his APC UPS and rrdtool.
Look here: http://oss.oetiker.ch/rrdtool/gallery/index.en.html and scroll down to 'Voltage control on APC Smart-UPS 2200'. |
|
Back to top |
|
|
|