Linux scripting

MYstIC G

Official Licensed Lump of Coal™ Distributor
Staff member
Moderator
FH Subscriber
Joined
Dec 22, 2003
Messages
12,443
Spam all you like it's your bandwidth! :p
 

Jupitus

Old and short, no wonder I'm grumpy!
Staff member
Moderator
FH Subscriber
Joined
Dec 14, 2003
Messages
3,362
You done it yet, Meg? You n00b!
 

MYstIC G

Official Licensed Lump of Coal™ Distributor
Staff member
Moderator
FH Subscriber
Joined
Dec 22, 2003
Messages
12,443
I did it before Deebs postwhored yesterday!

HA!

PS: Next day and still no delivery Mr 3 seconds!
 

TdC

Trem's hunky sex love muffin
Joined
Dec 20, 2003
Messages
30,925
I thought you didn't want my help? Now you want my help? make up your mind!
 

MYstIC G

Official Licensed Lump of Coal™ Distributor
Staff member
Moderator
FH Subscriber
Joined
Dec 22, 2003
Messages
12,443
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! :eek:
 

Jupitus

Old and short, no wonder I'm grumpy!
Staff member
Moderator
FH Subscriber
Joined
Dec 14, 2003
Messages
3,362
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! :eek:

So, in other words, you failed and ripped it off instead. I understand now. :flame:
 

Jupitus

Old and short, no wonder I'm grumpy!
Staff member
Moderator
FH Subscriber
Joined
Dec 14, 2003
Messages
3,362
I thought you didn't want my help? Now you want my help? make up your mind!

Meg's sooooooo fickle! I spose that comes with being a woman.
 

MYstIC G

Official Licensed Lump of Coal™ Distributor
Staff member
Moderator
FH Subscriber
Joined
Dec 22, 2003
Messages
12,443
So, in other words, you failed and ripped it off instead. I understand now. :flame:
What's your point? Last I checked that's how Uncle Bill started M$ and got rich?
 

MYstIC G

Official Licensed Lump of Coal™ Distributor
Staff member
Moderator
FH Subscriber
Joined
Dec 22, 2003
Messages
12,443
This is true but it's better to be poor and not need TdC than to be poor and need TdC.
 

TdC

Trem's hunky sex love muffin
Joined
Dec 20, 2003
Messages
30,925
rob = needy bugger tbh. shall I make you a hot chocolate, dear?
 

MYstIC G

Official Licensed Lump of Coal™ Distributor
Staff member
Moderator
FH Subscriber
Joined
Dec 22, 2003
Messages
12,443
Pfft, you're just angry because I didn't have time to test your backup script and I've moved onto other linux type things! :eek:

Does it have marshmallows in it?
 

TdC

Trem's hunky sex love muffin
Joined
Dec 20, 2003
Messages
30,925
it's ok Susan, just let it out
 

MYstIC G

Official Licensed Lump of Coal™ Distributor
Staff member
Moderator
FH Subscriber
Joined
Dec 22, 2003
Messages
12,443
I'm sorry, Dave. I'm afraid I can't do that.
 

TdC

Trem's hunky sex love muffin
Joined
Dec 20, 2003
Messages
30,925
you want my marshmellows but refuse to comply with my other wishes! and you think you're still getting a free three-second script? I think not!

also, don't use the backup script, it's buggy as fuck! I can send you a new one if you want :)
 

TdC

Trem's hunky sex love muffin
Joined
Dec 20, 2003
Messages
30,925
hey Rob, what OS are your shares running on? I'm assuming it's windows?
am bored and making an automount script for a laugh :)
 

MYstIC G

Official Licensed Lump of Coal™ Distributor
Staff member
Moderator
FH Subscriber
Joined
Dec 22, 2003
Messages
12,443
Ubuntu fool! Plus there is a way better solution for windows earlier in the thread!
 

TdC

Trem's hunky sex love muffin
Joined
Dec 20, 2003
Messages
30,925
mmmkay I'll write both cifs and nfs into the script. maybe I'll have it try to autodetect it. much fun :D </nerd>
 

MYstIC G

Official Licensed Lump of Coal™ Distributor
Staff member
Moderator
FH Subscriber
Joined
Dec 22, 2003
Messages
12,443
*shrugs*

Hopefully it'll work as well as your backup script then :p
 

TdC

Trem's hunky sex love muffin
Joined
Dec 20, 2003
Messages
30,925
MY backup script works perfectly. The one I gave to you is quite flawed :D
 

TdC

Trem's hunky sex love muffin
Joined
Dec 20, 2003
Messages
30,925
this works for me:

Code:
#!/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

prolly a tonne of cockups in there lol
 

MYstIC G

Official Licensed Lump of Coal™ Distributor
Staff member
Moderator
FH Subscriber
Joined
Dec 22, 2003
Messages
12,443
I already edited my fstab file, ha ha :D
 

TdC

Trem's hunky sex love muffin
Joined
Dec 20, 2003
Messages
30,925
never the less, my script is awesome :p
 

Users who are viewing this thread

Top Bottom