| Description: | The past few days I have been playing "High Availability" systems. So I had apache up and running and it worked, good. However on both machines each had its own copy of the web pages I was having it serve. So I was thinking why not have a 3rd machine be a fileserver and have the web pages be read over that. So here is a script I wrote to automatically do it for me. Now you can just use smbmount and it will "remount" the files if they are already there or throw an error if it can't find the server, but I through in the checks just for fun. |
| OS: | Linux/Unix |
| Requirements: | Bash, Samba (server and clients) |
Source Code:
# Check if the share is already mounted if [ $(mount | grep -c //server/sharename) -eq 1 ] then echo "Drive Already Mounted"; else # If its not already mounted "ping" the ip address (or name) of the server if ping -c 1 ip_address then # If you get a response from the server mount the share smbmount //server/sharename /localfolder -o username=SAMBA_USERNAME,password=SAMBA_PASSWORD,uid=500,gid=500 echo "Drive Mounted"; else # It cant find the server echo "Cannot Find Server!"; fi fi
Example:
if [ $(mount | grep -c //filserver/backups) -eq 1 ] then echo "Drive Already Mounted"; else # If its not already mounted "ping" the ip address (or name) of the server if ping -c 1 filserver then # If you get a response from the server mount the share smbmount //fileserver/backups /backups -o username=jeff,password=JeffRocksMySocks,uid=500,gid=500 echo "Drive Mounted"; else # It cant find the server echo "Cannot Find Server!"; fi fi