Вопрос

How do I setup this log for accurate timing? I am trying to create log file using date '+%Y%m%d-%H:%M'. What is happening with my output is that the timestamp is the same.

RUN refresh proc          ===> 20130817-21:05
Waiting for pid:24638     ===> 20130817-21:05
Run parallel scripts      ===> 20130817-21:05
Waiting for pids: 24652   ===> 20130817-21:05
Waiting for pids: 24653   ===> 20130817-21:05
Waiting for pids: 24654   ===> 20130817-21:05
Waiting for pids: 24655   ===> 20130817-21:05
Running post process      ===> 20130817-21:05
Process Complete          ===> 20130817-21:05

I know time elapsed during this process. What am I doing wrong with creating my log? Here's my working script:

# Setup job
TIMESTAMP=`date '+%Y%m%d-%H:%M'`;
MYLOG=$BASEDIR/mvhistory.log
#Run Procedures
echo "====================================================" >> $MYLOG 2>&1
echo "RUN refresh proc ===> $TIMESTAMP" >> $MYLOG 2>&1
STAGING.sql &
pid0=$!
wait $pid0
echo "Waiting for pid:$pid0  ===> $TIMESTAMP" >> $MYLOG 2>&1
echo "Run parallel scripts   ===> $TIMESTAMP" >> $MYLOG 2>&1
1.sql &
pid1=$!
2.sql &
pid2=$!
3.sql &
pid3=$!
4.sql &
pid4=$!
wait $pid1 $pid2 $pid3 $pid4
echo "Waiting for pids: $pid1 ===> $TIMESTAMP" >> $MYLOG 2>&1
echo "Waiting for pids: $pid2 ===> $TIMESTAMP" >> $MYLOG 2>&1
echo "Waiting for pids: $pid3 ===> $TIMESTAMP" >> $MYLOG 2>&1
echo "Waiting for pids: $pid4 ===> $TIMESTAMP" >> $MYLOG 2>&1
echo "Running post process    ===> $TIMESTAMP" >> $MYLOG  2>&1
run_CLEAN.sql
echo "Process Complete        ===> $TIMESTAMP" >> $MYLOG  2>&1
exit 0
Это было полезно?

Решение

First of all, your TIMESTAMP value is never changed. A better way is to use a function to get the timestamp each time you display it.

getTimestamp() {
    echo `date '+%Y%m%d-%H:%M'`
}

echo "Waiting for pids: $pid1 ===> $(getTimestamp)" >> $MYLOG 2>&1

But the problem is that the lines are written into the log file at the same time (when all the proc are terminated), so the timestamp is the same. You probably need to do it without "wait", with a loop and check the process state for each pid.

Другие советы

i think it's because it's the same var. just change TIMESTAMP=date '+%Y%m%d-%H:%M' => TIMESTAMP=$(date '+%Y%m%d-%H:%M')

and it should work

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top