LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How to create a batch file? (https://www.linuxquestions.org/questions/programming-9/how-to-create-a-batch-file-322960/)

Franziss 05-12-2005 10:11 PM

How to create a batch file?
 
I'm running in Linux, I got a C program which take in a file to do something and the executing time is supposed to be recorded in another file. Right now I have 50 files which the C program need to take in and record their time.

May I know how do I go about doing this? Thanks....

Matir 05-12-2005 10:24 PM

You can time the execution of a program using the 'time' utility. Good luck!

Franziss 05-12-2005 10:39 PM

Thanks for your reply!

But how do I execute them in batches and record the time taken of each file in a RESULT FILE? I'm searching for info on the net now, is it using shell scripting?

Matir 05-12-2005 10:42 PM

It can be done with shell scripting. What is the command you need to execute and time?

You can just use a basic loop, output redirection, etc.

Franziss 05-12-2005 11:00 PM

This is how my shell scripting pseudo flows:

FOR i = 1 to 50
Write current time to file RESULT
Run my C program. The command is "./cb DNA1" // DNA1 is the file that is read in by C program cb, so there is DNA1 to DNA50
Write DNA1 to file RESULT
Write current time to file RESULT // so for each loop, i will use the start and stop time to get the actual writing time.

Because I am new to shell scripting, can you help me in the code?

Thanks for your kind help! I really appreciate it! =)

Matir 05-13-2005 12:46 AM

Roughly speaking, this should work for you:

Code:

#!/bin/bash
i=1
while [ "$i" -le "50" ]
    do date >>RESULT
    ./cb DNA$i
    echo "Processed DNA$i" >>RESULT
    date >>RESULT
    let i=$i+1
done

This will print the current 'date' output surrounding the line "Processed DNAX" where X is the number from 1 to 50.

Franziss 05-13-2005 01:01 AM

Whoa! You're GOOD! Thanks man!

Do you know is there any way to obtain the difference in time? E.g. date2 - date1? The completion time minus the starting time?

Matir 05-13-2005 08:44 AM

Well, you cam get the number of seconds like so:
Code:

START=`date +%s`
./cb DNA$i
END=`date +%s`
let TIME=$END-$START

$TIME will then contain the number of seconds it took.

Franziss 05-16-2005 12:36 AM

Thanks for your help again! I really appreciate it! :) :D ;)


All times are GMT -5. The time now is 08:17 AM.