I didn't, still don't and won't need your help! I've done it (Read: That script I found works fine). You however are still under strict proof that you can do it!
I thought you didn't want my help? Now you want my help? make up your mind!
What's your point? Last I checked that's how Uncle Bill started M$ and got rich?So, in other words, you failed and ripped it off instead. I understand now.
What's your point? Last I checked that's how Uncle Bill started M$ and got rich?
#!/bin/bash
#####
# ${ME} v0.1 AUTOMOUNT script for MYstIC_G
#
# who is too lazy to put entries in the fstab
#
# by teedlecee, who enjoys writing idiocy like this
#####
# Usage:
#
# start this script as root and put it in the background
# /path/to/scriptname &
#####
# Purpose:
#
# the script will float in the background, checking to see if it
# can see a configured machine in either your work or play networks
# and if it can, it will try to mount a configured share for you.
# it will use a variable to determin if the server sharing is a
# smb or nfs server.
#
# note: with nfs I assume you're allowed to mount from the server.
# note: actually, I assume lots of things :-p
#
#####
# Variable explaination:
#
# DIR= the main directory under which your mounts will appear
# WORK= the hostname of the server in your work network
# WORKSHARE= what kind of share is it. accepts WIN | LIN for smb or nfs
# WORKUNC= network path win= //${WORK}/share lin= ${WORK}:/share
# WORKUSER= does your work server need a user?
# WORKPASS= does your work server need a password?
# PLAY= the hostname of the server in your play network
# PLAYSHARE= what kind of share is it. accepts WIN | LIN for smb or nfs
# PLAYUNC= network path win= //${PLAY}/share lin= ${PLAY}:/share
# PLAYUSER= does your play server need a user?
# PLAYPASS= does your play server need a password?
# PATH= internal path for the script. you shouldn't need to edit this
# QUIET= do you want the script to make noise?
# DEBUG= turn debug on. you shouldn't need to edit this
# INTERVAL= how long the script waits before polling. 30 seconds is ok
#####
# VARIABLES TO EDIT
DIR=/some/dir /mnt is a good choice
WORK=workhostname
WORKSHARE=WIN|LIN
WORKUNC=sharename
WORKUSER=user or blank
WORKPASS=pass or blank
PLAY=playhostname
PLAYSHARE=WIN|LIN
PLAYUNC=sharename
PLAYUSER=user or blank
PLAYPASS=pass or blank
# VARIABLES TO ONLY EDIT IF YOU KNOW WHAT YOU ARE DOING
PATH=/bin:/sbin:/usr/bin
QUIET=NO
#DEBUG="set -x"
INTERVAL=30
# VARIABLES TO >>>NOT<<< EDIT
ME=`basename $0`
OOPS=
CANSEE=
# MAIN DEBUG SWITCH
${DEBUG}
# FUNCTIONS
die()
{
${DEBUG}
if [ ${QUIET} = "YES" ]; then
exit 1
else
echo ""
echo "TdC failed miserably in function <$1>"
echo ""
if [ -n '${OOPS}' ]; then
echo "There was a meaningful message and it is:"
echo "${OOPS}"
echo ""
fi
exit 1
fi
}
sane()
{
${DEBUG}
for c in which sleep ping smbmount mount umount logger showmount basename
do
which $c > /dev/null 2>&1
if [ $? -ne 0 ]; then
OOPS="can\'t find $c ; edit PATH!"
die "sane"
fi
done
if [ ! -d ${DIR} ]; then
OOPS="directory ${DIR} does not exist ; edit DIR!"
die "sane"
fi
}
pingit()
{
${DEBUG}
ping $1 -c4 > /dev/null 2>&1
if [ $? -eq 0 ]; then
CANSEE=$1
fi
}
mountitwin()
{
${DEBUG}
smbmount $1 $2 -o user=$3,pass=$4
if [ $? -ne 0 ]; then
OOPS="the smbmount went horribly wrong ; turn on DEBUG and hope it tells you something meaningful"
die "mountit"
fi
}
mountitlin()
{
${DEBUG}
mount $1 $2 -o soft
if [ $? -ne 0 ]; then
OOPS="the nfsmount went horribly wrong ; turn on DEBUG and hope it tells you something meaningful"
die "mountit"
fi
}
rox()
{
${DEBUG}
x=$(( $RANDOM % 2 ))
y=$(( $RANDOM % 2 ))
let z=x+y
a=$(( $z % 2 ))
if [ $a -eq 0 ]; then
logger "rob herds cows"
else
logger "rob herds goats"
fi
}
ismounted()
{
${DEBUG}
mount | grep $1 > /dev/null 2>&1
if [ $? -eq 0 ]; then
continue
else
return 0
fi
}
killmount()
{
${DEBUG}
umount -f ${DIR}/${WORK} > /dev/null 2>&1
umount -f ${DIR}/${PLAY} > /dev/null 2>&1
rmdir ${DIR}/${WORK} > /dev/null 2>&1
rmdir ${DIR}/${PLAY} > /dev/null 2>&1
}
cleanup()
{
${DEBUG}
killmount
if [ ${QUIET} = "YES" ]; then
logger "${ME} exiting..."
exit 0
else
echo "${ME} exiting..."
logger "${ME} exiting..."
exit 0
fi
}
# MAIN
if [ $UID -ne 0 ]; then
echo "You are not root....noob :-P"
exit 1
fi
trap cleanup INT KILL TERM
sane
if [ ${QUIET} = "YES" ]; then
logger "${ME} starting..."
else
echo "${ME} starting..."
logger "${ME} starting..."
fi
killmount
while sleep ${INTERVAL}
do
for s in ${WORK} ${PLAY}
do
pingit $s
if [ -n ${CANSEE} ]; then
if [ "${CANSEE}" = "${WORK}" ]; then
ismounted ${WORK}
mkdir ${DIR}/${WORK}
if [ ! -d ${DIR}/${WORK} ]; then
OOPS="failed to create ${DIR}/${WORK} ; I suck...no...YOU SUCK :-P"
die "main"
fi
if [ ${WORKSHARE} = "WIN" ]; then
mountitwin ${WORKUNC} ${DIR}/${WORK} ${WORKUSER} ${WORKPASS}
fi
if [ ${WORKSHARE} = "LIN" ]; then
mountitlin ${WORKUNC} ${DIR}/${WORK}
fi
fi
if [ "${CANSEE}" = "${PLAY}" ]; then
ismounted ${PLAY}
mkdir ${DIR}/${PLAY}
if [ ! -d ${DIR}/${PLAY} ]; then
OOPS="failed to create ${DIR}/${PLAY} ; I suck...no...YOU SUCK :-P"
die "main"
fi
if [ ${PLAYSHARE} = "WIN" ]; then
mountitwin ${PLAYUNC} ${DIR}/${PLAY} ${PLAYUSER} ${PLAYPASS}
fi
if [ ${PLAYSHARE} = "LIN" ]; then
mountitlin ${PLAYUNC} ${DIR}/${PLAY}
fi
fi
fi
done
rox
done