View previous topic :: View next topic |
Author |
Message |
truekaiser l33t
Joined: 05 Mar 2004 Posts: 801
|
Posted: Sun May 22, 2016 6:08 am Post subject: Some script help please. |
|
|
I had to switch to connman from wicd to mange my wireless connections. As a result I lost the ability to run scripts on a per essid basis.
I have tried running the following type of script both with connman's 'after connect' option. As well as trying to use /etc/local.d.
Here is the script, or at least the latest version.
Code: |
#!/bin/bash
connection=$(/sbin/iwgetid -r)
if [[ "$connection" == "Monolith" ]]; then
/etc/init.d/nfs start
else
echo "not at home"
fi
|
|
|
Back to top |
|
|
steveL Watchman
Joined: 13 Sep 2006 Posts: 5153 Location: The Peanut Gallery
|
Posted: Sun May 22, 2016 9:33 am Post subject: |
|
|
You probably want a case: Code: | #!/bin/sh
case $(/sbin/iwgetid -r) in
Monolith*) /etc/init.d/nfs start
*) echo 'Not at home' >&2
esac | What does the output of /sbin/iwgetid -r look like?
You may want *Monolith* as the first case, for example.
Then you can add other cases as you go.
#bash are your friends ;)
They teach POSIX sh too, if you specify that upfront.
In passing, the above situation is one of only two in shell that does need quoting of the expansion: directly after case, the shell must not field-split the word.
The other is assignment, as used in your original post (but not in local or other builtins.) |
|
Back to top |
|
|
truekaiser l33t
Joined: 05 Mar 2004 Posts: 801
|
Posted: Sun May 22, 2016 4:53 pm Post subject: |
|
|
From the man page iwgetid -r prints the raw name of the connected esid of the network you're connected to. In this case, my custom made AP Monolith
Tried your version of it and Bash spits out syntax errors.
Code: | line 4: syntax error near unexpected token ')'
line 4: '*) echo 'Not at home' >&2' |
What i am trying to accomplish is for the system to start services such as nfs and samba ONLY when I am on a specific network. Mainly my home one as I don't want those on when I am on a public network or tethered to my phone.
I think I may be running into permission problems though as possibly the 'after connect' may be running stuff as non root(which is smart) and I need stuff run as root..
Which means i may need to dabble with sudo.. Something i don't like using.
steveL wrote: | You probably want a case: Code: | #!/bin/sh
case $(/sbin/iwgetid -r) in
Monolith*) /etc/init.d/nfs start
*) echo 'Not at home' >&2
esac | What does the output of /sbin/iwgetid -r look like?
You may want *Monolith* as the first case, for example.
Then you can add other cases as you go.
#bash are your friends
They teach POSIX sh too, if you specify that upfront.
In passing, the above situation is one of only two in shell that does need quoting of the expansion: directly after case, the shell must not field-split the word.
The other is assignment, as used in your original post (but not in local or other builtins.) |
|
|
Back to top |
|
|
pilla Bodhisattva
Joined: 07 Aug 2002 Posts: 7729 Location: Underworld
|
Posted: Sun May 22, 2016 5:03 pm Post subject: |
|
|
It seems to be missing ;; after the statements:
Code: |
case 'Monolithy' in
Monolit*) echo ' hello' ;;
*) echo 'world' ;;
esac
|
_________________ "I'm just very selective about the reality I choose to accept." -- Calvin |
|
Back to top |
|
|
truekaiser l33t
Joined: 05 Mar 2004 Posts: 801
|
Posted: Sun May 22, 2016 5:11 pm Post subject: |
|
|
pilla wrote: | It seems to be missing ;; after the statements:
Code: |
case 'Monolithy' in
Monolit*) echo ' hello' ;;
*) echo 'world' ;;
esac
|
|
that fixes it. Now to just get the damn thing to run when I need it too. |
|
Back to top |
|
|
pilla Bodhisattva
Joined: 07 Aug 2002 Posts: 7729 Location: Underworld
|
Posted: Sun May 22, 2016 5:31 pm Post subject: |
|
|
From the manual, you should drop your script in one of these directories in order to have it executed:
Code: |
/etc/wicd/scripts/predisconnect
/etc/wicd/scripts/postdisconnect
/etc/wicd/scripts/preconnect
/etc/wicd/scripts/postconnect
|
I would bet on postconnect.
Moved from Gentoo Chat. _________________ "I'm just very selective about the reality I choose to accept." -- Calvin |
|
Back to top |
|
|
truekaiser l33t
Joined: 05 Mar 2004 Posts: 801
|
Posted: Sun May 22, 2016 5:33 pm Post subject: |
|
|
pilla wrote: | From the manual, you should drop your script in one of these directories in order to have it executed:
Code: |
/etc/wicd/scripts/predisconnect
/etc/wicd/scripts/postdisconnect
/etc/wicd/scripts/preconnect
/etc/wicd/scripts/postconnect
|
I would bet on postconnect.
Moved from Gentoo Chat. |
Close, I switched 'from' wicd to connman I'm trying to figure out a system to replicate this feature from wicd. |
|
Back to top |
|
|
pilla Bodhisattva
Joined: 07 Aug 2002 Posts: 7729 Location: Underworld
|
Posted: Sun May 22, 2016 5:46 pm Post subject: |
|
|
truekaiser wrote: |
Close, I switched 'from' wicd to connman I'm trying to figure out a system to replicate this feature from wicd. |
lol, my fault. I guess you need something like connman-dispatcher. _________________ "I'm just very selective about the reality I choose to accept." -- Calvin |
|
Back to top |
|
|
truekaiser l33t
Joined: 05 Mar 2004 Posts: 801
|
Posted: Sun May 22, 2016 7:10 pm Post subject: |
|
|
pilla wrote: | truekaiser wrote: |
Close, I switched 'from' wicd to connman I'm trying to figure out a system to replicate this feature from wicd. |
lol, my fault. I guess you need something like connman-dispatcher. |
That might work. I can't find any info if it can run init scripts? Or do i need to use sudo to get it the privileges to start init script services? |
|
Back to top |
|
|
pilla Bodhisattva
Joined: 07 Aug 2002 Posts: 7729 Location: Underworld
|
Posted: Sun May 22, 2016 7:59 pm Post subject: |
|
|
Make your scripts execute as root using chmod +s. Of course, beware of security issues. _________________ "I'm just very selective about the reality I choose to accept." -- Calvin |
|
Back to top |
|
|
truekaiser l33t
Joined: 05 Mar 2004 Posts: 801
|
Posted: Sun May 22, 2016 8:27 pm Post subject: |
|
|
pilla wrote: | Make your scripts execute as root using chmod +s. Of course, beware of security issues. |
I would imagine it would take local access to exploit that compared to leaving those services on regardless of the network. Thus allowing remote exploits. |
|
Back to top |
|
|
pilla Bodhisattva
Joined: 07 Aug 2002 Posts: 7729 Location: Underworld
|
Posted: Sun May 22, 2016 9:06 pm Post subject: |
|
|
truekaiser wrote: | pilla wrote: | Make your scripts execute as root using chmod +s. Of course, beware of security issues. |
I would imagine it would take local access to exploit that compared to leaving those services on regardless of the network. Thus allowing remote exploits. |
Indeed, it is a trade-off. _________________ "I'm just very selective about the reality I choose to accept." -- Calvin |
|
Back to top |
|
|
truekaiser l33t
Joined: 05 Mar 2004 Posts: 801
|
Posted: Sun May 22, 2016 9:11 pm Post subject: |
|
|
pilla wrote: | truekaiser wrote: | pilla wrote: | Make your scripts execute as root using chmod +s. Of course, beware of security issues. |
I would imagine it would take local access to exploit that compared to leaving those services on regardless of the network. Thus allowing remote exploits. |
Indeed, it is a trade-off. |
I'll take the local then. I keep my laptop pretty damn close to me at almost all times when I take it with me out of town. I am though paranoid about using public or hotel wifi though. |
|
Back to top |
|
|
Dr.Willy Guru
Joined: 15 Jul 2007 Posts: 547 Location: NRW, Germany
|
Posted: Mon May 23, 2016 5:13 pm Post subject: |
|
|
pilla wrote: | truekaiser wrote: |
Close, I switched 'from' wicd to connman I'm trying to figure out a system to replicate this feature from wicd. |
lol, my fault. I guess you need something like connman-dispatcher. |
Since connman depends on wpa_supplicant, 'wpa_cli -a' might work. |
|
Back to top |
|
|
|