When a script is reading text file I would like this code to run specific command when it finds a specific string within a specific variable.
Example:
Let's say that I would like to use the following code to read the output of the command last
:
#!/bin/bash
for i in `last`; do
sleep 0.1 | echo -ne "$i "
done
The output of the command last
is a table in the form of a list of entries, something like:
username pts/2 1.2.3.4 via Sun Sep 2 06:40 - 06:40 (00:00)
. . . .
. . . .
The variable
i
in the previous code can be any phrase in the previous table. I would like to apply a specific command e. g. begin new line when the code finds a specific string within the variablei
, for example when the variablei
contains a closed parenthesis)
I want the code to begin a new line.When the code finishes reading the output of the command
last
, I want the code to repeat the for loop once again (multiple times) to read if there are any new updates. How can I direct the code to re-run again? For example, is there such a commandgoto
which will force the code to go to specific line?
Would you please advice?
(00:00)
or(12:05)
or ...etc-s
and save the current time? Also, the output of last is reverse chronological, so the additional runs would be all out of order.last
will be updated every time someonessh
a computer on network. i want to repeat for loop again and again and again and again and again and again and again and again and again and again and again and again and again and again and again and again and ……. etc. How can I do it? ;-)