#!/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/eth1.res ]
then
    rm /test/result/eth1.res
fi

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

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


# Display content of /test/result/eth2.res
echo -e "\n\rContent of eth1.res"
cat /test/result/eth1.res

# Display content of /test/result/eth2.err
echo -e "\n\rContent of eth1.err"
cat /test/result/eth1.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/eth1.err ]
then
    # Test was successful
    echo -e "\n\rETHERNET 1 TEST-PASSED"
    echo "ETHERNET 1 TEST-PASSED"  >> /test/result/eth1.res
else
    # Test failed
    echo -e "\n\rETHERNET 1 TEST-FAIL"
    echo "\n\rETHERNET 1 TEST-FAILED"  >> /test/result/eth1.res
fi 
