Visit The New, Modern Unix Linux Community


Execution problem with Cron


View Poll Results: Was this post useful?
yes 1 100.00%
no 0 0%
Voters: 1. This poll is closed

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Execution problem with Cron
# 1  
Execution problem with Cron

Hi,
I'm unable to understand why the grep command in cronjob works intermittently

Expected output:
Grep command to look for a particular string with today's date and exit from infinite while loop else it must sleep for 5 mins

I'm using the following statement in my shell script, the variable $logString is empty even when the pattern exists in the log
Code:
while [ -z "$logString" ]
                do
                        echo "Sleep for 5 mins" >> $LOG
                        sleep 300
                        # logString=$(/usr/bin/perl -ne '/STATUS\s+\['"$month"'\/'"$day"'\s+(05|06).*\]\:\s+main\:\s+Active\s+region.*/ && print' << logname>>)
                        logString=$(grep "$(/usr/bin/date +"\%m/\%d")" /ilx/log/exrMngr.log | /usr/bin/grep ".*0[56]\:[0-9]\{2\}\:[0-9]\{2\}" | /usr/bin/grep 'Active region has been')
                        echo "String is: $logString" >> $LOG
                done

while it was successful in yesterday's cron run

Sleep for 5 mins
String is: STATUS [06/09 05:04:57]: main: Active region has been changed from: 0 to: 1

it failed today

Sleep for 5 mins
String is:

Moderator's Comments:
Mod Comment Please use code tags

Last edited by jim mcnamara; 06-10-2019 at 08:40 AM..
# 2  
Three things we need to help:
Code:
1 What UNIX?
2. What shell?
3. a sample of the log file that you know has the pattern.  A few lines are great.

Otherwise we are just guessing what is going on. Thanks.
This User Gave Thanks to jim mcnamara For This Post:
# 3  
1 What UNIX?
- SunOS 11.4.5
2. What shell? -
- /bin/sh
3. a sample of the log file that you know has the pattern. A few lines are great.
Code:
             - STATUS [06/10 05:05:01]: Total counts of security records: 8982673.
               STATUS [06/10 05:05:02]: main: Active region has been changed from: 1 to: 0
               STATUS [06/10 05:06:02]: elapsed time: 60; vait_time: 1800

Cronjob starts at 5, ideally it should have exit at 05:05:02 when it finds the matching string


Snap from the cronjob log
Code:
============ Started at Sun Jun  9 05:00:00 EDT 2019 ==========
Put to maintenance
Sleep for 5 mins
String is: STATUS [06/09 05:04:57]: main: Active region has been changed from: 0 to: 1
Flush_cache.sh Completed
Taking the process out of maintenance


Last edited by vbe; 06-13-2019 at 06:53 AM..
# 4  
Any suggestions from anyone?
# 5  
Well, I can't see an error / failure. No "intermittend" behaviour. Data is from 10. June, and log (which seems to have worked) from 9. June. They can't possibly match.
# 6  
Hey RudiC
thanks for your response

I have managed to fix this issue, now its working consistently
There was no escape sequence needed for %m and %d

Now after fixing the line reads like this
Code:
logString=$(/usr/bin/grep "$(/usr/bin/date +"%m/%d")"  <log name> | /usr/bin/grep ".*0[56]\:[0-9]\{2\}\:[0-9]\{2\}" | /usr/bin/grep 'Active region has been')

# 7  
Why three greps? Why not
Code:
logString=$(/usr/bin/grep  "$(/usr/bin/date +"%m/%d") 0[56]\(:[0-9]\{2\}\)\{2\}.*Active region has been"  <log name>)


Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #274
Difficulty: Easy
OpenSolaris is a descendant of the UNIX System V Release 4 (SVR4) code base developed by Sun and AT&T in the late 1980s.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Execution problem with CRON job

HI, I have written an executable file in unix and I was able to execute it successfully but when I called this file with cron job it was giving error like "permission denied" and "No such file or directory". Please help in how cron calls the file and what permission is required on the file... (2 Replies)
Discussion started by: vipin kumar rai
2 Replies

2. UNIX for Dummies Questions & Answers

Execution problem with Cron: Script works manually but not w/Cron. Why?

Hello gurus, I am making what I think is a simple db2 call from within a shell script but I am having difficulty producing the desired report when I run the script shown below from a shell script in cron. For example, my script and the crontab file setup is shown below: #!/bin/ksh db2... (3 Replies)
Discussion started by: okonita
3 Replies

3. 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

4. Shell Programming and Scripting

Execution problems with cron

I am new to creating crontab file , i just wrote below (40 19 * 3 * /root/maths/practisecron.sh), the script just prints "Hi". When ever i save the above file i am getting this . # crontab -e crontab: installing new crontab Can you please check where it went wrong.. (1 Reply)
Discussion started by: vkiyv05
1 Replies

5. Shell Programming and Scripting

problem with sleep cmd in execution of cron...

I am scheduling a task at regular intervals at seconds acuracy using crond and sleep command . my data in crontab file is as below:- the above line is working fine when we are creating this crontab file before 00:05 min . But when we are creating the crontab file at 00:05min , unable to... (10 Replies)
Discussion started by: manoj424
10 Replies

6. UNIX for Dummies Questions & Answers

Execution Problems with Cron

Hi friends, today i created a cron job , registered the crontab file associated but dont know why the cron is not getting executed at the right time.?? content of Crontab file : 21 15 * * * /subrat/myt i wanted to execute the script myt on 15:21 PM of everyday. the script myt... (2 Replies)
Discussion started by: paras.oriental
2 Replies

7. Shell Programming and Scripting

Execution Problems with Cron

Hi, I have written a shell script to transfer files to a SFTP server passing the filername, source and dest directory as parameters and it runs well. :) I want to schedule this script to run periodically using a cron job. root@pingu # cat /etc/crontab SHELL=/bin/bash... (1 Reply)
Discussion started by: chetancrsp18
1 Replies

8. AIX

Execution Problem with Cron

Guys, I am beginer in unix. There is a cobol file with fixed-width. I want to read the total Line, Word and character count. I have tried with wc-l unix command, but it returns '0'. Please advice me the correct command/steps to get the record count. Thanks in advance. (4 Replies)
Discussion started by: vibhar
4 Replies

9. Solaris

Solaris 10.5 perl and cron job execution problem

Hi, I want to run a crontab job on solaris 10.5. I have configured the crontab accordingly 10 * * * * /scripts/dbalter.pl >> /scripts/cronout.txt However this does not work .Then I go to /var/mail/root and find an error in the output: From root@myserver Wed Feb 4 17:02:00 2009... (1 Reply)
Discussion started by: sonu2die4
1 Replies

10. Solaris

cron execution

Hi, Here is the code snippet when executing on the command line it does execute smoothly, but while i place this on cron it doesnt run. Can anybody suggest where the problem in cron is.? #!/usr/bin/ksh home_dir="/export/home/scripts/MonitorScripts" ThresholdLimit=5 touch... (6 Replies)
Discussion started by: rameek20
6 Replies

Featured Tech Videos