• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1133
  • Last Modified:

Check samba connection

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
adamgasior
Asked:
adamgasior
  • 2
  • 2
1 Solution
 
omarfaridCommented:
Hi,

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

0
 
alextoftCommented:
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
 
alextoftCommented:
Hmm, it appears to have stripped the quotes round the echo statement when I posted, but you get what I mean...
0
 
adamgasiorAuthor Commented:
it is not really working. When I physically disconnect machines, the touch command hangs
0
 
omarfaridCommented:
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now