Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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 nothingI 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

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

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

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

![]() |
![]() |
![]() |

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