bash loops

while counter

#!/bin/bash
#
SLEEPTIME=5
MAXCOUNT=5
URL="https://www.example.com/xys"
#
COUNTER=0
while [  $COUNTER -lt $MAXCOUNT ]; do
    let COUNTER=COUNTER+1
    echo "Iteration: $COUNTER
"
    curl -k $URL
    echo "
Status: $?
"
    # Don't execute for last iteration
    if [  $COUNTER -lt $MAXCOUNT ]; then
      sleep $SLEEPTIME
    fi
done

while file input

#!/bin/bash
#
HOSTFILE="hostdetails.txt"
# tail to remove header
cat $HOSTFILE | tail -n +2 | while read ServerName site os platform pvlan vlan ip subnet mask gateway nat
do
  echo "$ServerName - $ip"
  ping -c 1 $ip
done

QR Code
QR Code tech:linux:bash_loops (generated for current page)