Bash 스크립트의 출력을 HTML로 생성

Bash 스크립트의 출력을 HTML로 생성

스크립트 출력을 HTML 형식으로 변환하는 스크립트를 만들고 싶습니다.

내 스크립트의 샘플 출력은 다음과 같습니다.

[root@test tmp]# cat StoreOnceStatus.txt
spawn ssh -o StrictHostKeyChecking=no [email protected]
Password:
Last login: Fri Jan 27 14:44:50 2017 from 10.x.x.x

Welcome to the HP StoreOnce Backup System Command Line Interface.
Type 'help' at the prompt for context-sensitive help.

> serviceset show status

Service Set 1         Status
-------------         -------
Overall             : Running
StoreOnce Subsystem : Running
Virtual Tape        : Running
NAS                 : Running
StoreOnce Catalyst  : Running
Replication         : Running
Housekeeping        : Running


>
> hardware show status

Name                  Dev-id                                Status
--------------------  ------------------------------------  ------
HP                    300000000-00000-0000-0000-0000         OK
p0000 Storage System  0000-0000-1000-b0000-50000             OK

>
> exit


Connection to 10.x.x.x closed.

이 파일에서 명령 serviceset show statushardware show status.

답변1

원하는 형식을 취하는 template.html 파일을 만들 수 있습니다. 실제 값 대신 나중에 스크립트를 통해 수집된 실제 값으로 대체될 일부 표현식(예: SERVICESETSTATUS, HARDWARESTATUS...)으로 채울 수 있습니다.

스크립트에서 sed 명령을 사용하여 템플릿의 표현식을 출력 명령으로 바꿀 수 있습니다.

sed "s/expression/$(command)/" template.html

또는 귀하의 경우:

sed "s/SERVICESETSTATUS/$(serviceset show status)/" template.html

나는 몇 년 전에 위키 페이지를 만들 때 비슷한 것을 사용했습니다.

관련 정보