# CIFS file system check.

**URL:** https://community.unix.com/t/cifs-file-system-check/270387
**Category:** Shell Programming and Scripting
**Created:** [July 28, 2010, 2:42am UTC](https://community.unix.com/t/cifs-file-system-check/270387 "2010-07-28T02:42:18Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![pinga123](https://community.unix.com/letter_avatar/pinga123/32/5_5575768a8748004e209b776fc1b2916d.png) [@pinga123](https://community.unix.com/u/pinga123)
#### Post date: [July 28, 2010, 2:42am UTC](https://community.unix.com/t/cifs-file-system-check/270387/1 "2010-07-28T02:42:18Z")

</div>

I have written a script to take backup of linux data on window's shared folder.  
I have used following method in my script.

```nohighlight
 mount -t cifs <windowshare> -o username=username,password=myPassword <mountlocation>

```

However most of linux system doesnt support CIFS filesystem.  
How would i check if CIFS filesystem or service is present or not before executing the script?

---

<div class="post-metadata">

### Author: ![dr.house](https://community.unix.com/letter_avatar/dr.house/32/5_5575768a8748004e209b776fc1b2916d.png) [@dr.house](https://community.unix.com/u/dr.house)
#### Post date: [July 28, 2010, 2:57am UTC](https://community.unix.com/t/cifs-file-system-check/270387/2 "2010-07-28T02:57:38Z")

</div>

You may want to check the results of a faked mount, e.g.:

```nohighlight
[root@leonov] mount -f -a; RV=$?; echo "Return Value: $RV"
Return Value: 0
[root@leonov] mount -f crap; RV=$?; echo "Return Value: $RV"
mount: can't find crap in /etc/fstab or /etc/mtab
Return Value: 1
[root@leonov] mount -f crap 2>/dev/null; RV=$?; echo "Return Value: $RV"
Return Value: 1

```

---

<div class="post-metadata">

### Author: ![pinga123](https://community.unix.com/letter_avatar/pinga123/32/5_5575768a8748004e209b776fc1b2916d.png) [@pinga123](https://community.unix.com/u/pinga123)
#### Post date: [July 28, 2010, 3:07am UTC](https://community.unix.com/t/cifs-file-system-check/270387/3 "2010-07-28T03:07:26Z")

</div>

> [@dr.house](#):
>
> You may want to check the results of a faked mount, e.g.:
> 
> ```plaintext
> [root@leonov] mount -f -a; RV=$?; echo "Return Value: $RV"
> Return Value: 0
> [root@leonov] mount -f crap; RV=$?; echo "Return Value: $RV"
> mount: can't find crap in /etc/fstab or /etc/mtab
> Return Value: 1
> [root@leonov] mount -f crap 2>/dev/null; RV=$?; echo "Return Value: $RV"
> Return Value: 1
> 
> ```

I have tried as u suggested but not getting what was desired.  
for example

```plaintext
# mount -f cifs
mount: can't find cifs in /etc/fstab or /etc/mtab
[root@TomcatServer ntserver]# echo $?
1

```

However i can sucessfully mount the share using cifs on same machine.

```plaintext
mount -t cifs //10.180.8.23/downloads -o username=username,password=password /mnt/ntserver

```

---

<div class="post-metadata">

### Author: ![dr.house](https://community.unix.com/letter_avatar/dr.house/32/5_5575768a8748004e209b776fc1b2916d.png) [@dr.house](https://community.unix.com/u/dr.house)
#### Post date: [July 28, 2010, 5:58am UTC](https://community.unix.com/t/cifs-file-system-check/270387/4 "2010-07-28T05:58:24Z")

</div>

> [@pinga123](#):
>
> ```plaintext
> mount -t cifs //10.180.8.23/downloads -o username=username,password=password /mnt/ntserver
> 
> ```

```plaintext
mount -f -t cifs //10.180.8.23/downloads -o username=username,password=password; echo "$?"

```

---

<div class="post-metadata">

### Author: ![pinga123](https://community.unix.com/letter_avatar/pinga123/32/5_5575768a8748004e209b776fc1b2916d.png) [@pinga123](https://community.unix.com/u/pinga123)
#### Post date: [July 28, 2010, 11:28pm UTC](https://community.unix.com/t/cifs-file-system-check/270387/5 "2010-07-28T23:28:04Z")

</div>

I will prefer to use following code.

```nohighlight
HAVE_CIFS=no
grep -q cifs /proc/filesystems && HAVE_CIFS=yes
/sbin/modinfo cifs &>/dev/null && HAVE_CIFS=yes

if ["x$HAVE_CIFS" = "xyes"]; then
  ...
fi

```

---

<div class="post-metadata">

### Author: ![alister](https://community.unix.com/letter_avatar/alister/32/5_5575768a8748004e209b776fc1b2916d.png) [@alister](https://community.unix.com/u/alister)
#### Post date: [July 29, 2010, 1:53am UTC](https://community.unix.com/t/cifs-file-system-check/270387/6 "2010-07-29T01:53:31Z")

</div>

Why bother with a fake mount? Just go ahead and try to mount it for real. Before continuing with the script, check the exit status of the mount. If it succeeded, continue. If not, abort. You should be doing this anyway, as the mount could possibly fail for a different reason other than lack of cifs support.

---

<div class="post-metadata">

### Author: ![pinga123](https://community.unix.com/letter_avatar/pinga123/32/5_5575768a8748004e209b776fc1b2916d.png) [@pinga123](https://community.unix.com/u/pinga123)
#### Post date: [July 29, 2010, 3:36am UTC](https://community.unix.com/t/cifs-file-system-check/270387/7 "2010-07-29T03:36:41Z")

</div>

> [@alister](#):
>
> Why bother with a fake mount? Just go ahead and try to mount it for real. Before continuing with the script, check the exit status of the mount. If it succeeded, continue. If not, abort. You should be doing this anyway, as the mount could possibly fail for a different reason other than lack of cifs support.

That should be a different reason.

Because if i go as per your suggestion the problem is i may not be able to recognize if cifs file system is supported or not.

According to me first file system check followed by status check for actual statement should be done.

---

<div class="post-metadata">

### Author: ![pludi](https://community.unix.com/user_avatar/community.unix.com/pludi/32/1278_2.png) [@pludi](https://community.unix.com/u/pludi)
#### Post date: [July 29, 2010, 3:49am UTC](https://community.unix.com/t/cifs-file-system-check/270387/8 "2010-07-29T03:49:21Z")

</div>

If your kernel makes its configuration available via the /proc filesystem, you can use something like

```nohighlight
zcat /proc/config.gz | grep -qE 'CONFIG_CIFS=[ym]'

```

to check for CIFS support.
