Shell script with cronjob


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script with cronjob
# 1  
Old 09-25-2013
Shell script with cronjob

Hello All,

I have a script which will cd into a directory based on current timestamp.
It will then do a grep and search for a condition. It's run on a cron job that runs every 30 minutes. So if it finds a match in 00, it sends out the contents of that grep to an alert and emails out. Now say, 01 comes around and nothing is in that file but the contents of 00 are still alerted and emailed out. I know it's doing that because it's repeating the grep from 00.. Is there a better way to do this grep? I'd hate to create 24 separate cronjobs for the same script based on timestamp.
Code:
#*/30 * * * 1,2,3,4,5 /pathtoscript.sh

cd /live/prod/`date +%Y/%m/%d`/prod/somedirectory/

the logs in somedirectory are based on GMT timestamp 

00  01  02  03  04  05  06  07  08  09  10  11  12  13  14

grep Order * |grep -i XFS*

Your comments are greatly appreciated.
Moderator's Comments:
Mod Comment Please use code tags next time for your code and data


---------- Post updated at 01:53 PM ---------- Previous update was at 10:16 AM ----------

My apologies. I have a cronjob that runs every 30 minutes
Code:
*/30 * * * 1,2,3,4,5 /pathtoscript.sh

pathtoscript.sh consists of the following
Code:
cd /live/prod/`date +%Y/%m/%d`/prod/somedirectory/

COUNT=`grep Order *| wc -l`
OUT=`grep OrderToOrder * `

if [ "$COUNT" -eq 0 ]
then
  exit 1
else
  echo "$OUT" |mutt -s "\"Order FOUND, FYI, Please check\" " -- myemail.address.com
fi

exit 0

##Now on first run if a match is found in say 00 hr, if success it will email contents

When script runs again the next half hr, it will return the same results from 00.

Is there anyway to have the cron run again and not display the 00 output? The only other way i can figure it out is to have the same script but grep for diff hours. But then i would have to duplicate the script many times. Is there any other solution?

Last edited by Scott; 09-25-2013 at 03:09 PM.. Reason: Use code tags, please...
# 2  
Old 09-25-2013
So, at hour 0 you want to email everything from the 0 folder to the 24 folder; but at hour 5, you only want to email everything from the 5 folder to the 24 folder?
# 3  
Old 09-25-2013
What's the structure of your order files? One big, growing file with many orders, or one file per order?

EDIT: @Corona688: I don't think there are distinct directories per hour, but per day.
# 4  
Old 09-30-2013
RudiC - The log file structure is below

00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16, etc. These logs are based on GMT timestamp. In each log are many orders and entries.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Linux script for several cronjob

I have a linux server for my joomla website. I am importing xml feeds (around 200). The component give a tool which list all the cron job commands to automaticaly make the feeds import I don't want to add one by one each cron job. So my idea is to make one cron job which will call a shell... (0 Replies)
Discussion started by: nino59
0 Replies

2. Shell Programming and Scripting

Schedule and Run By weekly shell script in cronjob

Hi All, How to schedule a shell script(script name- byweeklyreport.sh) it should run by weekly in corn job or is there any script have to write to check week and then run the above script. example-1st run March 06 2013 2nd run March 20 2013 3rd run April 3 2013... (13 Replies)
Discussion started by: krupasindhu18
13 Replies

3. Shell Programming and Scripting

Shell script scheduling in cronjob

Hi, I have developed a file deletion script and scheduled it in cronjob to run daily at 5:00 AM. But the script is not running automatically any day. However when I run the script manually at any time, it runs successfully. This is how the cron looks like : 0 5 * * *... (5 Replies)
Discussion started by: jhilmil
5 Replies

4. UNIX for Dummies Questions & Answers

How to Update DB table from txt file using CRONJOB in Unix Shell Script

Hi Experts, can guide how we can Update a Database Table using a txt file source Using Unix Shell Scripts. What are the Cron Jobs codes can written to Update DB table. txt file contains record like data. US 09/03/2012 User DocType DocID. these above feilds in txt files need to be updated in... (4 Replies)
Discussion started by: mahesh.sap
4 Replies

5. UNIX for Dummies Questions & Answers

Script not running through Cronjob

Hi, I have a .ksh script which updates the database. The script is running fine manually but it is not running through cron.All the file permissions are fine. The script contents are as below: #!/usr/bin/ksh ddate=`date +%Y%m%d` echo $ddate nohup sqlplus crm/crm @db_state_sync.sql >>... (3 Replies)
Discussion started by: shivangi
3 Replies

6. Shell Programming and Scripting

Execute Shell Script from CRONJOB

Hi Users, I am Newbie to linux and cron. I have a requirement to run a job at 8 AM every Sunday. I am using RHEL 5. Based on the hints through google search I created crontab and added entry to call the shell script which will in turn login to Oracle user and execute a pl/sql block. ... (1 Reply)
Discussion started by: reachravi70
1 Replies

7. UNIX for Dummies Questions & Answers

how to cancel a cronjob if the cronjob still running

hi everyone I'm newbie in this forum hope I can get some help here :) I have a command in crontab that executed every 1 minute sometime this command need more than 1 minute to finish the problem is, the crontab execute this command although it's not finish processing yet and causing the system... (7 Replies)
Discussion started by: 2j4h
7 Replies

8. Shell Programming and Scripting

cronjob inside the script

Hiii, can nayone provide me the sample script which can do the following tasks--- I will apperciate if anyone give me their valuable inputs.I guess this is not at all a big task for the experts in the forum so kindly help me out in this. (3 Replies)
Discussion started by: namishtiwari
3 Replies

9. Shell Programming and Scripting

help help cronjob problem with script

hi all, have no experience with cronjob at solaris, i have create script like below: #!/bin/sh DAY=`/export/home/oracle/bin/lastdate | nawk '{print $1}'` /export/home/orahome/bin/sqlplus -s abc/abc<<eof set heading off; set linesize 100; set feedback off; spool... (4 Replies)
Discussion started by: bucci
4 Replies

10. Shell Programming and Scripting

Shell script not running thru Cronjob

Hi I have a shell script, it run ok if executed from the path it is located at but doesnot run when the same is tried through cron-job. can someone help me please. regards gaurav shrinivas Email address removed (8 Replies)
Discussion started by: gauravshrinivas
8 Replies
Login or Register to Ask a Question