asiablock update script - help

Post new topic   Reply to topic    DD-WRT Forum Index -> Broadcom SoC based Hardware
Author Message
nitrocs
DD-WRT User


Joined: 21 Jul 2009
Posts: 59

PostPosted: Wed Jun 20, 2012 13:37    Post subject: asiablock update script - help Reply with quote
router - e3000
build - DD-WRT v24-sp2 (12/24/10) mega
SVN - 15962

I'm looking to automate my asiablock update w/ a CRON activated script. What I've cobbled together so far is:

Quote:

#!/bin/sh
#

logger "*-* ASIABLOCK UPDATE *-*"
wget -O /opt/etc/init.d/S95asiablock http://otrw.basmaf.com/S95asiablock_2010

sed -ie 's/kr ph/kr ph za co/g' /opt/etc/init.d/S95asiablock

rm /opt/etc/init.d/S95asiablocke

service asiablock on

service asiablock start


When I run w/ sh i get errors that the file is not found when it goes to wget & thus the script fails to do anything

what am I missing?
Sponsor
basmaf
DD-WRT Guru


Joined: 24 Feb 2011
Posts: 1074

PostPosted: Wed Jun 20, 2012 13:48    Post subject: Reply with quote
Delete this line
rm /opt/etc/init.d/S95asiablock

There is nothing to start when you remove the script after fetching it.

wget -O overwrites the current file.
nitrocs
DD-WRT User


Joined: 21 Jul 2009
Posts: 59

PostPosted: Wed Jun 20, 2012 17:05    Post subject: Reply with quote
re-read that line
its in there because the sed command seemingly creates a copy of the original...which I want removed

the issue is that the script cant find the file when issuing the wget command

is my syntax off?
basmaf
DD-WRT Guru


Joined: 24 Feb 2011
Posts: 1074

PostPosted: Wed Jun 20, 2012 17:25    Post subject: Reply with quote
Yes your off.

sed -i will edit the file 'in place'
Since you haven't defined a backup extension none will be created.

Just issue the commands one at a time and cat the file in between.

Code:
bas@lenovo:~$ cat /tmp/S95asiablock | grep 'kr '
ISO_spam="af cn in pk my kh li vn kr ph"
bas@lenovo:~$ sed -ie 's/kr ph/kr ph za co/g' /tmp/S95asiablock
bas@lenovo:~$ cat /tmp/S95asiablock | grep 'kr '
ISO_spam="af cn in pk my kh li vn kr ph za co"
bas@lenovo:~$


Use it like this..
Code:
#!/bin/sh
service asiablock stop
service asiablock off

logger "*-* ASIABLOCK UPDATE *-*"
wget -O /opt/etc/init.d/S95asiablock http://otrw.basmaf.com/S95asiablock_2010
sed -ie 's/kr ph/kr ph za co/g' /opt/etc/init.d/S95asiablock

service asiablock on
service asiablock start



What are you trying to accomplish.
I haven't made any changes to the file other then applying she-bang to the pre-wall script.
I know frater has said it should be updated regularly.

Script works as is and don't see anything I should modify on it.
nitrocs
DD-WRT User


Joined: 21 Jul 2009
Posts: 59

PostPosted: Wed Jun 20, 2012 18:00    Post subject: Reply with quote
basmaf wrote:
Yes your off.

sed -i will edit the file 'in place'
Since you haven't defined a backup extension none will be created.

Just issue the commands one at a time and cat the file in between.

Code:
bas@lenovo:~$ cat /tmp/S95asiablock | grep 'kr '
ISO_spam="af cn in pk my kh li vn kr ph"
bas@lenovo:~$ sed -ie 's/kr ph/kr ph za co/g' /tmp/S95asiablock
bas@lenovo:~$ cat /tmp/S95asiablock | grep 'kr '
ISO_spam="af cn in pk my kh li vn kr ph za co"
bas@lenovo:~$


Use it like this..
Code:
#!/bin/sh
service asiablock stop
service asiablock off

logger "*-* ASIABLOCK UPDATE *-*"
wget -O /opt/etc/init.d/S95asiablock http://otrw.basmaf.com/S95asiablock_2010
sed -ie 's/kr ph/kr ph za co/g' /opt/etc/init.d/S95asiablock

service asiablock on
service asiablock start



What are you trying to accomplish.
I haven't made any changes to the file other then applying she-bang to the pre-wall script.
I know frater has said it should be updated regularly.

Script works as is and don't see anything I should modify on it.


Im writing this to have a weekly update of the ipdeny.com list(s)
the sed edits the script to add in two additional subnet groups (za & co)
I'm not very good at all w/ scripting in bash...very novice
The output I am getting from my script is:
Quote:

root@ETHEREAL:~# sh -x /mnt/asia_upd.sh
+ wget -O /mnt/S95asiablock http://otrw.basmaf.com/S95asiablock_2010
--2012-06-20 13:58:38-- http://otrw.basmaf.com/S95asiablock_2010%0D
Resolving otrw.basmaf.com... 83.83.79.213
Connecting to otrw.basmaf.com|83.83.79.213|:80... connected.
HTTP request sent, awaiting response... 404 Not Found
2012-06-20 13:58:38 ERROR 404: Not Found.

+
: not foundpd.sh: line 5:
+ sed -ie s/kr ph/kr ph za co/g /mnt/S95asiablock
: No such file or directoryablock
+
: not foundpd.sh: line 7:
+ rm /mnt/S95asiablocke
cannot remove `/mnt/S95asiablocke\r': No such file or directory
+
: not foundpd.sh: line 10:
+
: not foundpd.sh: line 14:
+
: not foundpd.sh: line 16:
+
: not foundpd.sh: line 18:
+
: not foundpd.sh: line 20:
root@ETHEREAL:~#

output directory is changed in the above example as to not affect current service

I cannot figure out why the wget command works when issued by itself, but when initiated through the script it cannot find the file on the download server

EDIT: for some reason a "carriage return" is being inserted after the end of the wget command. I am typing the script in notepad++...so instead i copied & pasted into GUI custom command & all seems to work
basmaf
DD-WRT Guru


Joined: 24 Feb 2011
Posts: 1074

PostPosted: Wed Jun 20, 2012 18:30    Post subject: Reply with quote
Ok your using Winblows
Change the end of line of notepad to unix

For achieving what you want downloading of the script is not needed
Stop asiablock
Rm /opt/etc/iptables.asia*
Start asiablock
This will result in downloading the subnets again
You need to renove asia related iptables file otherwise they will be reused
nitrocs
DD-WRT User


Joined: 21 Jul 2009
Posts: 59

PostPosted: Wed Jun 20, 2012 18:35    Post subject: Reply with quote
basmaf wrote:

Stop asiablock
Rm /opt/etc/iptables.asia*
Start asiablock



like i said, i am extremely novice & tend to script in bash in the most round-about bruteforce way
this is much more elegant...i like

thank you!
basmaf
DD-WRT Guru


Joined: 24 Feb 2011
Posts: 1074

PostPosted: Thu Jun 21, 2012 7:36    Post subject: Reply with quote
No problem.
One step at a time Wink

I also learned it the hard way...
and still learning though
nitrocs
DD-WRT User


Joined: 21 Jul 2009
Posts: 59

PostPosted: Thu Jun 21, 2012 18:00    Post subject: Reply with quote
UPDATE:

After using basmaf's scripting idea for some testing, I found that it did not remove all of the files affected by asiablock (i.e. ones in /tmp) & was causing some odd behavior. Rather than add more delete lines, I'm sticking with Frater's recommended update method from the wiki.

First part of script operates as such:
- kill any outside pptp connections (my network setup requires this)
- download new copy of asiablock
- add additional subnets to asiablock script
- remove file added by sed
- restart asiablock

I also found that when asiablock/firewall restart occured my pixelserv was re-downloading the blacks list & overwriting my modified file. The 2nd part of my script acts as follows:
- compare current blacks file to saved modded copy
- only if different, stop pixelserv, remove current blacks & replace with modded copy
- restart pixelserv

Quote:

killall pppd
wget -O /opt/etc/init.d/S95asiablock http://wd.mirmana.com/S95asiablock_2010
if [ $? -gt 0 ];
then
wget -O /opt/etc/init.d/S95asiablock http://otrw.basmaf.com/S95asiablock_2010
fi
sleep 2s
sed -ie 's/kr ph/kr ph ir hk ar br za co id/g' /opt/etc/init.d/S95asiablock
#add: iran, hong kong, argentina, brazil, south africa, columbia & indonesia
sleep 2s
rm /opt/etc/init.d/S95asiablocke
sleep 1s
service asiablock on
sleep 1s
service asiablock start
logger "*-* ASIABLOCK UPDATE COMPLETE *-*"

sleep 90s

cmp -s /opt/etc/pixelserv/blacks /opt/etc/pixelserv/blacks.MODDED_v2 > /dev/null
if [ $? -eq 1 ];
then
service pixelserv stop
sleep 1s
rm /opt/etc/pixelserv/blacks
cp /opt/etc/pixelserv/blacks.MODDED_v2 /opt/etc/pixelserv/blacks
service pixelserv start
logger "*-* PIXELSERV BLACKS UPDATED *-*"
else
logger "*-* PIXELSERV UPDATE NOT NEEDED *-*"
fi


Attached is a copy of my modded blacks file if anyone would like to try it out...put it in /opt/etc/pixelserv/

As I've said before...I'm just looking to automate some functions & have fun while doing so! BASH scripting as a novice is difficult!



blacks.zip
 Description:
modified blacks file

Download
 Filename:  blacks.zip
 Filesize:  268.11 KB
 Downloaded:  395 Time(s)

basmaf
DD-WRT Guru


Joined: 24 Feb 2011
Posts: 1074

PostPosted: Thu Jun 21, 2012 18:20    Post subject: Reply with quote
about pixelserv.

Instead of messing with the blacks file
add additional hosts to opt/etc/pixelserv/host.include
Every time it starts it will add those line to blacks.
basmaf
DD-WRT Guru


Joined: 24 Feb 2011
Posts: 1074

PostPosted: Thu Jun 21, 2012 20:21    Post subject: Reply with quote
to get back on sed

you were right. about asiablocke

use sed -i not sed -ie it will see the e as backupextension.
if none is given none will be made.
it will clean your script from unnecessary removes.
nitrocs
DD-WRT User


Joined: 21 Jul 2009
Posts: 59

PostPosted: Fri Jun 22, 2012 0:21    Post subject: Reply with quote
basmaf wrote:
to get back on sed

you were right. about asiablocke

use sed -i not sed -ie it will see the e as backupextension.
if none is given none will be made.
it will clean your script from unnecessary removes.


much thanks!
Display posts from previous:    Page 1 of 1
Post new topic   Reply to topic    DD-WRT Forum Index -> Broadcom SoC based Hardware All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum