Solved

Check samba connection

Posted on 2007-12-05
5
1,109 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
it is not really working. When I physically disconnect machines, the touch command hangs
0
 
LVL 40

Expert Comment

by:omarfarid
Comment Utility
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This is the error message I got (CODE) Error caused by incompatible libmp3lame 3.98-2 with ffmpeg I've googled this error message and found out sometimes it attaches this note "can be treated with downgrade libmp3lame to version 3.97 or 3.98" …
If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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.:

772 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

16 Experts available now in Live!

Get 1:1 Help Now