I am having problem running a Script from /etc/NetworkManager/dispatcher.d. (I have openSuse13.1 Xfce 64bit).
The script is to login to my ISP; without the script I have to login via ‘java enabled’ browser.
I have checked the NetworkManager log. Earlier (couple of days ago when suse forum was not available) the log reported that the script did not have necessary permissions, or permission denied.
However, today the log does not have any entry regarding /dispatcher.d.
I still cannot run the script, which is in /etc/NetworkManager/dispatcher.d/autologinscript.
Here is the script:
#!/bin/sh
IFACE=$1
ACTION=$2
if "$IFACE" = "eth0" ]; then
if "$ACTION" = "up" ]; then
curl -d "function=ExecuteLogin&user=username&pwd=password&remember=false×tamp=xxx941xxx90xx" http://ISPurl/Ajax.php
fi
fi
I can login with my ISP when I run the ‘curl’ command from the Terminal.
The script as such is working in Arch Linux, which is also installed on the same PC.
Currently ‘root’ owns the said script file.
Any ideas what I am missing here? or whatever I am not doing correctly…
On 01/11/2014 08:46 PM, fantab wrote:
>
> I am having problem running a Script from
> /etc/NetworkManager/dispatcher.d. (I have openSuse13.1 Xfce 64bit).
> The script is to login to my ISP; without the script I have to login via
> ‘java enabled’ browser.
>
> I have checked the NetworkManager log. Earlier (couple of days ago when
> suse forum was not available) the log reported that the script did not
> have necessary permissions, or permission denied.
> However, today the log does not have any entry regarding /dispatcher.d.
>
> I still cannot run the script, which is in
> /etc/NetworkManager/dispatcher.d/autologinscript.
>
> Here is the script:
>
> Code:
> --------------------
> #!/bin/sh
> IFACE=$1
> ACTION=$2
>
> if “$IFACE” = “eth0” ]; then
> if “$ACTION” = “up” ]; then
> curl -d “function=ExecuteLogin&user=username&pwd=password&remember=false×tamp=xxx941xxx90xx” http://ISPurl/Ajax.php
> fi
> fi
>
> --------------------
>
>
> I can login with my ISP when I run the ‘curl’ command from the Terminal.
> The script as such is working in Arch Linux, which is also installed on
> the same PC.
>
> Currently ‘root’ owns the said script file.
>
> Any ideas what I am missing here? or whatever I am not doing
> correctly…
The first thing I see is that you should never assume the environment in a
script like this. It is possible that /usr/bin/ is not in the path. Always use a
full path for any command.
Secondly, on openSUSE, sh is also found in /usr/bin/. You should change the
shebang (first line).
Lastly, make sure that the execute bits are set in the script’s permissions.
You must use the place where the interpreter you want to use is.
When your script is a bash script, it is /bin/bash
When your script is a POSIX shell script, it is /usr/bin/sh
It is you that should know what scripting language you have written the script in.
And I found the correct places by using:
henk@boven:~> which bash
/bin/bash
henk@boven:~> which sh
/usr/bin/sh
henk@boven:~>
But in the POSIX shell case you can also use /bin/sh because that is a link
henk@boven:~> l /bin/sh
lrwxrwxrwx 1 root root 4 3 aug 17:29 /bin/sh -> bash*
henk@boven:~>
BTW. Do NOT jump to the conclusion that the link shows that sh is the same as bash. It is not. It is only handled by the same program, but that program knows how it is called (argument 0) and it will handle a script according to the definitions that belong to that call.
Thank you wolfi323, it rechecked the log and /sbin/ifconfig and it turns out that my Network Inferface is ‘enp0s25’ and not ‘eth0’. And I have edited it accordingly in my script.
Heres is an excerpt from /var/log/NetworkManager/dispatcher.d/myautologin after the above edit:
2014-01-13T07:19:06.913664+05:30 Echo NetworkManager[555]: <info> NetworkManager state is now CONNECTED_GLOBAL
2014-01-13T07:19:06.913939+05:30 Echo NetworkManager[555]: <info> Policy set 'Wired Connection 1' (enp0s25) as default for IPv4 routing and DNS.
2014-01-13T07:19:06.917313+05:30 Echo NetworkManager[555]: <info> Activation (enp0s25) successful, device activated.
2014-01-13T07:19:06.952976+05:30 Echo nm-dispatcher.action[6862]: % Total % Received % Xferd Average Speed Time Time Time Current
2014-01-13T07:19:06.953798+05:30 Echo nm-dispatcher.action[6862]: Dload Upload Total Spent Left Speed
2014-01-13T07:19:06.959510+05:30 Echo nm-dispatcher.action[6862]: 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0curl: (6)** Could not resolve host: portal.myISP/url/.com**
2014-01-13T07:19:06.960141+05:30 Echo nm-dispatcher.action: Script '/etc/NetworkManager/dispatcher.d/myautologin.sh' exited with error status 6.
2014-01-13T07:19:07.017085+05:30 Echo NetworkManager[555]: <warn> Dispatcher script failed: Script '/etc/NetworkManager/dispatcher.d/myautologin.sh' exited with error status 6.
However, when I copy-paste curl -d “function=ExecuteLogin&user=username&pwd=password&remember=false×tamp=xxx941xxx90xx” http://ISPurl/Ajax.php from the script in the terminal and run it directly, it fetches the required info and I am logged in…
I never did what you try to do and I only try to interprete what I read.
In fact the error says that it can not resolve portal.myISP to an IP address. That would mean that that host/domainname is not in your /etc/hosts. or can not be resolved using your DNS (can you reach a DNS server as long as your connection is not up???)
In, what you say is a copy/paste of the curl statement (but you failed to copy/paste between CODE tags for our benifit, which will make me detach from this thread the next time you fail to to so), I d not see such a host name. II do see an URL (if the blue also belongs to the red and both belong to what you should have shown between CODE tags, you realy make things difficult!) has a hostname ISPurl.
Both seem to be uncomplete domainnames (not ending in a top level domain I know of, but that is only me).
Now go figure???
The above command runs fine when run directly from the Terminal, however it does NOT from the “/myloginscript.sh”, as can be seen in the /log.
Same thing when I use ‘wget’ instead of ‘curl’.
Why can’t it "resolve host: portal.myISP/url/.com" when it can do so fine when the command is run from terminal?
@arvidjaar: I have tried the full curl command (/usr/bin/curl) as you suggested but that didn’t help.
My NetworkManager log still complains that the “host cannot be resolved”… but when I run the same ‘curl’ command directly from the Terminal, it works and connects.
Here’s the Script again:
#!/bin/sh
IFACE=$1
ACTION=$2
if "$IFACE" = "enp0s25" ]; then
if "$ACTION" = "up" ]; then
curl -d "function=ExecuteLogin&user=**************&pwd=**********&remember=false×tamp=***941***90****" http://portal.xxxxxxxx.com/newportal/Ajax.php
fi
fi
And following lines seem relevant from NetworkManager log:
2014-01-16T08:26:50.411956+05:30 Echo NetworkManager[561]: <info> NetworkManager state is now CONNECTED_GLOBAL
2014-01-16T08:26:50.412310+05:30 Echo NetworkManager[561]: <info> Policy set 'Beamtele' (enp0s25) as default for IPv4 routing and DNS.
2014-01-16T08:26:50.415792+05:30 Echo NetworkManager[561]: <info> Activation (enp0s25) successful, device activated.
2014-01-16T08:26:50.535687+05:30 Echo **nm-dispatcher.action**[1238]: % Total % Received % Xferd Average Speed Time Time Time Current
2014-01-16T08:26:50.536100+05:30 Echo** nm-dispatcher.action**[1238]: Dload Upload Total Spent Left Speed
2014-01-16T08:26:50.540145+05:30 Echo** nm-dispatcher.action**[1238]: 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0curl: (6) **Could not resolve host: portal.****xxxxxxxx.com**
2014-01-16T08:26:50.541101+05:30 Echo **nm-dispatcher.action**: **Script '/etc/NetworkManager/dispatcher.d/myautologin.sh' exited with error status 6.**
2014-01-16T08:26:50.906376+05:30 Echo NetworkManager[561]:** <warn> Dispatcher script failed: Script '/etc/NetworkManager/dispatcher.d/myautologin.sh' exited with error status 6.**
2014-01-16T08:27:02.933406+05:30 Echo NetworkManager[561]: <info> (enp0s25): IP6 addrconf timed out or failed.
I still can’t understand why the host CAN be “RESOLVED” when using the ‘curl’ command directly from the Terminal and NOT when the command is run from the ‘myautologin.sh’ script.
Any ideas what could be going on here?
If more info is needed then do let me know.
Probably because DNS is not yet properly setup by NetworkManager. Try adding “cat /etc/resolv.conf” to the very beginning of your script to check whether it is the right one.
Following your lead I checked my /etc/resolv.conf, and it turns out that the file was “autogenerated by the netconfig”, it had the default ‘nameserver’ from my ISP, whereas I am using NetworkManager and have set different DNS.
I edited the /etc/resolv.conf and changed the ‘nameserver’ to those that I had set in NetworkManager and the ‘script’ is working. :good: