PHP and Shell implementation check whether SAMBA and NFSServer exist. sambanfs_PHP tutorial

Source: Internet
Author: User
PHP and Shell checks whether SAMBA and NFSServer exist, sambanfs. PHP and Shell check whether SAMBA and NFSServer exist. sambanfs usually uses etcfstab to process the mounting settings, and then uses mount-a to re-confirm the mounting, it is best to check whether SAMBA and NFS Server exist in the scheduling PHP and Shell, sambanfs

The mount settings are usually handled through/etc/fstab, and then the mount-a is used to re-confirm the mount, it is best to execute mount-a when the mounting directory is used by the scheduling program. The mount directory will not be automatically replied after the disconnection. the Timeout of mount-a is actually quite long, especially when the Server does not exist, it is best to use the corresponding client to check whether the server exists.

The client that checks NFS can use showmount for processing. the installation method on Ubuntu is as follows:

The code is as follows:


Sudo aptitude install nfs-common


The SAMBA client uses smbclient. the installation method on Ubuntu is as follows:

The code is as follows:


Sudo aptitude install smbclient


Process for checking whether the NFS Server exists
Check in Shell mode

The code is as follows:


# Use the client to check whether the server exists
/Sbin/showmount 192.168.0.6>/dev/null 2> & 1
If ["j $? "! = "J0"]; then
Echo "NFS Server is not exist"
Exit 1
Fi

# Reconfirm mounting
Mount-a>/dev/null 2> & 1
If ["j $? "! = "J0"]; then
Echo "NFS Server mount failed"
Exit 1;
Fi


Check in PHP mode

The code is as follows:


/* Use the client to check whether the server exists */
$ 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-confirm mounting */
If (shell_exec ('Mount-a 2> & 1 ')){
Echo "NFS Server mount failed"
Exit;
}

Check the process of SAMBA Server

Check in Shell mode

The code is as follows:


# Use the client to check whether the server exists
Smbclient-NL // 192.168.0.6>/dev/null 2> & 1
If ["j $? "! = "J0"]; then
Echo "SAMBA Server is not exist"
Exit 1
Fi

# Reconfirm mounting
Mount-a>/dev/null 2> & 1
If ["j $? "! = "J0"]; then
Echo "SAMBA Server mount failed"
Exit 1;
Fi


Check in PHP mode

The code is as follows:


/* Use the client to check whether the server exists */
$ 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-confirm mounting */
If (shell_exec ('Mount-a 2> & 1 ')){
Echo "SAMBA Server mount failed"
Exit;
}

Whether the volume Server exists. sambanfs usually uses/etc/fstab to process the mounting settings, and then uses mount-a to re-confirm the mounting. it is best to schedule the mounting...

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.