I have 3 directories (/1 /2 and /3) with same contents and want to achieve fail over among them.
The Solution i thought of:
link /data to /1 (and provide users with /data to access)
CRON a script (to run every minute) to verify if /1 exist or not, if it does not exist (or its contents not available) then link /data to /2 (or /3 etc.)
But, i don't want to use this solution as it is not 100% perfect. i want to know if this can be done using OS (Linux/Solaris) in-built features itself?
I think you have a couple options. If the directories in question are mounted via network you can use one of a few highly available clustering methods to provide redundancy.
If local storage then under solaris 10 you could use ZFS to create a zpool using the directories in question as vdev members and configure the whole as a mirror or raidz.
Under linux if the directory content is located on separate partitions you could use
md or lvm to the same effect, but it's less straightforward.
The last option is some ad-hoc analog to your suggestion where you perform a check against 'sentinel' content or access to the directory and then perform
synchronization with your hot spares, or relink the directory to one of the hot spares if you need to fail over.
I'd think this last would be very expensive in terms of synchronization however.