Sure you can do that. Pseudo code:
ifconfig eth0 up blah bleh
if (! ping -c 1 some.host.thats.up)
ifconfig eth0 down
ifconfig eth1 up blah bleh
You might want to send more than on ping packet if there's a chance for packet loss. However, I don't know what the return code of ping on partial packet loss is. But it's probably still 0.
just reread your question:
Would it be possible to setup all eth devices and then try each for connection
I take it you want to assign a certain ip to whatever interface happens to be connected, right? One thing you have to be careful about is to not assign the same ip to two interfaces. This will lead to routing problems. Also assigning to different ips from the same network will lead to arp flux problems. So you need to deconfigure one interface before the other comes up.
Another possible solution (the proper albeit most difficult one) is to use ethernet bonding (see /usr/src/linux/Documentation/networking/bonding.txt)