LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   Cron job parsing error (http://www.linuxquestions.org/questions/linux-software-2/cron-job-parsing-error-776524/)

clcbluemont 12-17-2009 04:01 PM

Cron job parsing error
 
I am trying to run a BASH script that contains the following command:
aureport -i --failed -ts 12/08/2009 > somefile.txt

The script runs fine from the command line but not by cron. I feel that the situation was improved by changing to the following:
aureport -i --failed -ts 12\/08\/2009 > somefile.txt

At least cron/aureport produces "error parsing start date (12/08/2009)". Otherwise it spits out the the aureport command line options like I don't have any clue as to what I am doing.

Running the command from a TCSH script works fine. However for reasons I will not describe I must use BASH. Any ideas why cron is not processing this correctly?

rweaver 12-17-2009 04:28 PM

Can you paste up the whole script?

unSpawn 12-17-2009 04:30 PM

Comments at "fix_date" in aureportgen.py at http://www.g-loaded.eu/packages/aure...gen-0.1.tar.gz say it's a glitch in aureport?

catkin 12-17-2009 04:38 PM

Would you care to be more specific about "it spits out the the aureport command line options like I don't have any clue as to what I am doing"?

How are you running this script? Via a bash command or directly as an executable file?

It sounds as if something in the environment differs between when the job is run from cron and from the command line. The question is what. For starters let's simulate the login environment by changing the first line of the script to
Code:

#!/bin/bash -l
That's a letter l for login.

Not good practice to leave it set like that because any terminal read or write by the shell login initialisation files will make cron suspend the job but a good technique to help identify the triggering cause of the problem.

Usually the problem is the value of $PATH -- so you could get the script to write that (to a file, not the terminal!) for comparison purposes; if there is a significant difference then the script can set the $PATH it wants rather than accepting whatever cron gives it (but you knew that already from searching LQ).

ShadowCat8 12-17-2009 05:07 PM

I want to make sure I understand the situation:

You have the following command inside of a BASH script:
Code:

aureport -i --failed -ts 12\/08\/2009 > somefile.txt
Correct?

And, then the cronjob running the script keeps giving you different output. Right?

Let us know.

clcbluemont 12-17-2009 05:28 PM

CRON bash and aureport
 
I want to make sure I understand the situation:

You have the following command inside of a BASH script:
Code:

aureport -i --failed -ts 12\/08\/2009 > somefile.txt
Correct?
Yes

And, then the cronjob running the script keeps giving you different output. Right?
I removed the problem command from the main script as to simplify troubleshooting.

[root@someae485151l ~]# ls -l file
-rwxr-xr-x 1 root root 53 Dec 17 18:19 file
[root@someae485151l ~]# cat file
#! bash

/sbin/aureport -i --failed -ts 12\/16\/2009
[root@someae485151l ~]#
The cron is setup for troubleshooting:
0,5,10,15,20,25,30,35,40,45,50,55 * * * * /root/file

The root user receives an e-mail saying:
error parsing start date (12/08/2009)

If I don't escape out the forward slashes I get:
usage: aureport [options]
-a,--avc Avc report
--auth Authentication report
-c,--config Config change report
-cr,--crypto Crypto report
-e,--event Event report
-f,--file File name report
--failed only failed events in report
-h,--host Remote Host name report
--help help
-i,--interpret Interpretive mode
-if,--input <Input File name> use this file as input
--input-logs Use the logs even if stdin is a pipe
-l,--login Login report
-k,--key Key report
-m,--mods Modification to accounts report
-ma,--mac Mandatory Access Control (MAC) report
--node <node name> Only events from a specific node
-n,--anomaly aNomaly report
-p,--pid Pid report
-r,--response Response to anomaly report
-s,--syscall Syscall report
--success only success events in report
--summary sorted totals for main object in report
-t,--log Log time range report
-te,--end [end date] [end time] ending date & time for reports
-tm,--terminal TerMinal name report
-ts,--start [start date] [start time] starting data & time for reports
-u,--user User name report
-v,--version Version
-x,--executable eXecutable name report
If no report is given, the summary report will be displayed

Again it works fine when I run file from the command line it is just through cron.

clcbluemont 12-17-2009 05:59 PM

Adding -l to bash gets the script to function under cron. I had executed env and did not see anything in the environment that would seem to aid the scripts execution. Ideas?

catkin 12-18-2009 01:33 PM

Intriguing.Sometimes environment variables can be subtle in their effect. Can you post the output of diff on the env output with and without the -l on the first line of the script?

What happens if you replace "12\/08\/2009" with '12/08/2009'?

clcbluemont 12-19-2009 08:01 AM

Here is the in the environments:
diff /tmp/file /tmp/file1
0a1
> HOSTNAME=name1.seadeer.com
1a3,6
> HISTSIZE=1000
> KDE_NO_IPV6=1
> QTDIR=/usr/lib/qt-3.3
> QTINC=/usr/lib/qt-3.3/include
3,4c8,12
< PATH=/usr/bin:/bin
< _=/usr/bin/env
---
> LS_COLORS=
> KDEDIR=/usr
> MAIL=/var/spool/mail/root
> PATH=/usr/lib/qt-3.3/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/bin:/bin:/root/bin
> INPUTRC=/etc/inputrc
5a14,16
> LANG=en_US.UTF-8
> KDE_IS_PRELINKED=1
> SSH_ASKPASS=/usr/libexec/openssh/gnome-ssh-askpass
8a20,24
> QTLIB=/usr/lib/qt-3.3/lib
> CVS_RSH=ssh
> LESSOPEN=|/usr/bin/lesspipe.sh %s
> G_BROKEN_FILENAMES=1
> _=/usr/bin/env
I had done an env, but had not thought of doing a diff. Thank you. The output without the escapes is:
usage: aureport [options]
-a,--avc Avc report
--auth Authentication report
-c,--config Config change report
-cr,--crypto Crypto report
-e,--event Event report
-f,--file File name report
--failed only failed events in report
-h,--host Remote Host name report
--help help
-i,--interpret Interpretive mode
-if,--input <Input File name> use this file as input
--input-logs Use the logs even if stdin is a pipe
-l,--login Login report
-k,--key Key report
-m,--mods Modification to accounts report
-ma,--mac Mandatory Access Control (MAC) report
--node <node name> Only events from a specific node
-n,--anomaly aNomaly report
-p,--pid Pid report
-r,--response Response to anomaly report
-s,--syscall Syscall report
--success only success events in report
--summary sorted totals for main object in report
-t,--log Log time range report
-te,--end [end date] [end time] ending date & time for reports
-tm,--terminal TerMinal name report
-ts,--start [start date] [start time] starting data & time for reports
-u,--user User name report
-v,--version Version
-x,--executable eXecutable name report
If no report is given, the summary report will be displayed

catkin 12-19-2009 09:05 AM

Quote:

Originally Posted by clcbluemont (Post 3797850)
Here is the in the environments:
[snip]
I had done an env, but had not thought of doing a diff. Thank you. The output without the escapes is:[snip]

There are quite a few envar differences there and I for one do not know what their effect might be on aureport. It might be worth adding export var=value commands in the script to replicate the envars set when "logged in". If that fixes it, comment half of them out ... and so on until you find which one(s) are required to make aureport work.

When you tried removing the escapes, did you also change the quotes from double to single?


All times are GMT -5. The time now is 02:33 AM.