#!/bin/sh

# Hint: "ori" = ORIginal; "rb" = ReadBack; "res" = RESult; "err" = ERRor


# Make shure that result Directory exists
if [ ! -d /test/result ]
then
    mkdir /test/result
fi

# Make shure that result file of Test does NOT exists
if [ -s /test/result/eth0.res ]
then
    rm /test/result/eth0.res
fi

# Make shure that error file of Test does NOT exists
if [ -s /test/result/eth0.err ]
then
    rm /test/result/eth0.err
fi

# Ping Server in local network to make shure Ethernet Device works
# "-c 4": Send only 4 packages
# "-I eth0": Use Ethernet 0 as device
ping -c 4 -I eth0 192.168.1.2 1>> /test/result/eth0.res 2>> /test/result/eth0.err


# Display content of /test/result/usb2.res
echo -e "\n\rContent of eth0res"
cat /test/result/eth0.res

# Display content of /test/result/usb2.err
echo -e "\n\rContent of eth0.err"
cat /test/result/eth0.err

# Variable "$?" contains the ping result. 0 represents a successful ping. If ethernet device not available, error file will
# not be empty
if [  $? -eq 0  -a ! -s /test/result/eth0.err ]
then
    # Test was successful
    echo -e "\n\rETHERNET 0 TEST-PASSED"
    echo "ETHERNET 0 TEST-PASSED"  >> /test/result/eth0.res
else
    # Test failed
    echo -e "\n\rETHERNET 0 TEST-FAIL"
    echo "\n\rETHERNET 0 TEST-FAILED"  >> /test/result/eth0.res
fi 
