Run script from another script if system date was reached


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Run script from another script if system date was reached
# 1  
Old 03-03-2010
Run script from another script if system date was reached

I what to find a system date in a shell script and search for it in a file in specific record.
If the record (ENDC) has the same date I what to execute another shell script.

Here is example of the file:

Quote:
list abf.dbf -j -p9-12eq"ENDC" -c=101
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxENDAxxxxxxxxxxxxxxx2010030119435857P ??????
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxENDBxxxxxxxxxxxxxxx2010030119435857P ??????

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxENDCxxxxxxxxxxxxxxx2010030119435857P ??????[/


Can someone please help me with this ?

# 2  
Old 03-03-2010
Maybe this is what your looking for...
Code:
#!/bin/ksh

typeset -i record_cnt=$(grep -c "ENDC.*$sysDate" file1)
if (( $record_cnt > 0 )); then
  execute_script.sh
fi

# 3  
Old 03-04-2010
If you are using bash shell use the following script.

Code:
#!/bin/sh

date=`date "+%Y%m%d"`
typeset -i record=$(grep -c "ENDC.*$date" fil)
echo $record;
if [[ $record -gt 0 ]]; then
        sh another_script.sh
fi


Last edited by Nila; 03-04-2010 at 12:22 AM..
# 4  
Old 03-04-2010
The following POSIX date command will give you that last day of the previous month (including the previous year) in an easily parsed format:

Code:
date  -j -v1d -v-0m -v-1d +'%m %d %Y'

The -j flag says 'don't change the system date based on what follows'

The -v option returns adjustments to the current date. There can be more than one and interpreted left to right. So:
'-v1d' sets the first date of the current month;
'-v-0m' subtracts zero months, but could be different if you want the last day of another month;
'-v-1d' subtracts 1 day from the first of the month giving the last day of the previous month.
'%m %d %Y' gives the format of '02 28 2010' if you run this command any day this month.

Now just parse that with BASH, awk or perl and you are on your way.

Hope that helps...

Last edited by drewk; 03-04-2010 at 01:40 PM.. Reason: typo...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Run shell script based on date file

Hi Team, I have a to run a script based on a date present in a different file which updates everyday. Kindly help with the solution. My current execution : ksh scriptname.sh 10152019. But here i want to enter this date from a file which gets updated daily. My appraoch : date file location:... (3 Replies)
Discussion started by: midhun3108
3 Replies

2. Shell Programming and Scripting

Pass system date and sysdate-7 in script through crontab

Hi , I have to schedule one job in crontab, but with two parameters. 1. Sysdate in YYYYMMDD format 2. Sysdate - 7 in YYYYMMDD format Please suggest how to do that. Thanks in advance. (1 Reply)
Discussion started by: Anupam_Halder
1 Replies

3. UNIX for Dummies Questions & Answers

How to write a shell script to Run it the from Date A to Date B?

Hi , How would i write a shell script to run the code from one date to another date EXample 2014-01-01 to 2014-02-28, can i any provide some clue on this (4 Replies)
Discussion started by: vikatakavi
4 Replies

4. Shell Programming and Scripting

Perl system() to run a script

Hello, I'm trying to run "csso" (minify css) in a CGI script from the web panel. That is not working: Returns error 0; my $cmd = qq`csso stylesheet.css > stylesheet.min.css`; system($cmd); But that is working: my $cmd = qq`echo 'blabla' > stylesheet.min.css`; system($cmd); I'm... (12 Replies)
Discussion started by: madispuk
12 Replies

5. Shell Programming and Scripting

run script in time and date range

i need to run one script inside of other, and there is some terms - main script in scheduled in cron for everyday runing every 5min - i need to run /tmp/script2.sh after first 3 days in month - i need to run /tmp/script2.sh from 7-9AM, main script is runining all day all recommendations are... (1 Reply)
Discussion started by: waso
1 Replies

6. Shell Programming and Scripting

shell script that will run for a specific date

Hi, I have these changes needed to modify a shell script that will run on a specific date of a month, below pseudocode, appreciate any answers..thanks.. if date of the month is 26th then ..event 1 fi if date of the month is 26th and month are MAR,JUN,SEP,DEC then ..event2 ... (7 Replies)
Discussion started by: sonja
7 Replies

7. Shell Programming and Scripting

Add 1 year to System date in script

Hi All, I wanted to add 1 year to the system date in my script. say export start_date=`date +%F` echo $start_date o/p of this is 2009-09-02 To this i want to add 1 year. the output i need here is 2010-09-02 can anybody help me ? Thanks in advance, Vinay (4 Replies)
Discussion started by: vinayakatj56
4 Replies

8. UNIX for Advanced & Expert Users

To run the script only if the date is not between 5 th and 10th of january ?

Hi I am new to unix. I have to set up a cron for the program , which should run every Monday at 3 a.m, however , if the date is between the 5 th and the 15th of January,APril or December, the program should not run I know i cant do this in cron , Help with writing the if contion is... (7 Replies)
Discussion started by: saiviren
7 Replies

9. Shell Programming and Scripting

Run Shell Script on Remote System

I honestly tried searching for this in this forum and in google. Maybe I found the answer but didn't even realized it. I would like to run shell script thats on my machine that collects the hostname and IP address from the remote system and sends the output to my machine. I'm not sure if need... (2 Replies)
Discussion started by: elbombillo
2 Replies

10. Shell Programming and Scripting

Shell script for Creating Directory with name as system date

Dear Sir/Madam, I need a bit of your help. The problem is as follows : I have to create a directory in unix whose name is that of system date in the dd_mon_yyyy format . I am able to extract a date in required format ina variable , but when i'm using this variable in mkdir it is not... (7 Replies)
Discussion started by: aarora_98
7 Replies
Login or Register to Ask a Question