简体   繁体   中英

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

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM