LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-09-2013, 08:58 PM   #16
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600

Heh, no, it's an array:
OLDLINES=($(wc -l "${CONF}")); NEWLINES=($(wc -l "${_TMPFILE}"))
 
Old 02-09-2013, 09:20 PM   #17
rbees
Member
 
Registered: Mar 2004
Location: northern michigan usa
Distribution: Debian Squeeze, Whezzy, Jessie
Posts: 921

Original Poster
Rep: Reputation: 46
I copied and pasted that line and we are back where we started

Code:
:~$ sudo /home/user/3drop.list
[sudo] password for user: 
/home/user/3drop.list: 8: /home/user/3drop.list: Syntax error: "(" unexpected
current script

Code:
#!/bin/sh --
LANG=C; LC_ALL=C; export LANG LC_ALL; 
URI="http://www.spamhaus.org/drop"; CONF="/etc/arno-iptables-firewall/blocked-hosts"
_TMPFILE=$(mktemp -p /tmp drop_upd.XXXXXXXXXX)
[ -f "${_TMPFILE}" ] || { echo "Error, exiting." >/dev/stderr; exit 1; }
( wget -q ${URI}/drop.txt -O /dev/stdout; wget -q ${URI}/edrop.txt -O /dev/stdout ) > "${_TMPFILE}"
[ -s "${_TMPFILE}" ] || { echo "Error, exiting." >/dev/stderr; rm -f "${_TMPFILE}"; exit 1; }
OLDLINES=($(wc -l "${CONF}")); NEWLINES=($(wc -l "${_TMPFILE}"))
cp -f "${CONF}" /var/cache/$(/bin/date +'%Y%m%d')_blocked-hosts
sed -e 's/\;.*$//g' "${_TMPFILE}" > "${CONF}" && arno-iptables-firewall force-reload
echo "Blocked-hosts had ${OLDLINES[0]} lines, now ${NEWLINES[0]}. Finished, exiting."
rm -f "${_TMPFILE}"; exit 0
 
Old 02-09-2013, 09:41 PM   #18
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Well, the script works for me. I suggest you test it by running it as unprivileged user and without using Sudo. (You usually do not want to execute a script with root rights that resides in a directory that is not owned by root anyway.) If that doesn't error out (apart from not being able to replace the configuration file or restart the service) then run as 'sudo /bin/bash -vx /home/user/3drop.list 2>&1 | nl | tee /home/user/3drop.list.txt'. Read "/home/user/3drop.list.txt". If that doesn't contain errors then it's not the script that's the problem. If it however does contain errors then attach the plain text file "/home/user/3drop.list.txt".

Last edited by unSpawn; 02-09-2013 at 09:43 PM.
 
Old 02-10-2013, 06:41 AM   #19
rbees
Member
 
Registered: Mar 2004
Location: northern michigan usa
Distribution: Debian Squeeze, Whezzy, Jessie
Posts: 921

Original Poster
Rep: Reputation: 46
Same results.

Code:
:~$ /home/user/3drop.list
/home/user/3drop.list: 8: /home/user/3drop.list: Syntax error: "(" unexpected

I posted the file above but will attach anyway
Attached Files
File Type: txt 3drop.list.txt (779 Bytes, 21 views)
 
Old 02-10-2013, 07:00 AM   #20
rbees
Member
 
Registered: Mar 2004
Location: northern michigan usa
Distribution: Debian Squeeze, Whezzy, Jessie
Posts: 921

Original Poster
Rep: Reputation: 46
From what I see when searching the web on bash arrays there should be a set of square brackets somewhere in that line. Of coarse I am not much of a programmer and this is sh and not bash so I am guessing.
 
Old 02-10-2013, 07:24 PM   #21
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
I'm sorry but there's no indication you tested things the way I suggested and you didn't post what I asked for. Can't help you if you won't help me.
 
Old 02-10-2013, 07:44 PM   #22
rbees
Member
 
Registered: Mar 2004
Location: northern michigan usa
Distribution: Debian Squeeze, Whezzy, Jessie
Posts: 921

Original Poster
Rep: Reputation: 46
I ran the script as a normal user and got the same results as when I used sudo which I posted above.

As per your instructions
Quote:
If that doesn't error out {and it did} (apart from not being able to replace the configuration file or restart the service) "then run"
I didn't think there was anything else I could do at this point until I received other instructions. Sorry.

What should I do?

I don't know that it matters but the system I am testing on is Debian Wheezy (patched weekly) amd64. I also am getting an error when I run ls

Code:
:~$ ls
ls: unrecognized prefix: mh
ls: unparsable value for LS_COLORS environment variable
I have looked but have not yet figured out how to fix it.
 
Old 02-10-2013, 08:31 PM   #23
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
OK. I'll fire up a Debian box tomorrow and see (can't even remember which version it runs). The ls thing means something coreutils. Apparently "mh" stands for "Multi Hardlink" meaning your `dircolors -b` is missing a value for "mh" like ":mh=44;37:". See if you can
Code:
dircolors -b|sed -e "s/';$/mh=44;37:\';/g" ~/.dircolors
. ~/.dircolors
and then try 'ls' again.
 
Old 02-10-2013, 09:12 PM   #24
rbees
Member
 
Registered: Mar 2004
Location: northern michigan usa
Distribution: Debian Squeeze, Whezzy, Jessie
Posts: 921

Original Poster
Rep: Reputation: 46
don't have ~/.dircolors that and other files I have seen to check and edit don't exist on my system.
 
Old 02-11-2013, 07:52 AM   #25
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Should be
Code:
dircolors -b|sed -e "s/';$/mh=44;37:\';/g" > ~/.dircolors
. ~/.dircolors
 
Old 02-11-2013, 07:59 AM   #26
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
The script works OK on Squeeze and running '/bin/bash --version' returns "GNU bash, version 4.1.5(1)-release (i486-pc-linux-gnu)".
So what's your Bash version?
 
Old 02-11-2013, 05:28 PM   #27
rbees
Member
 
Registered: Mar 2004
Location: northern michigan usa
Distribution: Debian Squeeze, Whezzy, Jessie
Posts: 921

Original Poster
Rep: Reputation: 46
Code:
:~$ /bin/bash --version
GNU bash, version 4.2.37(1)-release (x86_64-pc-linux-gnu)
 
Old 02-11-2013, 05:30 PM   #28
rbees
Member
 
Registered: Mar 2004
Location: northern michigan usa
Distribution: Debian Squeeze, Whezzy, Jessie
Posts: 921

Original Poster
Rep: Reputation: 46
I got the dircolors thing fixed. THanks. Had to run it in a root console. Sudo didn't work.
 
Old 02-11-2013, 07:02 PM   #29
rbees
Member
 
Registered: Mar 2004
Location: northern michigan usa
Distribution: Debian Squeeze, Whezzy, Jessie
Posts: 921

Original Poster
Rep: Reputation: 46
on the dircolors thing now I have
Code:
dircolors: /home/kingbee/.dircolors:1: invalid line;  missing second token
at the top of the screen. I had a mh=00 that I deleted and did re-login but that did not fix it. There is another entry that has only 1 token? but as it is not a duplicate I didn't want to just remove it. The beginning of the file
Code:
LS_COLORS='rs=0:di=01;34:ln=01;36:pi=40;33:so=01;35
I fired up a Squeeze vm that I have and it runs the script ok. The vm has the same version of bash as what you reported. I did notice that the blocked-host file that is generated only contains the data from edrop.txt and "not" the data from drop.txt Of the two I would think the data from drop.txt would be more important to have. I did have to create a dummy directory and file in /etc/arno-iptables-firewall to get it to complete without error.
 
Old 02-11-2013, 07:51 PM   #30
rbees
Member
 
Registered: Mar 2004
Location: northern michigan usa
Distribution: Debian Squeeze, Whezzy, Jessie
Posts: 921

Original Poster
Rep: Reputation: 46
I did get it to work somewhat. It seams that getting rid of the second set of () fixes that part. Changing to
Code:
OLDLINES=$(wc -l "${CONF}"); NEWLINES=$(wc -l "${_TMPFILE}")
fixes that part. Thanks to one of the guys at my local lug.

Now there is a different problem.

Code:
./3drop.list: 11: ./3drop.list: Bad substitution
The debug output
Code:
sudo ./3drop.list
+ LANG=C
+ LC_ALL=C
+ export LANG LC_ALL
+ URI=http://www.spamhaus.org/drop
+ CONF=/etc/arno-iptables-firewall/blocked-hosts
+ mktemp -p /tmp drop_upd.XXXXXXXXXX
+ _TMPFILE=/tmp/drop_upd.3fZ29B6UBs
+ [ -f /tmp/drop_upd.3fZ29B6UBs ]
+ wget -q http://www.spamhaus.org/drop/drop.txt -O /dev/stdout
+ wget -q http://www.spamhaus.org/drop/edrop.txt -O /dev/stdout
+ [ -s /tmp/drop_upd.3fZ29B6UBs ]
+ wc -l /etc/arno-iptables-firewall/blocked-hosts
+ OLDLINES=23 /etc/arno-iptables-firewall/blocked-hosts
+ wc -l /tmp/drop_upd.3fZ29B6UBs
+ NEWLINES=23 /tmp/drop_upd.3fZ29B6UBs
+ /bin/date +%Y%m%d
+ cp -f /etc/arno-iptables-firewall/blocked-hosts /var/cache/20130211_blocked-hosts
+ sed -e s/\;.*$//g /tmp/drop_upd.3fZ29B6UBs
+ arno-iptables-firewall force-reload
Arno's Iptables Firewall Script v2.0.1c
-------------------------------------------------------------------------------

Feb 11 20:30:34 All firewall rules applied.
./3drop.list: 11: ./3drop.list: Bad substitution
The script is still overwriting drop.txt when it downloads edrop.txt too
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Host is blocked because of many connection error;unblock with mysqladmin-flush-hosts jsaravana87 Linux - Server 1 11-28-2011 09:11 AM
blocked update lucid lynx tiomoco Linux - Newbie 2 03-08-2011 12:54 PM
Script for hosts, numbers of hosts and users connected to squid server arunabh_biswas Programming 5 08-28-2010 04:11 AM
script to update /etc/hosts on dhcp obtained ip change. juanctes Linux - General 1 02-02-2008 09:17 AM
script to update /etc/hosts bradut Linux - Newbie 8 07-16-2002 10:52 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:29 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration