You are not logged in.

#1 2012-12-08 12:36:51

fantab
Member
From: 3rd Rock from the Sun
Registered: 2011-06-07
Posts: 152

[SOLVED] NetworkManager/dispatcher.d: Problem running a Script

I need to run a script to autologin into to my ISP. I put this script in /etc/NetworkManager/dispatcher.d and run it from there at every boot to autologing into my ISP.

I have fresh installed Arch-64-gnome (pure systemd). Now, the script is not working...

Here's the script /autologin.sh:

#!/bin/sh
if [ "$IFACE" = "eth0" ]; then
	curl -d "function=ExecuteLogin&user=USERNAME&pwd=PASSWORD&remember=false&timestamp=xxx9416xx902x" http://MyISP/Ajax.php
fi

However, when I remove the IFACE variable and just run

#!/bin/sh
curl -d "function=ExecuteLogin&user=USERNAME&pwd=PASSWORD&remember=false&timestamp=xxx9416xx902x" http://MyISP/Ajax.php

the script works and I am logged in automatically to my ISP.

I need the script to work with $IFACE variable or something other because I also use Wireless Broadband Modem for faster downloads and when I do so I disconnect my Eth0-wired. In order to reconnect to my Eth0 I have to either manually re-enter my ISP login info or restart. Also with IFACE variable I can manage the connection from the nm-applet by switching ON/OFF the "Wired".

Can the forum please take a look at the script and help me with it?

Last edited by fantab (2012-12-13 04:02:31)


"Evolution is the nature's way of issuing upgrades".
__________________________________________________________
Arch_x64-Gnome-Shell ~ Arch-lts_x64-Xfce ~ LMDE_x64-Cinnamon

Offline

#2 2012-12-08 12:58:29

65kid
Member
From: Germany
Registered: 2011-01-26
Posts: 663

Re: [SOLVED] NetworkManager/dispatcher.d: Problem running a Script

From the networkmanager man page:

Each script receives two arguments, the first being the interface name of the device just activated, and second an action.

... meaning you would have to set

IFACE=$1

Offline

#3 2012-12-08 13:17:34

fantab
Member
From: 3rd Rock from the Sun
Registered: 2011-06-07
Posts: 152

Re: [SOLVED] NetworkManager/dispatcher.d: Problem running a Script

65kid wrote:

From the networkmanager man page:

Each script receives two arguments, the first being the interface name of the device just activated, and second an action.

... meaning you would have to set

IFACE=$1

Thanks 65kid, but could you please explain some more as I not really good at writing scripts or at least guide me with links.


"Evolution is the nature's way of issuing upgrades".
__________________________________________________________
Arch_x64-Gnome-Shell ~ Arch-lts_x64-Xfce ~ LMDE_x64-Cinnamon

Offline

#4 2012-12-08 13:24:43

65kid
Member
From: Germany
Registered: 2011-01-26
Posts: 663

Re: [SOLVED] NetworkManager/dispatcher.d: Problem running a Script

the IFACE variable doesn't just set itself. The interface and the action are passed as parameters to your script (as the man page explains). This means that in your script $1 is the first parameter (= the interface) and $2 is the second parameter (= the action).
So if you set IFACE=$1, the IFACE variable will contain the interface. You might also want to set ACTION=$2 and then check if the action is actually "up" (I assume you don't want to execute the script when your interface is going "down").

Offline

#5 2012-12-09 04:04:23

fantab
Member
From: 3rd Rock from the Sun
Registered: 2011-06-07
Posts: 152

Re: [SOLVED] NetworkManager/dispatcher.d: Problem running a Script

Thanks again 65kid.

However I cannot translate the info you've provided into a script since I don't know anything about writing bash scripts. I would like to request to you and the forum to help me with it... Please. An example/sample of how the script should be will help me a lot. 

Thanks...

Last edited by fantab (2012-12-09 05:33:52)


"Evolution is the nature's way of issuing upgrades".
__________________________________________________________
Arch_x64-Gnome-Shell ~ Arch-lts_x64-Xfce ~ LMDE_x64-Cinnamon

Offline

#6 2012-12-10 07:14:06

fantab
Member
From: 3rd Rock from the Sun
Registered: 2011-06-07
Posts: 152

Re: [SOLVED] NetworkManager/dispatcher.d: Problem running a Script

Okay, I did some reading and looked at some examples on the net. (I am a noob at this).

Here is what I have come up with:

#!bin/sh
IFACE=$1
ACTION=$2

if [ "$1" = "eth0" ]; then
        if [ "$2" = "up" ]; then
curl -d "function=ExecuteLogin&username.............. http://...../Ajax.php
        fi
fi

I tested it and it is not working. I request the forum to PLEASE take a look at the above script I wrote and correct me whereever I am wrong.

Thanks


"Evolution is the nature's way of issuing upgrades".
__________________________________________________________
Arch_x64-Gnome-Shell ~ Arch-lts_x64-Xfce ~ LMDE_x64-Cinnamon

Offline

#7 2012-12-10 13:42:54

65kid
Member
From: Germany
Registered: 2011-01-26
Posts: 663

Re: [SOLVED] NetworkManager/dispatcher.d: Problem running a Script

- the first line must be #!/bin/sh not #!bin/sh
- why are you even setting IFACE and ACTION if you are using $1 and $2 in the if conditions? Either remove the IFACE and ACTION declaration or use them in the if conditions instead of $1 and $2.

Offline

#8 2012-12-11 05:43:28

fantab
Member
From: 3rd Rock from the Sun
Registered: 2011-06-07
Posts: 152

Re: [SOLVED] NetworkManager/dispatcher.d: Problem running a Script

65kid wrote:

- the first line must be #!/bin/sh not #!bin/sh
- why are you even setting IFACE and ACTION if you are using $1 and $2 in the if conditions? Either remove the IFACE and ACTION declaration or use them in the if conditions instead of $1 and $2.

Thanks a lot 65kid.

The first mistake you pointed out was a typo. I, however, corrected the second:

(a)

#!/bin/sh
IFACE=$1
ACTION=$2

if [ "$IFACE" = "eth0" ]; then
        if [ "$ACTION" = "up" ]; then
        curl -d "function=ExecuteLogin&username.............. http://...../Ajax.php
        fi
fi

OR...

(b)

#!/bin/sh
if [ "$1" = "eth0" ]; then
        if [ "$2" = "up" ]; then
        curl -d "function=ExecuteLogin&username.............. http://...../Ajax.php
        fi
fi

I request you to please take a look at 'em.

EDIT: I tested the (a) script and it is working. big_smile

Last edited by fantab (2012-12-11 08:26:42)


"Evolution is the nature's way of issuing upgrades".
__________________________________________________________
Arch_x64-Gnome-Shell ~ Arch-lts_x64-Xfce ~ LMDE_x64-Cinnamon

Offline

Board footer

Powered by FluxBB