Linux Help
guides forums blogs
Home Desktops Distributions ISO Images Logos Newbies Reviews Software Support & Resources Linuxhelp Wiki

Welcome Guest ( Log In | Register )

Advanced DNS Management
New ZoneEdit. New Managment.


Sign Up Now
> loop port variable to connect to multiple computers
post May 8 2016, 10:51 AM
Post #1

Whats this Lie-nix Thing?

Group: Members
Posts: 8
Joined: 27-March 15
Member No.: 18,860

I have an SSH server that is used by client computers to create reverse SSH tunnels on. Each client computer is connected on a different port, and to connect from the SSH server on the client computer, that port is used.

I have a bash script that is supposed to connect on all the client computers, get some information and create an html report. My problem is that the script only connects on the first port in the list. It does not continue to process all the clients on the rest of the ports list.

Any ideas what could I be doing wrong?


function get_stats {
    local port=$1

    local cpu="$(ssh -o StrictHostKeyChecking=no user@localhost -p $port echo $[100-$(vmstat|tail -1|awk '{print $15}')]"%")"
    local dsk="$(ssh -o StrictHostKeyChecking=no user@localhost -p $port df -h /dev/mmcblk0p2 | awk 'NR>1{print $5}')"
    local mem="$(ssh -o StrictHostKeyChecking=no user@localhost -p $port free | grep -e-/+ | awk '{print $3/($3+$4) * 100.0 ''}' | cut -d '.' -f1)%"
    local tmp="$(ssh -o StrictHostKeyChecking=no user@localhost -p $port /opt/vc/bin/vcgencmd measure_temp | sed -e 's/temp=//')"
    local mda="$(ssh -o StrictHostKeyChecking=no user@localhost -p $port /bin/ls -R -l /user/media | /usr/bin/wc -l)"

    echo     '<tr>'
    echo         '<td>Client on port $port</td>'
    echo         "<td align="center">$cpu</td>"
    echo         "<td align="center">$dsk</td>"
    echo         "<td align="center">$mem</td>"
    echo         "<td align="center">$tmp</td>"
    echo         "<td align="center">$mda</td>"
    echo     '</tr>'

    echo '<html>'
    echo '<head>'
    echo '<title>Report</title>'
    echo '</head>'
    echo '<body>'
    echo '<table border="1" align="center">'
    echo     '<tr>'
    echo         '<td></td>'
    echo         '<td>CPU Usage</td>'
    echo         '<td>Disk Usage</td>'
    echo         '<td>Memory Usage</td>'
    echo         '<td>Temperature</td>'
    echo         '<td>Media Count</td>'
    echo     '</tr>'


while read port; do
    get_stats $port
done <$portfile

    echo '</table>'
    echo '</body>'
    echo '</html>'
Go to the top of the page
+Quote Post

Posts in this topic

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:


RSS Lo-Fi Version Time is now: 20th July 2018 - 05:33 PM