Вам не нужен parallel
, поскольку тело цикла не зависит от предыдущего итераций. Просто запустите новый фоновый процесс для каждого хоста. Однако
while read host; do
sortstuff.sh -a "$host" > sortedstuff-"$host" &
done < live_hosts
wait # Optional, to block until the background tasks are done
parallel
действительно упрощает управление некоторыми аспектами; вы можете более легко ограничить количество параллельно выполняемых заданий.
Siempre puede implementar eltail -f
(bien aquí, a menos que elimine el comentario del seek()
, más como tail -n +1 -f
ya que estamos volcando todo el archivo )a mano con perl
por ejemplo:
perl -e '
$| = 1;
# seek STDIN, 0, 2; # uncomment if you want to skip the text that is
# already there. Or if using the ksh93 shell, add
# a <((EOF)) after < your-file
while (1) {
if ($_ = <STDIN>) {
print; $t = 0
} else {
print "\n" if $t == 3;
# and a line of "-"s after 10 seconds:
print "-" x 72. "\n" if $t == 10;
sleep 1;
$t++;
}
}' < your-file
O deje que tail -f
haga el seguimiento y use perl
para insertar las nuevas líneas si no hay entrada durante 3 segundos:
tail -f file | perl -pe 'BEGIN{$SIG{ALRM} = sub {print "\n"}} alarm 3'
Asumen que la salida en sí no se ralentiza (como cuando la salida va a una tubería que no se lee activamente ).
bash
+date
solución:
while IFS= read -r line; do
prev=$t # get previous timestamp value
t=$(date +%s) # get current timestamp value
[[ ! -z "$prev" ]] && [[ "$((t-prev))" -ge 3 ]] && echo ""
echo "$line" # print current line
done < <(tail -f error.log)
Python
solución (con argumento dinámico intervalo de tiempo ):
tailing_by_time.py
guión:
import time, sys
t_gap = int(sys.argv[1]) # time gap argument
ts = 0
while True:
line = sys.stdin.readline().strip() # get/read current line from stdin
curr_ts = time.time() # get current timestamp
if ts and curr_ts - ts >= t_gap:
print("") # print empty line/newline
ts = curr_ts
if line:
print(line) # print current line if it's not empty
Uso:
tail -f error.log | python tailing_by_time.py 3