Solved

Check samba connection

Posted on 2007-12-05
5
1,111 Views
Last Modified: 2013-12-16
Dear Experts,
I would like to write a script that checks if there is a connection and directory is really mounted (sometimes an entry it appears in /etc/mtab, but there is no connection in fact) This scripts will periodically (using cron) check if the mounted directory is still available.

I am mounting directory suing command (as root)

su - oracle -c "smbmount //192.168.3.1/BITEX_b /home/oracle/BITEX-backup -o username=oracle,password=oracle,rw"

What command should I use to check if SAMBA connection is still available?

Thanks for help

Groxy
0
Comment
Question by:adamgasior
  • 2
  • 2
5 Comments
 
LVL 40

Expert Comment

by:omarfarid
ID: 20418114
Hi,

Why don't you just create / delete a file in that mounted dir  and see if it succeeds or fails.

0
 
LVL 19

Accepted Solution

by:
alextoft earned 40 total points
ID: 20418599
Something quick and dirty like this perhaps?

#!/bin/bash
FILE="/home/oracle/BITEX-backup/a-file-on-your-remote-server
  if [ -f $FILE ];
    then
      echo Samba mount OK
    else
      umount -f /home/oracle/BITEX-backup
      su - oracle -c "smbmount //192.168.3.1/BITEX_b /home/oracle/BITEX-backup -o username=oracle,password=oracle,rw"
  fi


0
 
LVL 19

Expert Comment

by:alextoft
ID: 20418602
Hmm, it appears to have stripped the quotes round the echo statement when I posted, but you get what I mean...
0
 

Author Comment

by:adamgasior
ID: 20441415
it is not really working. When I physically disconnect machines, the touch command hangs
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 20441538
OK,

You may monitor the touch command while it is running in the the background

e.g.

touch /sambadir/file &
sleep 3
count=`ps -ef | grep -v grep | grep touch | wc -l`
if test $count -gt 0
then
      echo "not mounted"
      kill -9 `ps -ef | grep -v grep | grep touch | awk '{print $2}'`
else
      echo "mounted"
fi
0

Featured Post

Scale it in WD Gold

With up to ten times the workload capacity of desktop drives, WD Gold hard drives employ advanced technology to deliver among the best in reliability, capacity, power efficiency and performance.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
Fine Tune your automatic Updates for Ubuntu / Debian
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now