can I specifiy the start and end times manually


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting can I specifiy the start and end times manually
# 1  
Old 01-09-2010
can I specifiy the start and end times manually

Hi

I have a ksh script which fetches data from a db using a number of .arc files and creates CSV files for them and puts them on the server.

Question is, can I specifiy the start and stop times manually and run the script manually to fetch data for a certain period?


# Get the current time as the stop time.

Code:
stoptime=`date +"%Y-%m-%d %H:00"`
if test $? -ne 0
then
   echo "Failed to get the date"
   rm -f $1/.optpamd.pid
   exit 4
fi

# Read the lasttime file to get the start time
# optlasttime contains the last time the database was
# successfully queried. The file is automatically created by
# this script

Code:
if test -f $1/optlasttime
then
   starttime=`cat $1/optlasttime`

# If the length of the chain is zero
# (lasttime is empty) it is updated properly
# and I wait for the following hour
Code:
   if test -z "$starttime"
   then
      echo "Empty file lasttime"
      echo $stoptime > $1/optlasttime
      rm -f $1/.optpamd.pid
      exit 5
   fi
else
   # If lasttime does not exist I create, it with the present date
   # and I wait for the following hour
   echo "File lasttime does not exist"
   echo $stoptime > $1/optlasttime
   rm -f $1/.optpamo.pid
   exit 6
fi

# Get a list of reports to run

Code:
while test "$starttime" != "$stoptime"
do

day=`echo $starttime | nawk '{ printf "%02d\n", substr($1,9,2)}'`
month=`echo $starttime | nawk '{ printf "%02d\n", substr($1,6,2)}'`
ano=`echo $starttime | nawk '{ printf "%02d\n", substr($1,1,4)}'`
hour=`echo ${starttime#* } | nawk '{ printf "%02d\n", substr($1,1,2)}'`
minute=`echo ${starttime#* } | nawk '{ printf "%02d\n", substr($1,4,2)}'`

Code:
more code to fetch data from db


# The interval superior of the date is the same that the inferior
# but increased 1 hour
Code:
endtime=$ano-$month-$day" "$hour":"$minute
ftime=$ano$month$day$hour$minute

#There are a number of '.arc' files per which this script fetches data from the db.
Code:
    #
      basename $rep
      datafile=$2/`basename $rep`.$ftime.csv
      rm -f $datafile
      touch $datafile

# For each report I execute its sentence SQL

Code:
for rep in $reports
   do

# Create Output file per each Measurement per hour

Code:
basename $rep
      datafile=$2/`basename $rep`.$ftime.csv
      rm -f $datafile
      touch $datafile

# Emptiness the files of compiled errors and reports

Code:
rm -f $1/aceerror
      rm -f $1/$rep.ace $1/$rep.arc
      
      echo "FROM :"$starttime"    TO :"$endtime"       STOPS:"$rep

# The hour changes

Code:
cat $rep.act | sed -e "s/STARTTIME/datetime($starttime) year to minute/" \
			 -e "s/ENDTIME/datetime($endtime) year to minute/" > $rep.ace

Any advice appreciated...Code too complex for me.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Splitting week start date and end date based on custom period start dates

Below are my custom period start and end dates based on a calender, these dates are placed in a file, for each period i need to split into three weeks for each period row, example is given below. Could you please help out to achieve solution through shell script.. File content: ... (2 Replies)
Discussion started by: nani2019
2 Replies

2. Shell Programming and Scripting

How to extract start/end times from log file to CSV file?

Hi, I have a log file (log.txt) that which contains lines of date/time. I need to create a script to extract a CSV file (out.csv) that gets all the sequential times (with only 1 minute difference) together by stating the start time and end time of this period. Sample log file (log.txt) ... (7 Replies)
Discussion started by: Mr.Zizo
7 Replies

3. UNIX for Dummies Questions & Answers

Append no of times a column is repeated at the end

Hi folks, Iam working on a bash script, i need to print how many times column 2 repeated at the end of each line. Input.txt COL1 COL2 COL3 COL4 1 XX 45 N 2 YY 34 y 3 ZZ 44 N 4 XX 89 Y 5 XX 45 N 6 YY 84 D 7 ZZ 22 S Output.txt COL1 COL2 COL3 COL4 COL5 1 XX 45 N 3 2 YY 34... (6 Replies)
Discussion started by: tech_frk
6 Replies

4. Shell Programming and Scripting

How can I search with start and end criteria?

Hello I'm using cygwin and wouldlike extract information from an xml file according specific values, but don't know how. Let's say in a file content looks like this: <tab> SURNAME=Mustermann NAME=Max CUSTOMER SINCE= 18.01.2000 ADDRESS=Birmingham ... (2 Replies)
Discussion started by: witchblade
2 Replies

5. Shell Programming and Scripting

Remove lines between the start string and end string including start and end string Python

Hi, I am trying to remove lines once a string is found till another string is found including the start string and end string. I want to basically grab all the lines starting with color (closing bracket). PS: The line after the closing bracket for color could be anything (currently 'more').... (1 Reply)
Discussion started by: Dabheeruz
1 Replies

6. Shell Programming and Scripting

Calculating start and end of UK summertime

I have a need to calculate when British Summer Time starts and ends. After messing around, the following seems to work in Bash. echo `date +%Y`-03-`cal 3 \`date +%Y\` | grep -oE "^]{2}" | tail -1`T01:00:00Zand echo `date +%Y`-03-`cal 10 \`date +%Y\` | grep -oE "^]{2}" | tail ... (10 Replies)
Discussion started by: esb4me
10 Replies

7. UNIX for Dummies Questions & Answers

How to start jobs manually from Crontab

Hello - I have about 7 jobs listed in my crontab. They run automatically everyday. However I am wondering how to start them manually? My system is SunOS 5.10 Jobs are listed in this fashion: 41 00 * * 1-5 /system/volms/.vbc/startmeup 01 44 * * 0-6 /system/volms/.vbc/kill (space)... (7 Replies)
Discussion started by: DallasT
7 Replies

8. Shell Programming and Scripting

can I specifiy the start and end times manually

Hi I have a ksh script which fetches data from a db using a number of .arc files and creates CSV files for them and puts them on the server. Question is, how can I specifiy the start and stop times specifically so that data is fetched for a certain period? # Get the current time as the... (1 Reply)
Discussion started by: shajju
1 Replies

9. Shell Programming and Scripting

searching between start and end time

Hello All, Below mentioned is my log file. I want to make a script which ask for start time and then end time and then search particular word between those lines. Like start time:2 end time: 4 and then search all values starting from cell 84 between this time. Please Help ... (2 Replies)
Discussion started by: wakhan
2 Replies

10. Shell Programming and Scripting

Start and End times of background processes

Hi I'm running 4 jobs in the background and I need to write the start and end times to a log file. I know there's probably a simple way to do this but, I can't think of it. I've used nohup <script name> & but, that doesn't record the times. Is there a way to get the start and end times of a... (2 Replies)
Discussion started by: stonemonolith
2 Replies
Login or Register to Ask a Question