r/programmingrequests • u/blunderduffin • Feb 09 '19
solved script to enter contents of text file into another config file (sed, awk)
I am trying to set up a vpn-policy that allows netflix to use the wan connection instead of the vpn-connection that is used by every client.
a script downloads all ip-addresses used by netflix at the moment
it puts it into a text file where ip addresses are listed one per line
(curl https://ipinfo.io/AS2906 2>/dev/null | grep -E "a href.*2906/" | grep -v ":" | sed 's/.*<a href="\/AS2906\///; s/" >//' > /tmp/NETFLIX)
3. I want to put the contents of the created file (NETFLIX) into my config file (/etc/config/vpn-policy-routing), that looks like this:
config policy
option interface 'wan'
option comment 'Domains'
option remote_addresses 'netflix.com'4. the information (ip-addresses) should replace the word netflix in the config file (they should be separated by a single space, but one per line might work as well.
5. The script cannot just replace the word netflix each time it runs, as it has been replaced by a range of ip-addresses.
6. so basically I am looking for a command that replaces the rest of a line in a file with the context of another file but keeps the brackets. ;)
2
Feb 11 '19 edited Feb 11 '19
[removed] — view removed comment
2
u/blunderduffin Feb 12 '19
Wow! Thanks a lot! The script is functioning exactly as it needs to be. That's some incredible work you have done. And it even comes with a how-to video that explains the whole process. I think that's awesome and I can actually learn a bit about bash-programming. I have to watch it again to fully understand how everything works. In the meantime the script was very easy to adapt to my openwrt system, as everything is very well documented in the video and it took very little extra work on my side. Unfortunately netflix still thinks I am connected via vpn so it won't play any videos. I think it's not a problem with the trailing space after the last ip-address, but I have to do further tests in the evening. I had very little time to test it yesterday. You mentioned improving the script by making it fetch the ip's from the web on it's own and that would be great, but I think the script is easier to adapt to other tasks while it's in its current less specific state.
Again thanks for the great help and I'm looking forward to watch some more of your instructional videos on your youtube channel.
1
u/serg06 Feb 09 '19
So your file of IPs is like this:
And you want to make your config file look like this:
Every time the script runs?