LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-12-2005, 10:11 PM   #1
Franziss
Member
 
Registered: Dec 2004
Posts: 35

Rep: Reputation: 15
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....
 
Old 05-12-2005, 10:24 PM   #2
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 128Reputation: 128
You can time the execution of a program using the 'time' utility. Good luck!
 
Old 05-12-2005, 10:39 PM   #3
Franziss
Member
 
Registered: Dec 2004
Posts: 35

Original Poster
Rep: Reputation: 15
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?
 
Old 05-12-2005, 10:42 PM   #4
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 128Reputation: 128
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.
 
Old 05-12-2005, 11:00 PM   #5
Franziss
Member
 
Registered: Dec 2004
Posts: 35

Original Poster
Rep: Reputation: 15
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! =)
 
Old 05-13-2005, 12:46 AM   #6
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 128Reputation: 128
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.

Last edited by Matir; 05-13-2005 at 12:49 AM.
 
Old 05-13-2005, 01:01 AM   #7
Franziss
Member
 
Registered: Dec 2004
Posts: 35

Original Poster
Rep: Reputation: 15
Thumbs up

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?
 
Old 05-13-2005, 08:44 AM   #8
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 128Reputation: 128
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.
 
Old 05-16-2005, 12:36 AM   #9
Franziss
Member
 
Registered: Dec 2004
Posts: 35

Original Poster
Rep: Reputation: 15
Thumbs up

Thanks for your help again! I really appreciate it!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to create batch file? TigerLinux Linux - Newbie 16 09-26-2011 12:24 PM
Sftp using a batch file JeRrYmAn Linux - Security 2 05-05-2006 10:15 AM
batch file for chmod's? teodavinci Linux - Networking 1 08-13-2004 02:39 PM
writing a batch file ???? Micro Linux - General 3 01-09-2003 11:04 AM
Bigslack Batch File Mal Slackware 1 07-03-2002 10:32 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:39 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration