#!/bin/bash
while read myHost
do
COUNT=100
SIZE=100
INTERVAL=0.2
IP=$(echo $myHost | cut -d " " -f1)
NAME=$(echo $myHost | cut -d " " -f2)
CUSTOMER=$(echo $myHost | cut -d " " -f3)
PING=$(ping -i $INTERVAL -q -n -s $SIZE -c $COUNT $IP | grep -i packet)
echo "IP of the device: $IP"
echo "Device name: $NAME"
echo "Customer name: $CUSTOMER"
echo "$PING"
echo ""
done < /files0/home/singhtr/input
This is one possible solution to your Problem. You can just use cut
to select the field
you want to output. And then output it with a simple echo
command.
To read in a file a single line at a time you can use
while read LINE
do
...
done < FILE
EDIT
If you want to run a script on a regular basis you should consider creating a cronjob
. You can type crontab -l
to see the cronjobs
of the current logged-in user. If you want to schedule a cronjob
you can do as follows:
$ crontab -e
edit the crontab by inserting for example:
*/15 * * * * /path/to/script >> /path/to/log_\`date +%s\` 2>&1
This will create a cronjob
that runs the script at the location /path/to/script
every 15 minutes and write it output + errors that might occur to file located at /path/to/log_
with a suffix of a unix time stamp (for example 1549883612).