Bloodyfisted
Bloodyfisted

Reputation: 11

Break lines in bash to HTML format

I'm having problems doing a break line between the IP addresses. They appear in 1 long horizontal line. I am able to do a break line on the first script, but it still appears in 1 line.

script #1 (showblock.sh)

command=$(pfctl -t bruteforce -T show)
my_array="${command[@]}"

for i in "${my_array[@]}"
do
   : 
   # do whatever on $i
   printf "%s\n" "${my_array[@]}"
done

script # 2 (showBlockOutput.sh)

#!/bin/sh
current_date=$(date)
output=$(showblock.sh)
OUT=oldBlocks/ipblock.html


cat << EOF > $OUT
<html>
<head>
  <meta http-equiv="refresh" content="30">
</head>
<body>
<h1>Blocked IPs</h1>
$current_date <br>
$output 
<br>
</body>
</html>
EOF

Upvotes: 1

Views: 448

Answers (1)

Barmar
Barmar

Reputation: 781954

You're not setting $command or $my_array to arrays. You can wrap the variable in () to split it into an array.

my_array=(${command})

And if you want these to be separate lines when the HTML is rendered, you need to put <br> between the lines, not newline.

There's no need for the for loop, printf will automatically loop when given more inputs than format operators.

printf "%s<br>\n" "${my_array[@]}"

The entire showblock.sh script can just be a one-liner:

#!/bin/bash
printf "%s<br>\n" $(pfctl -t bruteforce -T show)

Upvotes: 1

Related Questions