Home  >  Article  >  Backend Development  >  PHP and Shell implementation to check whether SAMBA and NFS Server exist, sambanfs_PHP tutorial

PHP and Shell implementation to check whether SAMBA and NFS Server exist, sambanfs_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:09:56942browse

PHP and Shell implementation check whether SAMBA and NFS Server exist, sambanfs

Usually, /etc/fstab is used to process the mounting settings, and then use mount -a to reconfirm the mounting. It is best to execute mount -a once when the scheduled program uses the mounting directory. The load directory will not automatically recover after being disconnected. The timeout of mount -a is actually quite long, especially when the server does not exist, so it is best to use the corresponding client to confirm whether the server exists.

The client that checks NFS can be handled with showmount. The installation method on Ubuntu is as follows:

Copy code The code is as follows:

sudo aptitude install nfs-common

SAMBA's client uses smbclient. The installation method on Ubuntu is as follows:
Copy code The code is as follows:

sudo aptitude install smbclient

Process of checking whether NFS Server exists
Check with Shell
Copy code The code is as follows:

# First use client to confirm whether 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
Copy code The code is as follows:

/*First use client to confirm whether 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;

 
/*Reconfirm the mount*/ 
if(shell_exec('mount -a 2>&1')){
echo "NFS Server mount failed"
exit;

Process of checking whether SAMBA Server exists

Check with Shell

Copy code The code is as follows:

# First use client to confirm whether 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
Copy code The code is as follows:

/*First use client to confirm whether 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;

 
/*Reconfirm the mount*/ 
if(shell_exec('mount -a 2>&1')){
echo "SAMBA Server mount failed"
exit;
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/939419.htmlTechArticlePHP and Shell implement checking whether SAMBA and NFS Server exist, sambanfs usually handles mounting through /etc/fstab settings, and then use mount -a to reconfirm the mount. It is best to schedule...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn