Problems with script and Cron


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Problems with script and Cron
# 1  
Old 04-16-2010
Problems with script and Cron

Hi Guys,

total newbie here, Ive read through some of the threads about cron and scripts not working and have still drawn a blank as to why mine isnt working correctly.

I have a script that runs the ausearch with a set of criteria i have setup, the only access i have to the system is via puttycm(putty) and su to the root account.

The script checks the audit log for the criteria and dumps it out to a file i have specified, now when I call this from bash it runs fine and creates all the files and populates all the files I expect it to from the files I am watching in auditd.

when I setup cron to do this all the files get created but nothing get populated into them.

Sample script:

Code:
#!/bin/bash

TODAYS=`date +%Y-%m-%d`

mkdir /var/audits/TC/$TODAYS
mkdir /var/audits/Apache/$TODAYS
mkdir /var/audits/Tomcat/$TODAYS

/sbin/ausearch -ua 500 -ts today -k tc-tocs -i > /var/audits/TC/$TODAYS/tc-tocs.txt

from crontab -e:
17 19 * * * /var/audits/script/audits.sh

As you can see I am using absolute paths so i dont think its that, this really has me stumped.

Can anyone lend a hand please?

Last edited by pludi; 04-21-2010 at 08:59 AM..
# 2  
Old 04-16-2010
does '/sbin/ausearch' rely on any environment variables that you're aware of?
# 3  
Old 04-19-2010
If this is Red Hat 5.1 it is a known problem which is fixed in 5.2 (introduced the --input-logs parameter).

Of course if you have the later version you need to specify the --input-logs parameter to stop the program reading from standard input).

Last edited by methyl; 04-19-2010 at 12:43 PM..
# 4  
Old 04-21-2010
Quote:
Originally Posted by methyl
If this is Red Hat 5.1 it is a known problem which is fixed in 5.2 (introduced the --input-logs parameter).

Of course if you have the later version you need to specify the --input-logs parameter to stop the program reading from standard input).
I should have mentioned this is running on CentOS 5.2

---------- Post updated at 03:37 PM ---------- Previous update was at 12:24 PM ----------

Are there any other scheduling apps I can try out for CentOS 5.2? as cron seems to be very picky about what it runs, and I cant see any reason why my script is having problems.

Ive even told the /sbin/ausearch the full path to the audit file incase it cant find it, using cron.
# 5  
Old 04-21-2010
Quote:
Originally Posted by richie190784
I should have mentioned this is running on CentOS 5.2

---------- Post updated at 03:37 PM ---------- Previous update was at 12:24 PM ----------

Are there any other scheduling apps I can try out for CentOS 5.2? as cron seems to be very picky about what it runs, and I cant see any reason why my script is having problems.

Ive even told the /sbin/ausearch the full path to the audit file incase it cant find it, using cron.
strace/truss the command and see if it's successfully opening your audit.log file.

Code:
strace -o /myLog.strace /sbin/ausearch -ua 500 -ts `date +%Y-%m-%d` -k tc-tocs -i

You should find something like:

Code:
open("/var/log/audit/audit.log", O_RDONLY) = 4
access("/var/log/audit/audit.log", R_OK) = 0

Also, try upgrading your audit and audit libs to the latest version to ensure that your ausearch is not under the effects of RH bug 436301.


From the ausearch manpage:

Code:
--input-logs
              Use the log file location from auditd.conf as input for searching. This is needed if you are using ausearch from a cron job.


Last edited by verdepollo; 04-21-2010 at 12:32 PM.. Reason: Suggest RPM update.
# 6  
Old 04-21-2010
Well I'm not entirely sure what I changed to get it working but the script is now working,

Thanks for the help guys.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Problems with set up Cron

Hi I want to set up a cron for every 15 minutes between some hours. Can you tell whether the below command will work. Getting confuse because my time goes from night to next day morning. i want to setup 8 PM to next day 10 AM. */15 20-10 * * * sh abc.sh (1 Reply)
Discussion started by: raju2016
1 Replies

2. UNIX for Dummies Questions & Answers

Execution Problems with Cron

Good evening, ive got this cron to be run: if i run this manually it doesnt work,it takes me to the prompt again /export/app/CO/opge/scr/Informe_parametros_colombia.ksh >/dev/null 2>&1 here is the code fragment: coopge@coopge: opge PRODUCCION>more... (1 Reply)
Discussion started by: alexcol
1 Replies

3. UNIX for Dummies Questions & Answers

cron problems

I am trying to setup a cron that runs a script to update my ip for my domain name every time I reboot and checks if my ip changes every 5 minutes and if it does then I update it. I am running Ubuntu server 12.04. The file /etc/cron.d/ipupdate contains # # # Run ipupdate # # /5 * ... (3 Replies)
Discussion started by: Bros2
3 Replies

4. UNIX and Linux Applications

Execution Problems with Cron

Hi all!! I have a nerve-wracking concept (probably for me!!) which is not understood. My crontab entry looks this way. 33 09 22 3 * /home/myexp.sh "Bgp4 ALL" >/dev/null 2>&1 But cron gets started occasionally. Sometimes it does. Sometimes it does not. And sometimes it hangs in the middle (I... (1 Reply)
Discussion started by: dhivyasuresh
1 Replies

5. Programming

execution problems with cron

how to store a date into file? and how we can access date from the file? ---------- Post updated at 06:09 AM ---------- Previous update was at 06:08 AM ---------- how we can store date in file? (1 Reply)
Discussion started by: causalmodi777
1 Replies

6. Shell Programming and Scripting

Problems running script in cron...

Hi all, I have a script running on a Solaris 8 box and the first thing it does it check which user is executing it; if ; then echo "This script must be run as testuser" 1>&2 exit 1 fi This works fine when manually running the script however when adding into that users' crontab it... (1 Reply)
Discussion started by: JayC89
1 Replies

7. Shell Programming and Scripting

Problems with Cron and isql

Dear Friends, I am running a script which runs a select query from a sybase table and outputs the result (1 row) into a .txt file in unix. When I run the script manually it behaves normally. However it doesnt run in crontab. #!/usr/bin/ksh . /opt/ivb/config/set_env ... (1 Reply)
Discussion started by: santoshpayal
1 Replies

8. UNIX for Dummies Questions & Answers

cron problems

Hi there, this time a have a other problem :) i will start a script over the cron. if i start the script manual (per command) it works without any problems, but over the cron it doesent work. my cron looks like this: 26 15 * * * /path/scriptname.sh 2> /path/error.log there is no... (3 Replies)
Discussion started by: scotty
3 Replies

9. UNIX for Advanced & Expert Users

Cron problems

Hi, I am having a few problems with cron. I have created a shell script (to rotate www logs - this works) and then did the following (as root) #crontab -e 2 0 * * 3 /cron_scripts/wwwlogs.sh ? w ? q # crontab -l entry not shown e.g. it did not show what I had just writern I then... (6 Replies)
Discussion started by: warrend
6 Replies

10. UNIX for Dummies Questions & Answers

Very urgent!! Cron problems

I'm having serious problems running cron. I want to create midnight backups of my files on my unix server and there is something wrong with cron. Here is what I do: First I saw that cron is running (while logged on as root) by typing "ps -aedf|grep cron" and I noticed that there is 1 instance... (4 Replies)
Discussion started by: pappous
4 Replies
Login or Register to Ask a Question