Bash Script Looping all the time


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash Script Looping all the time
# 1  
Old 12-13-2014
[Solved] Bash Script Looping all the time

Hello,

I have a database file, named data.txt, and a shell script (convert.sh) to convert data.txt from columns to row. Output file name will be column_to_row.txt
In this example data.txt has only four rows.

Format of data.txt is:
info name surname telefon_nr

Data.txt
Code:
info boris vian 0012345678
info kristaq skowronska 009876567
info emmanuel kant 00987654321

convert.sh
Code:
#!/bin/bash
while read -r COL1 COL2 COL3 COL4
sleep 2
do
echo "
[info_card]
name                          = "$COL2"
surname                      = "$COL3"
phone_nr                     = "$COL4" "
done < Data.txt
exit 0

To run convert.sh, i enter below command in terminal:

Code:
./convert.sh > column_to_row.txt

When I run it, script is not ending until i press ctrl+c. After processing four lines, it keeps running. How may I stop this script when all lines existing in data.txt file are processed ?


Many Thanks
Boris

Last edited by baris35; 12-13-2014 at 06:42 AM.. Reason: sorted, many thanks!
# 2  
Old 12-13-2014
Sleep 2 always has a return code 0; therefore the loop will run indefinitely...

The sleep 2 should be after the do
This User Gave Thanks to Scrutinizer For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Controlling time stamps in a bash script

Hi, I have a bash script that generates CSV (.txt) files at fairly regular time intervals. I'm currently time stamping each batch of measurements at the time I write the rows into a MySQL database. As the result, one set of data might get the time 12:01:32 and the next set of data gets the time... (18 Replies)
Discussion started by: Zooma
18 Replies

2. Shell Programming and Scripting

How to add missing date and time in a bash script?

Hi Again, I have a file that contains date and time for the past 2 hours. What i need is add missing date and time in a file. INPUT 2016-01-13 01:33 10 2016-01-13 01:31 10 2016-01-13 01:30 10 2016-01-13 01:29 10 2016-01-13 01:28 10 2016-01-13 01:27 10 2016-01-13 01:26 10 2016-01-13... (14 Replies)
Discussion started by: ernesto
14 Replies

3. Shell Programming and Scripting

Script in bash that works only some of the time

I ran this script yesterday (in the background) /usr/bin/nohup myfilelocation/myscriptname.sh & the script worked perfectly. i ran it today (also in the background) and just sat there. So i killed it and ran it normally and it worked perfectly. Anyone suggest why it just sat there and... (8 Replies)
Discussion started by: twinion
8 Replies

4. Shell Programming and Scripting

Need bash script to ping the servers and rename the output file each time the script is ran

HI, I have a file serverlist in that all host names are placed. i have written a small script #./testping #! /bin/bash for i in `cat serverlist` do ping $i >> output.txt done so now it creates a file output.txt till here fine.. now each time i run this script the output file... (4 Replies)
Discussion started by: madhudeva
4 Replies

5. Shell Programming and Scripting

Looping Bash Script

Does anyone have a same of a bash script that cd to a directory and execute a cgi script then moves onto the next directory then executes another cgi ? (3 Replies)
Discussion started by: Virusbot
3 Replies

6. Shell Programming and Scripting

How to compare time in bash script?

Hi, Anyone know how to compare the time in bash script? I want to compare say 30 min. to 45 min. ( AIX ) Thanks. (1 Reply)
Discussion started by: sumit30
1 Replies

7. Shell Programming and Scripting

execution time / runtime -- bash script please help!

Hello, I'm running a bash script and I'd like to get more accurate a runtime information then now. So far I've been using this method: STARTM=`date -u "+%s"` ......... *script function.... ......... STOPM=`date -u "+%s"` RUNTIMEM=`expr $STOPM - $STARTM` if (($RUNTIMEM>59)); then... (6 Replies)
Discussion started by: TehOne
6 Replies

8. Shell Programming and Scripting

bash script to count the time of transaction

Halo, Bash Script can get the time of process the trasaction or not? For example, bash script use to procee the trasaction, like select and checking.. then generate the XML. after it, i need to get the time which to count the process. Anyone can help me? Thank you (1 Reply)
Discussion started by: ryanW
1 Replies

9. Shell Programming and Scripting

looping in hexadecimal with bash

i want to write a script that creates a directory tree named in hexadecimal but i'm stuck at the hexadecimal part ... here is my code (incase i was dealing with intergers ...using bash) max=39 for((i=1;i<=max;i++)) do mkdir $i cd $i done i have tried using "typeset i16 i" but... (7 Replies)
Discussion started by: soba
7 Replies

10. UNIX for Dummies Questions & Answers

looping in hexadecimal with bash

hello every one this is my first post ... well i'm new to linux .... i've been enjoying shell scripting tutorials and i'm new to writting scripts i want to write a script that creates a directory tree named in hexadecimal but i'm stuck at the hexadecimal part ... here is my code (incase i... (2 Replies)
Discussion started by: soba
2 Replies
Login or Register to Ask a Question