Linux scripting

MYstIC G

Official Licensed Lump of Coal™ Distributor
Staff member
Moderator
FH Subscriber
Joined
Dec 22, 2003
Messages
12,362
Howdy peeps.

I've got Ubuntu netbook remix on the notebook because windows sucks.

No idea how to do any scripting so looking for some help.

Basically when the notebook logs me in having established a wireless connection I want it to map a samba drive (my music folder on my nas).

Basic idea was to run a script that pinged my nas, if it gets a positive response then run the mount script, if not don't bother.

Some resource pointers or help would be greatly appreciated! :D
 

Deebs

Chief Arsewipe
Staff member
Moderator
FH Subscriber
Joined
Dec 11, 1997
Messages
9,076,920
You can use init.d scripts or rc.local to call an additional script.

What are the commands you need to call to setup your share ??
 

MYstIC G

Official Licensed Lump of Coal™ Distributor
Staff member
Moderator
FH Subscriber
Joined
Dec 22, 2003
Messages
12,362
just a plain mount command, got that all sorted.

Code:
#!/bin/bash
HOSTS="cyberciti.biz theos.in router"

COUNT=4

for myHost in $HOSTS
do
  count=$(ping -c $COUNT $myHost | grep 'received' | awk -F',' '{ print $2 }' | awk '{ print $1 }')
  if [ $count -eq 0 ]; then
    # 100% failed 
    echo "Host : $myHost is down (ping failed) at $(date)"
  fi
done
Just found the above here: Simple Linux and UNIX system monitoring with ping command and scripts

Seems that will probably do the job with some tweaking.

What's the difference between init.d or rc.local fella?
 

Deebs

Chief Arsewipe
Staff member
Moderator
FH Subscriber
Joined
Dec 11, 1997
Messages
9,076,920
Well init.d you give the script a number and that dictates the order in which the script will be executed. If you look in /etc/init.d/rc.x directories you will see lots of scripts with a number after them. The lowest numbers get called first.

rc.local is called after all the init.d scripts have finished. So you could create a file with the contents above and then just add the filename to rc.local and job done. Ensure it has +x on it, ie executable.
 

MYstIC G

Official Licensed Lump of Coal™ Distributor
Staff member
Moderator
FH Subscriber
Joined
Dec 22, 2003
Messages
12,362
Cool, cheers fella.
 

MYstIC G

Official Licensed Lump of Coal™ Distributor
Staff member
Moderator
FH Subscriber
Joined
Dec 22, 2003
Messages
12,362
Finding the good stuff for Linux is a serious ball ache sometimes:

wicd - home
 

MYstIC G

Official Licensed Lump of Coal™ Distributor
Staff member
Moderator
FH Subscriber
Joined
Dec 22, 2003
Messages
12,362
No wonder people use windows.

Get it all sorted, want it to run a mount command and then POW "can only run as root".

In windows all it takes is map network drive and type in the path, then if it's not there later, it just doesn't work.

Arragh!
 

MYstIC G

Official Licensed Lump of Coal™ Distributor
Staff member
Moderator
FH Subscriber
Joined
Dec 22, 2003
Messages
12,362
No it's not. To do what I want I can use laptop-net, whereami, wicd or script it myself.

God forbid the built in "Network Manager" package that's been developing since 2004 would do this however... oh no.
 

TdC

Trem's hunky sex love muffin
Joined
Dec 20, 2003
Messages
30,801
I fail to understand your problem. I think linux has decided you are teh ghei.

so, you want something like (pseudocode)

if I can see my pron container,
make my pron accessible to me and,
stop fecking about unless,
I can not see my pron container,
wait a bit and repeat.

Frankly I am surprised that the file manager in Ubuntu can not do this for you (eg, network discovery, mounting of visible remote shares, etc. There are different sets of programs which should be able to do these kinds of things. Otherwise, surely something like sudo /sbin/mount -o soft <my pron host share> /home/rob/pron is within the capabilities of one such as yourself?
 

MYstIC G

Official Licensed Lump of Coal™ Distributor
Staff member
Moderator
FH Subscriber
Joined
Dec 22, 2003
Messages
12,362
No I want,

My laptop just connected to the WiFi at work, mount the work stuff on the work network
-or-
My laptop just connected to the WiFi at home, mount the goat pr0n and the music directory
-else-
Do nothing.
 

MYstIC G

Official Licensed Lump of Coal™ Distributor
Staff member
Moderator
FH Subscriber
Joined
Dec 22, 2003
Messages
12,362
PS: I know the mount command! :eek:
 

TdC

Trem's hunky sex love muffin
Joined
Dec 20, 2003
Messages
30,801
well as you have not managed to get it working I have taken a pretty dim view of your expertise ;)
 

MYstIC G

Official Licensed Lump of Coal™ Distributor
Staff member
Moderator
FH Subscriber
Joined
Dec 22, 2003
Messages
12,362
Good! :eek:
 

MYstIC G

Official Licensed Lump of Coal™ Distributor
Staff member
Moderator
FH Subscriber
Joined
Dec 22, 2003
Messages
12,362
Ok smart arses, does either of you have a linux laptop that does what I'm trying to get working? :p
 

Deebs

Chief Arsewipe
Staff member
Moderator
FH Subscriber
Joined
Dec 11, 1997
Messages
9,076,920
Nope :) I use Linux for my firewall and backups of FH.
 

MYstIC G

Official Licensed Lump of Coal™ Distributor
Staff member
Moderator
FH Subscriber
Joined
Dec 22, 2003
Messages
12,362
Go on then...
 

TdC

Trem's hunky sex love muffin
Joined
Dec 20, 2003
Messages
30,801
so...you admit your fail? you want my help? you know you'll never hear the end of it ;)
 

MYstIC G

Official Licensed Lump of Coal™ Distributor
Staff member
Moderator
FH Subscriber
Joined
Dec 22, 2003
Messages
12,362
I admit nothing, I put you to strict proof that you can do what you say, on pain of "HA HA HA, YOU SUCK!" taunts if you do not! :eek:
 

MYstIC G

Official Licensed Lump of Coal™ Distributor
Staff member
Moderator
FH Subscriber
Joined
Dec 22, 2003
Messages
12,362
For what it's worth, the script I linked to last actually seems to work. It handily wrote a message in the log file saying so to prove it.

Now just need to get home so I can stick the details for my NAS in and hopefully (with finger crossing) all shall be well in Robville and shall continue to sucketh greatly in 3secondtdcville!
 

TdC

Trem's hunky sex love muffin
Joined
Dec 20, 2003
Messages
30,801
so you don't want my help? gaaaaaay tbh :p

tbh what I would do is use the mount command, because I am like that.

also, I can write you a script that writes ROB IS GAY to the message system as well as any other, and it will also mean nothing....or everything :)
 

Deebs

Chief Arsewipe
Staff member
Moderator
FH Subscriber
Joined
Dec 11, 1997
Messages
9,076,920
so you don't want my help? gaaaaaay tbh :p

tbh what I would do is use the mount command, because I am like that.

also, I can write you a script that writes ROB IS GAY to the message system as well as any other, and it will also mean nothing....or everything :)

To be fair Teedles, Mystic G AND Chetan (the hyperative scrote) are both gay for not visting Arnhem and Breda.

Seriously they need Windows for Dummies and not "A proper operating system for intelligent people" for Dummies.

Thank you.
 

TdC

Trem's hunky sex love muffin
Joined
Dec 20, 2003
Messages
30,801
that is true Deebs, and they will never live it down!


NEVAR!!!! :eek:
 

MYstIC G

Official Licensed Lump of Coal™ Distributor
Staff member
Moderator
FH Subscriber
Joined
Dec 22, 2003
Messages
12,362
To be fair Teedles, Mystic G AND Chetan (the hyperative scrote) are both gay for not visting Arnhem and Breda.

Seriously they need Windows for Dummies and not "A proper operating system for intelligent people" for Dummies.

Thank you.
Couldn't leave the family business' after how the year started so suck a fat one! :eek:

Additionally if anyone wants to try what I'm trying on linux on windows, it's a crapload easier because you just use netprofiles - Project Hosting on Google Code

Stupid netbook being too shitty to run XP.
 

Deebs

Chief Arsewipe
Staff member
Moderator
FH Subscriber
Joined
Dec 11, 1997
Messages
9,076,920
Post count spam.

+1 (and I hear Septic Peg moaning....)
 

Users who are viewing this thread

Top Bottom