1

I want to create a bash script to enable all users to connect to wireless networks. Following the instructions on this page, I can set that and it works. However, I want to be able to do this more quickly by running a script.

I considered using sed like this

sudo sed -i "s/auth_admin_keep/yes/g" /usr/share/polkit-1/actions/org.freedesktop.NetworkManager.policy

but in this file, there are two instances of auth_admin_keep and I only want to replace the first one. I don't want the script to replace the second one even if I accidentally run the script twice.

  • 1
    Although you can use sed to replace only the first instance, if you run it a second time it would then replace the second. You will need to identify a more specific pattern for your substitution. – Panther Jun 09 '14 at 16:30

1 Answers1

1

WARNING: This answer is only for 12.04. The file in question could change in future releases, so don't try it in other Ubuntu versions.

I was able to find the answer to my problem thanks to this site. I need this for Ubuntu 12.04 and the line I need to change is line 695, so this command will get the job done no matter how many times I run it.

sudo sed -i "695s/auth_admin_keep/yes/g" /usr/share/polkit-1/actions/org.freedesktop.NetworkManager.policy
Anwar
  • 76,649
  • Thanks to which site? Also it is dangerous to change a line blindly without knowing what that is changing. The line can change in future ubuntu releases and even in updates. As in 16.04, that particular line has no such auth_admin_keep things – Anwar Nov 13 '16 at 18:15
  • You're absolutely right. I no longer have a need to do this so I haven't looked for better solutions. – HarlemSquirrel Nov 13 '16 at 18:19
  • Could you at least describe the block after change? – Anwar Nov 13 '16 at 19:06
  • I don't have a system running 12.04 anymore to find that line. Sorry. – HarlemSquirrel Nov 13 '16 at 22:01
  • I also changed my approach to solving this problem. http://askubuntu.com/q/244567/109540 – HarlemSquirrel Nov 13 '16 at 22:03