LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   CIFS file system check. (https://www.linuxquestions.org/questions/linux-newbie-8/cifs-file-system-check-822560/)

pinga123 07-28-2010 01:44 AM

CIFS file system check.
 
I have written a script to take backup of linux data on window's shared folder.
I have used following method in my script.
Code:

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?

zirias 07-28-2010 01:56 AM

Hmm ;) your subject was a little misleading to me, I really thought you wanted to fsck a remote fs.

Well I think cifs is available on MOST linux systems, but it is often there as a module. You could check by the following procedure:

Code:

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

The first line checks whether cifs is currently available as filesystem, the second line checks whether the loadable kernel module is there -- in both cases, cifs will be usable on this box.

pinga123 07-28-2010 03:32 AM

Quote:

Originally Posted by zirias (Post 4047597)
Hmm ;) your subject was a little misleading to me, I really thought you wanted to fsck a remote fs.

Well I think cifs is available on MOST linux systems, but it is often there as a module. You could check by the following procedure:

Code:

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

The first line checks whether cifs is currently available as filesystem, the second line checks whether the loadable kernel module is there -- in both cases, cifs will be usable on this box.

above code doesnt help as when i checked with cisssfs which should not exists in /proc/filesystems ,i got wrong output.

Code:

# echo $HAVE_CIFS
yes
[root@TomcatServer /]# grep -q cisssfs /proc/filesystems && HAVE_CIFS=no
[root@TomcatServer /]# echo $HAVE_CIFS
yes


zirias 07-28-2010 03:34 AM

This is why HAVE_CIFS is set to "no" in the first line!

PS: Maybe read up a little on shell scripting: The command after && is ONLY executed when the command preceding it returned successful. The script WILL work like presented in my first post.

pinga123 07-28-2010 04:08 AM

Quote:

Originally Posted by zirias (Post 4047695)
This is why HAVE_CIFS is set to "no" in the first line!

PS: Maybe read up a little on shell scripting: The command after && is ONLY executed when the command preceding it returned successful. The script WILL work like presented in my first post.

thank for the information however i have one doubt in my mind.

what is the difference between
Code:

"x$HAVE_CIFS" = "xyes"
and
Code:

"$HAVE_CIFS" = "yes"

zirias 07-28-2010 04:41 AM

The first won't break with versions of "test" that don't deal with emtpy strings correctly. Although $HAVE_CIFS can't be empty in THIS script, I just ALWAYS use the "safe" version.

pinga123 07-28-2010 10:20 PM

Quote:

Originally Posted by zirias (Post 4047745)
The first won't break with versions of "test" that don't deal with emtpy strings correctly. Although $HAVE_CIFS can't be empty in THIS script, I just ALWAYS use the "safe" version.

Thanks for your helpful suggestion now onward i will always use the safe method.


All times are GMT -5. The time now is 04:21 PM.