This is under Ubuntu 11.10
I have a script that starts a PPTP VPN connection fetches a couple of files, then closes the connection. When I run this script from a terminal prompt it works perfectly; however, when I schedule it to run with CRON the nmcli
commands in the script generate errors. The VPN connections are configured to be used by any user, not just my account.
Here is the relevant line of the script:
/usr/bin/nmcli con up id MyVPN
And here is the errors that generate when using it in CRON:
** (process:6360): WARNING **: _nm_object_get_property: Error getting 'WirelessHardwareEnabled' for /org/freedesktop/NetworkManager: (9) Rejected send message, 2 matched rules; type="method_call", sender=":1.624" (uid=1000 pid=6360 comm="/usr/bin/nmcli con up id MyVPN ") interface="org.freedesktop.DBus.Properties" member="Get" error name="(unset)" requested_reply="0" destination="org.freedesktop.NetworkManager" (uid=0 pid=1029 comm="NetworkManager ") ** (process:6360): WARNING **:
_nm_object_get_property: Error getting 'WwanHardwareEnabled' for /org/freedesktop/NetworkManager: (9) Rejected send message, 2 matched rules; type="method_call", sender=":1.624" (uid=1000 pid=6360 comm="/usr/bin/nmcli con up id MyVPN ") interface="org.freedesktop.DBus.Properties" member="Get" error name="(unset)" requested_reply="0" destination="org.freedesktop.NetworkManager" (uid=0 pid=1029 comm="NetworkManager ") ** (process:6360): WARNING **:
_nm_object_get_property: Error getting 'WimaxHardwareEnabled' for /org/freedesktop/NetworkManager: (9) Rejected send message, 2 matched rules; type="method_call", sender=":1.624" (uid=1000 pid=6360 comm="/usr/bin/nmcli con up id MyVPN ") interface="org.freedesktop.DBus.Properties" member="Get" error name="(unset)" requested_reply="0" destination="org.freedesktop.NetworkManager" (uid=0 pid=1029 comm="NetworkManager ") ** (process:6360): WARNING **:
_nm_object_get_property: Error getting 'State' for /org/freedesktop/NetworkManager: (9) Rejected send message, 2 matched rules; type="method_call", sender=":1.624" (uid=1000 pid=6360 comm="/usr/bin/nmcli con up id MyVPN ") interface="org.freedesktop.DBus.Properties" member="Get" error name="(unset)" requested_reply="0" destination="org.freedesktop.NetworkManager" (uid=0 pid=1029 comm="NetworkManager ")
Any ideas would be appreciated!
The reason while nmcli does not through cron is because the VPN details (username, password) reside in the account details of the user in the keyring. And nmcli requires DBus to retrieve the information.
That is, if you want to configure your system so that nmcli works, you need to get nmcli to work with the environment that CRON offers to the scripts.
See some examples at https://stackoverflow.com/questions/5819667/help-me-setup-a-cron-job-on-ubuntu and also at http://ubuntuforums.org/showpost.php?p=9016250&postcount=2 and https://wiki.archlinux.org/index.php/NetworkManager#Automatically_unlock_keyring_after_login
Just had a similar issue, and none of the above answers worked for me. I ended up simulating the problem with screen:
Add above line to cron, let it run once, turn it back off. Connect to your screen session (screen -r). If you are checking the screen session has been created (with
ps
) be aware that they are sometimes in capitals (e.g.ps | grep SCREEN
)Now
nmcli
and similar will fail.In particular, I noted that my problem was that
nmcli dev wifi
would execute just fine, butnmcli nm wifi on
wouldn't.The solution for me was quite simple in the end. I added a
sudo
. Only necessary in cron. Not sure why this fixed it.sudo su
beforecrontab -e
worked for me.