PHP and Shell implementation check whether SAMBA and NFSServer exist

Source: Internet
Author: User
This article mainly introduces PHP and Shell implementation to check whether SAMBA and NFSServer exist. This article provides PHP check scripts and Shell check scripts respectively. If you need them, refer

This article mainly introduces PHP and Shell implementation to check whether SAMBA and NFS Server exist. This article provides PHP check scripts and Shell check scripts respectively. For more information, see

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;
}

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.