PHP and Shell implementations check Samba and NFS server for _php tips

Source: Internet
Author: User

Usually through the/etc/fstab to handle the mount settings, and then use Mount-a to reconfirm the mount, preferably in the scheduling program used to mount the directory also perform a mount-a, mount directory in the disconnection is not automatically reply, mount-a Timeout actually quite a long time , especially when the server does not exist, it is a good idea to use the corresponding client to first confirm that the server exists.

The client that checks for NFS can be treated with showmount and installed on Ubuntu in the following way:

Copy Code code as follows:

sudo aptitude install Nfs-common

The client of SAMBA, however, uses smbclient, which is installed on Ubuntu as follows:
Copy Code code as follows:

sudo aptitude install smbclient

procedures for checking for NFS Server presence
Check in the Shell way
Copy Code code as follows:

# First confirm server presence with Client
/sbin/showmount 192.168.0.6 >/dev/null 2>&1
If ["j$"!= "J0"]; Then
echo "NFS Server is not exist"
Exit 1
Fi

# Re-confirm Mount
Mount-a >/dev/null 2>&1
If ["j$"!= "J0"]; Then
echo "NFS Server Mount Failed"
Exit 1;
Fi

Check in PHP mode
Copy Code code as follows:

/* First to confirm server presence by client * *
$state = Shell_exec ('/sbin/showmount 192.168.0.6 >/dev/null 2>&1; echo $? ');
if (Trim ($state)!= ' 0 ') {
echo "NFS Server is not exist";
Exit
}

/* Re-check mount * *
if (shell_exec (' mount-a 2>&1 ')) {
echo "NFS Server Mount Failed"
Exit
}

To check if the SAMBA Server exists

Check in the Shell way

Copy Code code as follows:

# First confirm server presence with Client
SMBCLIENT-NL//192.168.0.6 >/dev/null 2>&1
If ["j$"!= "J0"]; Then
echo "SAMBA Server is not exist"
Exit 1
Fi

# Re-confirm Mount
Mount-a >/dev/null 2>&1
If ["j$"!= "J0"]; Then
echo "SAMBA Server Mount Failed"
Exit 1;
Fi

Check in PHP mode
Copy Code code as follows:

/* First to confirm server presence by client * *
$state = Shell_exec (' smbclient-nl//192.168.0.6 >/dev/null 2>&1; echo $? ');
if (Trim ($state)!= ' 0 ') {
echo "SAMBA Server is not exist";
Exit
}

/* Re-check mount * *
if (shell_exec (' mount-a 2>&1 ')) {
echo "SAMBA Server Mount Failed"
Exit
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.