Computing.Net > Forums > Linux > a script to check smb-share

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

a script to check smb-share

Reply to Message Icon

Name: Johanovitch
Date: April 20, 2003 at 12:35:28 Pacific
OS: SuSE 8.0
CPU/Ram: 366MHz/112MB
Comment:

Hello, I want to make a script that does the following:

- check if a certain smb-share is mounted
- if it's not mounted, mount the share (password need to be given)
- if the share is not available, do nothing

I want to run this script every hour.

Can anybody help me? I'm not yet so familiar with the samba-commands...

Does anybody know what happens if I shutdonw the computer from which the share is mounted, whithout unmounting the share on the server? Should I add something for this to the script to avoid problems?

Thanks in advance

Johan



Sponsored Link
Ads by Google

Response Number 1
Name: chris
Date: April 21, 2003 at 01:26:33 Pacific
Reply:

hi Johan

what you would like to do is a bit confusing :)
i think thats a way, wich could make you happy:
1. read the manuals about the automounter
2. read the examples form:
http://lists.olug.org/pipermail/olug/2002-December/001103.html
http://lists.samba.org/pipermail/smb-clients/2000-July/000037.html
3. just do it!

good luck!

chris



0

Response Number 2
Name: archangel
Date: April 21, 2003 at 02:23:30 Pacific
Reply:

The script for checking an mounting
-----------------
#!/bin/sh
# Find out the number of items in a directory,
# e.g. check if the share is mounted. If not
# mounted mount it.

# The command for mounting a samba share can be
# exemplified with the following command:
#
# #> mount -t smbfs -o username=foo,password=bar, \
# ip=192.168.0.3,uid=root,gid=root \
# //server/share /mnt/sambashare/
#

#--- Changable variables ---#
# MOUNTPOINT - is the directory where you wish
# to mount your share.
# SHARE - the sambashare
# IP - the ipaddress to the server
# USERNAME - the username on the server
# PASSWORD - the password on the server
# USERID - local username that will use the share, e.g.
# the share will be mounted for this user.
# GROUPID - the local user's group, e.g. the share will
# be mounted for this group.
MOUNTPOINT="/mnt/sambashare/";
SHARE="//server/share";
IP="123.456.789";
USERNAME="server_user";
PASSWORD="qwerty";
USERID="local_user";
GROUPID="local_user_group";

# ITEMS - the number of items in MOUNTPOINT, e.g.
# if ITEMS equals zero the MOUNTPOINT is
# empty, meaning that the share is not
# mounted.
ITEMS=`ls ${MOUNTPOINT} | wc -l`
if [ "${ITEMS}" -gt "0" ]; then
echo "Already mounted";
else
mount -t smbfs -o username=${USERNAME},password=${PASSWORD}, \
ip=${IP},uid=${USERID},gid=${GROUPID} ${SHARE} ${MOUNTPOINT}
echo "Share mounted";
fi
----------------

Then use crontab or kcron to make the script run every hour. Kcron is easier to use, and remember to make the script for root, since local users usually are not allowed to mount.

Good luck
//Jonas


0

Response Number 3
Name: Johanovitch
Date: April 21, 2003 at 10:38:23 Pacific
Reply:

Thanks for helping Jonas!
I seem to have a problem with the script though:
I made a file 'mountftp', made it executable and copied the script you gave me.
There seems to be a problem with the ITEMS:

--------------
p311:~ # ./mountftp
./mountftp: [: ls ${MOUNTPOINT} | wc -l: integer expression expected
INFO: Debug class all level = 3 (pid 22842 from pid 22842)
opts: ro
opts: username=johan
opts: password=mypassword
mount.smbfs started (version 2.2.3a)
added interface ip=192.168.0.1 bcast=192.168.0.255 nmask=255.255.255.0
resolve_lmhosts: Attempting lmhosts lookup for name johan
resolve_hosts: Attempting host lookup for name johan
resolve_wins: Attempting wins lookup for name johan
resolve_wins: WINS server ==
bind succeeded on port 0
Negative name query response, rcode 0x03: The name requested does not exist.
name_resolve_bcast: Attempting broadcast lookup for name johan
bind succeeded on port 0
Got a positive name query response from 192.168.0.2 ( 192.168.0.2 )
Connecting to 192.168.0.2 at port 139
Share mounted
--------------
The share is mounted, but If I run the script again, it gives the same, and not the "Already mounted".

any ideas?

Johan


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Linux Forum Home


Sponsored links

Ads by Google


Results for: a script to check smb-share

mount smb-share at ftp-login www.computing.net/answers/linux/mount-smbshare-at-ftplogin/23642.html

script problem www.computing.net/answers/linux/script-problem/19905.html

Shell scripting to get System Info. www.computing.net/answers/linux/shell-scripting-to-get-system-info/19972.html