Reputation: 39
I don't have any idea how to wait for next line in file. Like I have file from which I give orders to script. actions are: start process, stop process, log active process and exit script.
while true
do
while read line
do
# do what ever it does
done < file
done
This is what I use to stay in file until exit. How can I hold and wait for next command line when it gets to the last line in file?
Upvotes: 1
Views: 1534
Reputation: 753695
Note that your existing code reads the file multiple times, which is not what you're really after.
You could use:
tail -f file |
while read line
do
# do what ever it does
done
The tail -f
command looks for the end of the file repeatedly. Of course, now you have two problems:
tail -f
to stop?The answer to Q1 is 'the interrupt key'.
The answer to Q2 is 'if there might be more than 10 lines in the file at start up, then add -n 1000000
or something similar to give you the last million lines of the file'. (Use a larger number if your file might contain more than a million lines.)
Upvotes: 4