Que tal isso:
watch -n 1 "tail -n 1 /dev/ttyUSB0 > gpsout.tr"
Estou usando um GPS global G-STAR IV para meu projeto de redes ad hoc veicular. Neste, a saída nmea proveniente do GPS é atualizada a cada 1 segundo. Eu quero saber se existe uma maneira de salvar apenas a última linha em um arquivo externo e manter sobrescrevendo a linha naquele arquivo externo, como e quando o GPS envia sinais de dados.
A amostra de saída nmea do meu GPS é a seguinte.
$GPGSV,3,1,10,21,55,052,18,22,54,297,13,18,53,011,22,15,18,042,18*75
$GPGSV,3,2,10,14,43,184,,27,33,314,,29,21,152,,16,17,263,*7D
$GPGSV,3,3,10,24,10,092,,19,06,322,*79
$GPRMC,095827.000,A,2335.2440,N,05809.8432,E,0.55,103.38,091114,,,A*66
$GPGGA,095828.000,2335.2443,N,05809.8433,E,1,04,5.2,89.5,M,-34.7,M,,0000*46
$GPGSA,A,3,21,22,18,15,,,,,,,,,6.4,5.2,3.6*3C
$GPRMC,095828.000,A,2335.2443,N,05809.8433,E,1.21,102.44,091114,,,A*63
$GPGGA,095829.000,2335.2446,N,05809.8434,E,1,04,5.2,89.5,M,-34.7,M,,0000*45
$GPGSA,A,3,21,22,18,15,,,,,,,,,6.4,5.2,3.6*3C
$GPRMC,095829.000,A,2335.2446,N,05809.8434,E,0.92,102.44,091114,,,A*69
$GPGGA,095830.000,2335.2448,N,05809.8437,E,1,04,5.2,89.5,M,-34.7,M,,0000*40
$GPGSA,A,3,21,22,18,15,,,,,,,,,6.4,5.2,3.6*3C
$GPRMC,095830.000,A,2335.2448,N,05809.8437,E,1.25,102.12,091114,,,A*62
$GPGGA,095831.000,2335.2450,N,05809.8441,E,1,04,5.2,89.5,M,-34.7,M,,0000*49
$GPGSA,A,3,21,22,18,15,,,,,,,,,6.4,5.2,3.6*3C
$GPRMC,095831.000,A,2335.2450,N,05809.8441,E,1.47,101.80,091114,,,A*67
$GPGGA,095832.000,2335.2455,N,05809.8446,E,1,04,5.2,89.5,M,-34.7,M,,0000*48
$GPGSA,A,3,21,22,18,15,,,,,,,,,6.4,5.2,3.6*3C
$GPGSV,3,1,10,21,55,052,18,22,54,297,14,18,53,011,22,15,18,042,18*72
$GPGSV,3,2,10,14,43,184,,27,33,314,,29,21,152,,16,17,263,*7D
$GPGSV,3,3,10,24,10,092,,19,06,322,*79
$GPRMC,095832.000,A,2335.2455,N,05809.8446,E,2.36,100.07,091114,,,A*6D
$GPGGA,095833.000,2335.2459,N,05809.8450,E,1,04,5.2,89.5,M,-34.7,M,,0000*42
$GPGSA,A,3,21,22,18,15,,,,,,,,,6.4,5.2,3.6*3C
$GPRMC,095833.000,A,2335.2459,N,05809.8450,E,1.98,98.52,091114,,,A*50
$GPGGA,095834.000,2335.2458,N,05809.8454,E,1,04,5.2,89.5,M,-34.7,M,,0000*40
$GPGSA,A,3,21,22,18,15,,,,,,,,,6.4,5.2,3.6*3C
$GPRMC,095834.000,A,2335.2458,N,05809.8454,E,1.19,98.50,091114,,,A*59
$GPGGA,095835.000,2335.2450,N,05809.8457,E,1,04,5.2,89.6,M,-34.7,M,,0000*49
$GPGSA,A,3,21,22,18,15,,,,,,,,,6.4,5.2,3.6*3C
Atualmente estou salvando esta saída em um arquivo externo através do terminal no comando linux:
ima@ubuntu12:~$ sudo cat /dev/ttyUSB0 | tee gpsoutput.tr
Eu também tentei sudo cat /dev/ttyUSB0 | tee >(tail -n 1 > gpsout.tr)
, mas ele não é atualizado dinamicamente.
Mas, eu preciso de uma maneira de salvar apenas a última linha que vem do GPS para esse arquivo externo. isto é, ele sobrescreve o arquivo e substitui pela linha mais recente proveniente do GPS. Por favor ajude.. obrigado
Que tal isso:
watch -n 1 "tail -n 1 /dev/ttyUSB0 > gpsout.tr"