# Some script help please.

## truekaiser

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.

```

#!/bin/bash

connection=$(/sbin/iwgetid -r)

if [[ "$connection" == "Monolith" ]]; then

/etc/init.d/nfs start

else

echo "not at home"

fi

```

----------

## steveL

You probably want a case: 

```
#!/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.)

----------

## truekaiser

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.

```
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: 
> 
> ```
> #!/bin/sh
> 
> ...

 

----------

## pilla

It seems to be missing ;; after the statements:

```

case 'Monolithy' in 

Monolit*) echo ' hello' ;; 

*) echo 'world' ;; 

esac

```

----------

## truekaiser

 *pilla wrote:*   

> It seems to be missing ;; after the statements:
> 
> ```
> 
> case 'Monolithy' in 
> ...

 

that fixes it. Now to just get the damn thing to run when I need it too.

----------

## pilla

From the manual, you should drop your script in one of these directories in order to have it executed:

```

       /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.

----------

## truekaiser

 *pilla wrote:*   

> From the manual, you should drop your script in one of these directories in order to have it executed:
> 
> ```
> 
>        /etc/wicd/scripts/predisconnect
> ...

 

Close, I switched 'from' wicd to connman  :Razz:  I'm trying to figure out a system to replicate this feature from wicd.

----------

## pilla

 *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.

----------

## truekaiser

 *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?

----------

## pilla

Make your scripts execute as root using chmod +s. Of course, beware of security issues.

----------

## truekaiser

 *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.

----------

## pilla

 *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.

----------

## truekaiser

 *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.

----------

## Dr.Willy

 *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.

----------

