
スクリプト出力を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 status
とhardware show status
。
答え1
必要な形式をとる template.html ファイルを作成できます。実際の値ではなく、後でスクリプトによって収集された実際の値に置き換えられるいくつかの式(SERVICESETSTATUS、HARDWARESTATUSなど)で埋めることができます。
スクリプトで sed コマンドを使用して、テンプレートの式を出力コマンドに置き換えることができます。
sed "s/expression/$(command)/" template.html
またはあなたの場合:
sed "s/SERVICESETSTATUS/$(serviceset show status)/" template.html
私は数年前にWikiページを作成するときに似たものを使用しました。