Re: Handling special characters in peoples names in XML
Thanks Terry for responding. The files are very big and contain data I'd prefer not to be out in the wild. what parts of the file would be helpful , I can provide the lines with the text and say heard part of the xml ?? Thanks G On Thu, Jun 20, 2013 at 7:42 PM, Jenda Krynicky je...@krynicky.cz wrote: From: Gregory Machin g...@linuxpro.co.za I'm debugging an application written in Perl that converse data exported from the Nessus security scanner in xml format. I have narrowed down the bug to an issue with special characters in names that are in the file such as Fr~A©d~A©ric and Gr~A©goire , thus ~A© are most likely the guilty parties. What is the best and most simple way to handle this ? From a quick google it looks like I should convert the file to UTF8 format , would this be correct ? Thanks Greg Looks like the data already is utf8, but the header of the XML specifies otherwise. How do you parse the data? Can you give us a short example file? Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Handling special characters in peoples names in XML
Hi. I'm debugging an application written in Perl that converse data exported from the Nessus security scanner in xml format. I have narrowed down the bug to an issue with special characters in names that are in the file such as Frédéric and Grégoire , thus é are most likely the guilty parties. What is the best and most simple way to handle this ? From a quick google it looks like I should convert the file to UTF8 format , would this be correct ? Thanks Greg
DBI driving me nuts ... !
Hi Please can you advise ? #!/usr/bin/perl use Mysql; $dbh = Mysql-connect(localhost,mailscanner,root,c0nc3pt) or die (Error . Mysql-errno . - . Mysql-errstr); $sql = SELECT to_address FROM maillog LIMIT 10;; $sth = $dbh-query($sql) or die (Error . Mysql-errno . - . Mysql-errstr); while (@row = $sth-fetchrow){ print $row /n; } which gives this [r...@mail10 ~]# perl addressrep2.pl /n /n /n /n /n /n /n /n /n /n[r...@mail10 ~]# when it should give the same output as Database changed mysql SELECT to_address FROM maillog LIMIT 10 - ; ++ | to_address | ++ | iv...@systems.xxx| | tkek...@stpeters.xxx | | dfou...@howden.xxx | | melan...@mdlulisharp.xxx | | er...@mdlulisharp.xxx| | desi...@oas.xxx | | dbalakis...@multivid.xxx | | bhar...@webb.xxx | | jcven...@multivid.xxx| | ad...@troika-iw.xxx| ++ 10 rows in set (0.00 sec) mysql what am I doing wrong ? Thanks -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
regex question
Hi I'm look for code example that will only select a string containing 3 digits .. The string cant be less than 3 digit , can't be more than 3 and can't contain any other characters. I have googled and found code that will find 3 consecutive digits within a string or at the beginning. Any ideas ? Thanks G -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: regex question
Any numbers, but only 3 digits in the string. I'm filtering out local extention numbers from phone numbers Where in the log the extension is 104 and the phone number would be something like PSTN0/2-0115070545. All the stuff I have tried have returned would return both the extension number and 3 digits from the phone number eg 011 . So I only want the records that beginning and end in a number and have exactly 3 digits not longer. Thanks for you time. G On Tue, Sep 15, 2009 at 9:52 AM, Tim Bowden tim.bow...@mapforge.com.au wrote: On Tue, 2009-09-15 at 09:30 +0200, Gregory Machin wrote: Hi I'm look for code example that will only select a string containing 3 digits .. The string cant be less than 3 digit , can't be more than 3 and can't contain any other characters. I have googled and found code that will find 3 consecutive digits within a string or at the beginning. Any ideas ? Thanks G So you want a regex that will identify a three digit string (any 3 digits or 3 specified digits?) and anchor to both the start and end of the string? Tim Bowden -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: regex question
Thanks for the help .. knowing the anchor thing help me. if you not sure what ur looking for or what it call you end up with the wrong thing. On Tue, Sep 15, 2009 at 10:21 AM, Tim Bowden tim.bow...@mapforge.com.au wrote: On Tue, 2009-09-15 at 10:10 +0200, Gregory Machin wrote: Any numbers, but only 3 digits in the string. I'm filtering out local extention numbers from phone numbers Where in the log the extension is 104 and the phone number would be something like PSTN0/2-0115070545. All the stuff I have tried have returned would return both the extension number and 3 digits from the phone number eg 011 . So I only want the records that beginning and end in a number and have exactly 3 digits not longer. Thanks for you time. G Ah, so you do want to anchor at the beginning and end of the string. Have you looked at perlrequick (http://perldoc.perl.org/perlrequick.html) as Uri suggested? That should show you how to anchor a regex to the start and end of a string. Post what you're trying after looking there. Regards, Tim Bowden BTW, please try not to top post. It breaks the flow of the thread. On Tue, Sep 15, 2009 at 9:52 AM, Tim Bowden tim.bow...@mapforge.com.au wrote: On Tue, 2009-09-15 at 09:30 +0200, Gregory Machin wrote: Hi I'm look for code example that will only select a string containing 3 digits .. The string cant be less than 3 digit , can't be more than 3 and can't contain any other characters. I have googled and found code that will find 3 consecutive digits within a string or at the beginning. Any ideas ? Thanks G So you want a regex that will identify a three digit string (any 3 digits or 3 specified digits?) and anchor to both the start and end of the string? Tim Bowden -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Trying to remove text in inverted commas.
Hi I'm writing a script to import logs into a Mysql .. My Perl is rusty and I'm battling with a convention on the one column. I need to remove the text in inverted commas Prashil 106 so that just the number 106 remains.. I have been trying the following regex s/(\([^]+)\\s)//g but it doesn't seem to work. I got it from a website .. It looked correct .. mmm .. with regard to it's structure i don't quite get ([^]+) as I have tried replacing it with other combinations and had less luck. I have also tried s/\([:word:])\\s)//g ... Thanks for advise in advance Gregory Machin -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Trying to remove text in inverted commas.
My appologies for not including the sample data. Lines begin with SC or MC and are tab delimited SC 11-Aug-2009 07:54:38626 Heinrich 107 0800375...@sip2.switchtel.co.za:5060 171665a3-9560-4003-a649-9eeb72214130N/A N/A 10.0.1.249:6090 - 10.0.1.197:2234 1 (excellent) G729a G729a 31343 31348 20 20 0 15 170 0 0 66.8.102.5:6092 - 41.203.29.100:13682 5 (very bad)G729a G729a 31348 31343 20 20 10131 16 399046600 0 N/A N/A N/A N/A N/A N/A N/A SC 11-Aug-2009 07:58:45332 PSTN2/1-?(00) Prashil 106 d8324eef-c206-4f8e-bf9e-673419f76233PSTN call,PSTN callN/A 10.0.1.249:6000 - 10.0.1.174:2226 1 (excellent) G729a G729a 16360 16370 20 20 0 15 63 0 5 N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A MC 11-Aug-2009 08:04:160 Prashil 106 Hishal 111 32171bd8-db95-4392-9aa5-8f5b40ccd01dN/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A SC 11-Aug-2009 08:00:4991 PSTN1/1-Returned Call: ? Malcolm 112 2601d0b4-8e53-40b4-9fa8-1d16b0e49c74PSTN call N/A 10.0.1.249:6014 - 10.0.1.178:2230 1 (excellent) G729a G729a 4546455620 20 0 1 3 0 4 N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A SC 11-Aug-2009 07:58:56179 PSTN0/1-? Lourens 109 39c8b046-471a-4256-99c4-5cc97b0e084bPSTN call N/A 10.0.1.249:6004 - 10.0.1.177: 1 (excellent) G729a G729a 8925892920 20 0 15 20 0 4 N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A SC 11-Aug-2009 07:59:1273 PSTN1/1-?(00) Malcolm 112 2601d0b4-8e53-40b4-9fa8-1d16b0e49c74PSTN call,PSTN callN/A 10.0.1.249:6006 - 10.0.1.178:2226 1 (excellent) G729a G729a 3049305320 20 0 10 6 0 4 N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A N/A On Mon, Aug 24, 2009 at 12:19 PM, Thomas Bätzlert.baetz...@bringe.com wrote: Hello Gregory, Gregory Machin gregory.mac...@gmail.com asked: I'm writing a script to import logs into a Mysql .. My Perl is rusty and I'm battling with a convention on the one column. I need to remove the text in inverted commas Prashil 106 so that just the number 106 remains.. I have been trying the following regex s/(\([^]+)\\s)//g but it doesn't seem to work. It's always helpful if we can see several lines of sample input aswell as the output you wish to achieve so that we can understand your problem better. If your code doesn't work, please post the relevant portion of it. The RE you quoted will match a substring consisting of a double quote, followed by at least one character that is not a double quote, followed by another double quote and finally a whitespace (blank, tab) character. The match will be removed sicne you replace it with an empty string. Due to the modifier /g it will do that to multiple instances of the match in one line. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
using ssh to do remote audit of machines
Hi I have a database with my servers details in .. I would like to write a scripts to get the servers log on info ssh to the box and get basic info using the following hostname cat /etc/issue cat /proc/cpuinfo | grep model name cat /proc/meminfo | grep MemTotal uname -s -r squid -v /usr/sbin/sendmail -v -d0.1 Then save the info to the database. Any tips on doing this ? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: using ssh to do remote audit of machines
Thanks will look into those . On Tue, Sep 9, 2008 at 10:07 AM, Jeff Pang [EMAIL PROTECTED] wrote: 2008/9/9 Gregory Machin [EMAIL PROTECTED]: Hi I have a database with my servers details in .. I would like to write a scripts to get the servers log on info ssh to the box and get basic info using the following hostname cat /etc/issue cat /proc/cpuinfo | grep model name cat /proc/meminfo | grep MemTotal uname -s -r squid -v /usr/sbin/sendmail -v -d0.1 Then save the info to the database. From my thought, you can write a script on that host, which should update the database for the info you needed, and run it by crontab. If you really need to do a ssh operation in Perl, see perldoc Net::SSH. For database oepration, see perldoc DBI. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: store a complete object?
hi I dont see why you couldnt just INSERT the value into a database .. It's just the column type that may be the issue with mysql i would suggest the blob or one of the text types http://dev.mysql.com/doc/refman/5.0/en/blob.html .. On Tue, Aug 5, 2008 at 1:02 PM, Oliver Block [EMAIL PROTECTED] wrote: Hello everybody, my $obj = MYCLASS-new( ... ); I wonder if there are ways to save $obj with all its members to disc or a database table? Best Regards, Oliver Block -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
system() function not executing scripts
Hi I'm porting a script for one linux distro to another. but hit a problem, the main script is called by squid and runs as a service for squid, this script then calls other scripts depending on the action needed thought the system() function. The problem is it's not executing these scripts, i have chowned them to the user squid, and even chmod 0777 them, but no joy, yet they work fine if executed buy root what have i missed ? -- Gregory Machin [EMAIL PROTECTED] www.linuxpro.co.za -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
script won't write to file ...
Hi I have a script that i'm working on, I want it to write info to a log file, but I can't get it to write to the file.. I run the script as root, and I also chmod 0777 the file but still no out put ... what have it missed .. ___script___ #!/usr/bin/perl print hello; use use strict; #package ifwatch; ### global vars my $primaryif = /dev/ttyACM0; my $secondaryif = /dev/ttyACM1; my $primaryconfig = /etc/ifwatch/ACM0; my $secondayconfig = /etc/ifwatch/ACM1; my $currentif; my $mainloopsleep = 10; my $LOG_DIR = /var/log; daemonize(); main(); process handeling kill and restart call $SIG{INT} = sub { print STATUS_LOG localtime() . Exiting...\n; close (DEBUG_LOG); close (ERROR_LOG); exit; }; $SIG{HUP} = sub { print STATUS_LOG localtime() . Restarting...\n; exec ($0, @ARGV) or die Could not restart: $!\n; close (STATUS_LOG); close (STATUS_LOG); exit; }; sub ifcheck{ #my $files = /dev/xtty0; #Bunless (open(TESTFILE, $files)){ #die (File does not exist); #} } # daemonize sub daemonize { # use POSIX qw(setsid); open (STDIN, /dev/null); open (STATUS_LOG, /var/log/ifwatch); # defined(my $pid = fork) or die Can't fork: $!; # exit if $pid; } main loop sub main { print STATUS_LOG localtime() . hello ; my $loop = 1; while ($loop = -1) { print STATUS_LOG localtime() . sleeping\n; sleep $mainloopsleep; } print STATUS_LOG localtime() . ifwatch exiting; close (STATUS_LOG); } 1 ; -- Gregory Machin [EMAIL PROTECTED] www.linuxpro.co.za -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
testing if hardware is avalible
Hi can you advise on the best way test if a usb modem is plugged in ? I though about checking if the file/node /dev/ttyACM0 is present, as it's created when the device is plugged in using open (TEST, /dev/tty/ACM0); but just concecned if i do this while the device is acitive it will cause it to drop the connection... What is the best methode for this ?? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: script won't write to file ...
Ok thanks, for the advise, 2 questions - what did i do wrong in my original code, cause it's based on a working example, and is IO::File included in the default perl package ? is this script has to go on an embedded device with as min dependencies as possible ? Many Thanks On 7/20/07, Chas Owens [EMAIL PROTECTED] wrote: On 7/20/07, Gregory Machin [EMAIL PROTECTED] wrote: Hi I have a script that i'm working on, I want it to write info to a log file, but I can't get it to write to the file.. I run the script as root, and I also chmod 0777 the file but still no out put ... what have it missed .. snip Simplify, simplify, simplify. #!/usr/bin/perl use strict; use warnings; use IO::File; my $wait = 10; my $logfile = /var/log/ifwatch; my $continue = 1; open my $log, , $logfile or die could not open $logfile:$!; $log-autoflush(1); process handeling kill and restart call $SIG{INT} = $SIG{TERM} = sub { print $log localtime() . Exiting...\n; $continue = 0; }; $SIG{HUP} = sub { print $log localtime() . Restarting...\n; exec ($0, @ARGV) or die Could not restart: $!\n; }; open STDIN, , /dev/null or die could not redirect stdin: $!; print $log localtime() . ifwatch starting\n; while ($continue) { #do stuff print $log localtime() . sleeping\n; sleep $wait; } print $log localtime() . ifwatch exiting\n; -- Gregory Machin [EMAIL PROTECTED] www.linuxpro.co.za -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Dynamically loading perl code
On 7/12/07, Chas Owens [EMAIL PROTECTED] wrote: On 7/12/07, Gregory Machin [EMAIL PROTECTED] wrote: Hi I have a rusty memory of perl have the ability, where by you can load perl code into an variable / array then execute it on demand, anyone got an example of how to do this .. Many Thanks The string based version eval function can do this, but it is very dangerous (for one thing, you open yourself up to injection attacks*) and it is very rarely really needed. If you describe what you want to achieve we may be able to tell you how to achieve the effect without eval. * http://en.wikipedia.org/wiki/Code_injection What I want to do is to write a service monitoring daemon, where the core or body of the script parses a directory, that contains the config / perl scripts, and is loaded into the core script, if one of the scripts has an unrecoverable error, it's dumped, thus preserving the daemon, but more importantly it allows for more inflexibility, as each script can be tailored to suite that particular service, without bloating the core script, obviously keeping all good reusable code in the core script... The script needs to have as few dependencies as posible as it's going to be run on a custom os thats very minimal ... and not only will in need to monitor other daemons but also the status on network interfaces and there connectivity, monitor daemons log files can carry out actions based on the content, thus also trying to do preventative maintenance .. Quite an under taking for a nubee, but it'll help fast track my perl skills i'm sure .. -- Gregory Machin [EMAIL PROTECTED] www.linuxpro.co.za -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Dynamically loading perl code
Hi I have a rusty memory of perl have the ability, where by you can load perl code into an variable / array then execute it on demand, anyone got an example of how to do this .. Many Thanks -- Gregory Machin [EMAIL PROTECTED] www.linuxpro.co.za -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
missing something from regex ...
Hi i have the following string I need to break down into usable data ... CLIENT_LIST,tsc-odi.vpn.ct-net.org,165.146.60.29:11134,10.1.0.46,1959761,218729,Wed May 16 11:24:37 2007,1179307477 and I dont want Wed May 16 11:24:37 2007 cause the number at the end is the same thing .. this is the beginning of my code ... $row = CLIENT_LIST,tsc-odi.vpn.ct-net.org,165.146.60.29:11134,10.1.0.46,1959761,218729,Wed May 16 11:24:37 2007,1179307477 $row = ~/(\w+)\,(\w+)\,(\d+\.\d+\.\d+\.\d+\:\d+)\,(\d+\.\d+\.\d+\.\d+)\,(\d+)\,(\d+)\,\,(\d+)/ print info $1 \n; print hostname $2 \n; print pubip $3 \n; print wanip $4 \n; print recieved $5 \n; print sent $6 \n; print time $7 \n; and I'm getting the following error .. [EMAIL PROTECTED] ~]# ./vpninfo.pl ./vpninfo.pl: line 1: =: command not found ./vpninfo.pl: line 2: syntax error near unexpected token `(' ./vpninfo.pl: line 2: `$row = ~/(\w+)\,(\w+)\,(\d+\.\d+\.\d+\.\d+\:\d+)\,(\d+\.\d+\.\d+\.\d+)\,(\d+)\,(\d+)\,\,(\d+)/' [EMAIL PROTECTED] ~]# what have I missed ... Many thanks -- Gregory Machin [EMAIL PROTECTED] www.linuxpro.co.za -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: $ARGV[0] breaks the script
Hi thanks for looking at the script.. Just to clarify, the scipt runs perfectly if $input it hardcoded eg $input=httpd. thus if the process is running then it exits, if the process is not running then it exicutes exec /etc/init.d/$input restart ; But if I use $input=$ARGV[0] to give the process name from the command line, it runs as if the process is running if if I have stoped/killed it.. the only reason for this is that there is a hidden character, but where is it comming from ? On 12/14/06, D. Bolliger [EMAIL PROTECTED] wrote: Gregory Machin am Donnerstag, 14. Dezember 2006 13:24: hi Hi Gregory the script will not work Not work? :-) if I use $ARGV[0] but works 100% if I hard code the $input variable; what have i missed ? You can give anything as cmd line argument, and the script will tell you that it is not running, because of a) open PROS, ps -ef|grep $input |; combined with b) unless ($line =~ m/grep/){...} This script is running as root... that makes it even more important to check user provided data, what exactly is executed in the shell, and what binaries are called. - use absolute paths for binaries (ps and grep in this case) - make sure that $input only contains ascii characters for example, in this case, only a to z: my ($input) = $ARGV[0]=~/([a-z]{,16})/; # untested die unless $input; btw: /etc/init.d/grep start ??? This is a hint to also check if $input corresponds to a binary in /etc/init.d at the beginning of the script :-) This would solve the grep-not-allowed/script-uses-grep-and-does-not-work problem :-) What about also using /etc/init.d/some_daemon status and check if this information is in sync with the ps output (it isn't always, and the restart could therefore fail - what you don't test) hope this helps Dani #!/usr/bin/perl # if your prgram has the string grep in the name or in the path # this program won't work. use strict; use warnings; my $line; my $input; $input=$ARGV[0]; #$input=httpd; chomp $input; open PROS, ps -ef|grep $input |; while ($line = PROS){ unless ($line =~ m/grep/){ print $input is running\n; exit; } } print $input isn't running\n; exec /etc/init.d/$input restart ; Many thanks -- Gregory Machin [EMAIL PROTECTED] www.linuxpro.co.za -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- Gregory Machin [EMAIL PROTECTED] www.linuxpro.co.za -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
$ARGV[0] breaks the script
hi the script will not work if I use $ARGV[0] but works 100% if I hard code the $input variable; what have i missed ? #!/usr/bin/perl # if your prgram has the string grep in the name or in the path # this program won't work. use strict; use warnings; my $line; my $input; $input=$ARGV[0]; #$input=httpd; chomp $input; open PROS, ps -ef|grep $input |; while ($line = PROS){ unless ($line =~ m/grep/){ print $input is running\n; exit; } } print $input isn't running\n; exec /etc/init.d/$input restart ; Many thanks -- Gregory Machin [EMAIL PROTECTED] www.linuxpro.co.za -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
creepy print() that doesnt print.
Hi please could you have a look and see what I have missed. use File::Tail; my $name=/etc/openvpn/logs/CT-NET.log; my $maxinterval=10 ; my $adjustafter=7 ; $file=File::Tail-new(name=$name, maxinterval=$maxinterval, adjustafter=$adjustafter); while (defined($line=$file-read)) { print ($line);this line prints fine print (hello); but this one does not print at all } i have allso tried print hello; but the result is the same.. I have tried ping ($line hello); but it does not print the hello. what have I missed .. Many thanks for your time -- Gregory Machin [EMAIL PROTECTED] www.linuxpro.co.za -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: removing single quotation marks from a string ?
Thanks for all the advice :-). I'll follow up on it shortly, this is just my dummy script for testing :-) Have a grate day .. On 11/17/06, John W. Krahn [EMAIL PROTECTED] wrote: Mumia W. wrote: This works: use Mysql; use strict; use warnings; my $regex = '^(\d+)-(\w+)-(\d+) (\d+):(\d+):(\d+).*?client' . '\s(\d+)(.\d+)(.\d+)(.\d+)#(\d+): view external: (.*)$'; You need to escape the . character to match a literal period. You should probably also use the qr// operator: my $regex = qr/ ^ (\d+)-(\w+)-(\d+) \s+ (\d+):(\d+):(\d+) .*?client\s+ (\d+\.\d+\.\d+\.\d+)\#(\d+) :\s+view external:\s+ (.*) $ /x; my $dbh = Mysql-connect('localhost','test','') or die(Connect failed.); my $search = $dbh-query('select msg from logfiles') or die(Query failed: . $dbh-errstr); while (my @row = $search-fetchrow) { no strict 'vars'; Why are you turning off strict? $row[0] =~ tr/'//d; if ($row[0] =~ /$regex/os) { $day = $1; $month = $2; $year = $3; $hour = $4; $minute = $5; $second = $6; $clientip = $7; $clientip .= $8; $clientip .= $9; $clientip .= $10; $port = $11; $query = $12; print(day is $day\n); print(month is $month\n); print(year is $year\n); print(hour is $hour\n); print(minute is $minute\n); print(second is $second\n); print(clientip is $clientip\n); print(port is $port\n); print(query is $query\n); print(\n); Why all the copying? if ( $row[ 0 ] =~ /$regex/ ) { print TEXT; day is $1 month is $2 year is $3 hour is $4 minute is $5 second is $6 clientip is $7 port is $8 query is $9 TEXT } else { print Malformed Log Entry: $row[0]\n; } } undef $search; undef $dbh; John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order. -- Larry Wall -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- Gregory Machin [EMAIL PROTECTED] www.linuxpro.co.za -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
removing single quotation marks from a string ?
Hi I need to remove all the quotation marks from, a string I tried s/\'// but it did not work. what have i missed ?? Many Thanks -- Gregory Machin [EMAIL PROTECTED] www.linuxpro.co.za -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: removing single quotation marks from a string ?
Hi I'm still not getting the result i require please could someone have a quick look and see what i'm missing ... the following code is suposed to break up the looked info from dns server so I can manipulate it. It dies with the following errors when it reads more than one line from the database Can't call method fetchrow without a package or object reference at ./test.pl line 13. code #!/usr/bin/perl #$test = 15-Nov-2006 14:11:06.304 update: info: client 196.211.85.42#35435: view external: updating zone \'goal.lek.linserv.co.za/IN\': add use Mysql; $dbh = Mysql-connect('localhost','syslog_ng','root','') or die(Error . $dbh-errno . - . $dbh-errstr); $query = $dbh-query(SELECT msg FROM logs where program = 'named'; ) or die(Error . $dbh-errno . - . $dbh-errstr); while (@row = $query-fetchrow){ #chomp ; #if ($test =~ /^(\d+)-(\w+)-(\d+) (\d+):(\d+):(\d+).*?client (\d+)(.\d+)(.\d+)(.\d+)#(\d+): view external: (.*)$/){ $_ =~ tr/'//d ; if ($row[msg] =~ /^(\d+)-(\w+)-(\d+) (\d+):(\d+):(\d+).*?client (\d+)(.\d+)(.\d+)(.\d+)#(\d+): view external: updating zone (.*)$/){ $day = $1; $month = $2; $year = $3; $hour = $4; $minute = $5; $second = $6; $clientip = $7; $clientip .= $8; $clientip .= $9; $clientip .= $10; $port = $11; $query = $12; print(day is $day\n); print(month is $month\n); print(year is $year\n); print(hour is $hour\n); print(minute is $minute\n); print(second is $second\n); print(clientip is $clientip\n); print(port is $port\n); print(query is $query\n); print(\n); }else{ print(malformed log entry: $_ \n); } /code $test is a sample of the syntex. On 11/16/06, Gregory Machin [EMAIL PROTECTED] wrote: Hi I need to remove all the quotation marks from, a string I tried s/\'// but it did not work. what have i missed ?? Many Thanks -- Gregory Machin [EMAIL PROTECTED] www.linuxpro.co.za -- Gregory Machin [EMAIL PROTECTED] www.linuxpro.co.za -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
please advise help with regex
Hi I need to parse the logs for my named server. i'm having difficulty getting my mind around the regex to break the data up .. i want the break it up and store it in a data base then maniptulate the data from there ... |date | time |catagory|severity|client |ip |port |view||query | 28-Sep-2006 10:10:57.266update: info: client 192.168.1.170#33364: view internal: updating zone 'lan.linserv.co.za/IN': adding an RR at ' greg.lan.linserv.co.za' A any ideas ? Many thanks -- Gregory Machin [EMAIL PROTECTED] www.linuxpro.co.za
Re: please advise help with regex
i have been playing... will this work and wich is more efficient ? /^([0-3][0-9]\- #day-| (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s+#month | \-(20)[0-9][0-9]\s+ #year till 2099 | [0-9][0-9]\: #hour |= date and time [0-9][0-9]\: #miniute | [0-9][0-9]\:) #hour-| ((\.\d{3})? #milliseconds (\w\:) #catagory- catagory (\s+\w\:) #severity- serverity (\w\s+) #host- host (s+\d+\.\d+\.\d+\.\d+) #ip- ip (\#\d+/i) #port- port (\:\s+\s\w\s\w\:)#view - view (\s+[:alpha:]/)#query - query On 9/28/06, Rob Dixon [EMAIL PROTECTED] wrote: Gregory Machin wrote: Hi I need to parse the logs for my named server. i'm having difficulty getting my mind around the regex to break the data up .. i want the break it up and store it in a data base then maniptulate the data from there ... |date | time |catagory|severity|client |ip |port |view||query | 28-Sep-2006 10:10:57.266update: info: client 192.168.1.170#33364: view internal: updating zone 'lan.linserv.co.za/IN': adding an RR at ' greg.lan.linserv.co.za' A any ideas ? Hi Gregory It looks like your data fields are separated by a colon and a space, except for the first three. Is there really nothing at all between the milliseconds and the 'category' field? Anyway, assuming the data I have is correct (it's difficult to tell with the wrapping that the various email systems apply) the code below should do what you want. It works by splitting on, as I said, colon and whitespace, and then pulling off the first field and splitting it again into three based on the contents of these fields' data. You also seem to want the client field split into 'client', IP address and port number, so I've pulled that field out and split it up as well. Hope it helps, Rob use strict; use warnings; while (DATA) { chomp; my @data = split /:\s+/; my $prefix = $data[0]; splice @data, 0, 1, $prefix =~ /(\S+)\s+([0-9:.]+)(.+)/; my $client = $data[-4]; splice @data, -4, 1, $client =~ /[^\s#]+/g; print $_\n foreach @data; } __DATA__ 28-Sep-2006 10:10:57.266update: info: client 192.168.1.170#33364: view internal: updating zone 'lan.linserv.co.za/IN': adding an RR at ' greg.lan.linserv.co.za' A **OUTPUT** 28-Sep-2006 10:10:57.266 update info client 192.168.1.170 33364 view internal updating zone 'lan.linserv.co.za/IN' adding an RR at 'greg.lan.linserv.co.za' A -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- Gregory Machin [EMAIL PROTECTED] www.linuxpro.co.za
advise on writing cgi scripts to create + manage certificate authority.
Hi I have to write a cgi appliction to manage a certificate authority for AES 256 CBC and 128 CBC ... How would I go about this the only application I have used for this was comand lline interactive... Any suggestions .. -- Gregory Machin [EMAIL PROTECTED] www.linuxpro.co.za
Re: advise on writing cgi scripts to create + manage certificate authority.
Thanks for the lead ... But my question was focused on the creation of a certifictate authority mangment interface using cgi as aposed to comandline ... which is the norm ... I have a basic knowlage of perl cgi.. On 8/3/06, Gregory Machin [EMAIL PROTECTED] wrote: Hi I have to write a cgi appliction to manage a certificate authority for AES 256 CBC and 128 CBC ... How would I go about this the only application I have used for this was comand lline interactive... Any suggestions .. -- Gregory Machin [EMAIL PROTECTED] www.linuxpro.co.za -- Gregory Machin [EMAIL PROTECTED] www.linuxpro.co.za
need to return exit code
Hi My perl script is called by a bash script, used in a compile / build env. But the bash script is not seeing my script's exit and is timming out and continuing ... How can I pass a standard exit code 0 = success 1 = fail to the operating system / calling script. Many Thanks -- Gregory Machin [EMAIL PROTECTED] www.linuxpro.co.za
Re: need to return exit code
thanks for the support guys .. have a grate day .. On 7/31/06, Prabu [EMAIL PROTECTED] wrote: Gregory Machin wrote: Hi My perl script is called by a bash script, used in a compile / build env. But the bash script is not seeing my script's exit and is timming out and continuing ... How can I pass a standard exit code 0 = success 1 = fail to the operating system / calling script. Many Thanks Hello, Hope this is something you are looking for... #!/bin/sh echo Call Perl Program; perl pro.pl val=$?; if [[ $val == 0 ]] then echo Success $val; else echo Fail $val; fi The $? will contain the exit status of the perl program(command). -- Prabu.M.A When I was born I was so surprised I didnt talk for a period and half -Gracie Allen -- Gregory Machin [EMAIL PROTECTED] www.linuxpro.co.za
regex and parsing config file directives..
Hi. Sorry to bother but I can't get this script to work.. It is supposed to parse the openvpn config, 1) any line starting with a ; is to be ignored 2) all directives are written to a hash where the key is the directive and the value is the value of the directive . 3) if the directive is present but no value is set then the key must be set to the directive and the value must be set to defined or the same value as the key.. this is the script so far #!/usr/bin/perl # use strict; # vars my @tmp_load_file; my @tmp_directive; my %directive; # sub get_config_file { my $line; #used in while for outputing each line. print opening config file for processing\n\n; open(IN, /etc/openvpn/client.conf); while (IN){ if (( $_ =~ /^#/ ) || ( $_ =~ /^\ /) || ( $_ =~ /^\n/) ){ } else { chomp; push(@tmp_directive , $_ ); } } close (IN); } get_config_file; sub config_hash { # regex used in the function ## /.+\s(.+) used to find the option set for that directive. dev tun will return tun my $value ; foreach (@tmp_directive) { #print $_; if ( $_ != /^\;/) { } else { /^([\w|-]+)\s(.+)/ ; print $1 = $2 \n; $directive{$1} = $2 ; }if ( $_ != /^\;/) { } else { /^([\w|-]+)\n/ ; #print $1 = $1 \n; #$value = 1 unless $2; $directive{$1} = $1 ; } } } config_hash ; my $key; my $value;# print \n\n; for $key (keys %directive){ $value = $directive{$key}; print $key = $value\n; } this it the output.. [EMAIL PROTECTED] openvpn]$ perl passconfig.pl opening config file for processing = dev = tun0 proto = tcp remote = 192.168.1.1 1194 resolv-retry = infinite = = = ca = ca.crt cert = greg.crt key = greg.key cipher = AES-128-CBC = verb = 3 = proto = tcp cert = greg.crt dev = tun0 ca = ca.crt key = greg.key remote = 192.168.1.1 1194 verb = 3 cipher = AES-128-CBC resolv-retry = infinite Many Thanks Greg -- Gregory Machin [EMAIL PROTECTED] www.linuxpro.co.za
Re: regex and parsing config file directives..
looks good but my configs don't us = there is just a space ... so could one use my ($key,$value) = split/\ /; to split the kay and the value ? On 7/14/06, Jeff Peng [EMAIL PROTECTED] wrote: Hello, Follow the conditions,the resolving way is not so complicated as yours.I would give my sample way,hope it's useful to you. here is the config file's content: $ cat config.txt ;test file # comment lines IP = 1.2.3.4 PORT = 80 PREFORK_CHILDS = 5 MIN_SPARE_CHILDS here is the sample script: $ cat test.pl use strict; use Data::Dumper; my %hash; open HD,config.txt or die $!; while(HD){ next if /^\s*#|^\s*;/; next if /^\s*$/; my ($key,$value) = split/=/; $key =~ s/^\s+|\s+$//g; $value =~ s/^\s+|\s+$//g; $hash{$key} = $value || 'nodefined'; } close HD; print Dumper \%hash; __END__ Run it and get the result output: $ perl test.pl $VAR1 = { 'PREFORK_CHILDS' = '5', 'IP' = '1.2.3.4', 'MIN_SPARE_CHILDS' = 'nodefined', 'PORT' = '80' }; From: Gregory Machin [EMAIL PROTECTED] To: beginners@perl.org Subject: regex and parsing config file directives.. Date: Fri, 14 Jul 2006 11:18:40 +0200 Hi. Sorry to bother but I can't get this script to work.. It is supposed to parse the openvpn config, 1) any line starting with a ; is to be ignored 2) all directives are written to a hash where the key is the directive and the value is the value of the directive . 3) if the directive is present but no value is set then the key must be set to the directive and the value must be set to defined or the same value as the key.. this is the script so far #!/usr/bin/perl # use strict; # vars my @tmp_load_file; my @tmp_directive; my %directive; # sub get_config_file { my $line; #used in while for outputing each line. print opening config file for processing\n\n; open(IN, /etc/openvpn/client.conf); while (IN){ if (( $_ =~ /^#/ ) || ( $_ =~ /^\ /) || ( $_ =~ /^\n/) ){ } else { chomp; push(@tmp_directive , $_ ); } } close (IN); } get_config_file; sub config_hash { # regex used in the function ## /.+\s(.+) used to find the option set for that directive. dev tun will return tun my $value ; foreach (@tmp_directive) { #print $_; if ( $_ != /^\;/) { } else { /^([\w|-]+)\s(.+)/ ; print $1 = $2 \n; $directive{$1} = $2 ; }if ( $_ != /^\;/) { } else { /^([\w|-]+)\n/ ; #print $1 = $1 \n; #$value = 1 unless $2; $directive{$1} = $1 ; } } } config_hash ; my $key; my $value;# print \n\n; for $key (keys %directive){ $value = $directive{$key}; print $key = $value\n; } this it the output.. [EMAIL PROTECTED] openvpn]$ perl passconfig.pl opening config file for processing = dev = tun0 proto = tcp remote = 192.168.1.1 1194 resolv-retry = infinite = = = ca = ca.crt cert = greg.crt key = greg.key cipher = AES-128-CBC = verb = 3 = proto = tcp cert = greg.crt dev = tun0 ca = ca.crt key = greg.key remote = 192.168.1.1 1194 verb = 3 cipher = AES-128-CBC resolv-retry = infinite Many Thanks Greg -- Gregory Machin [EMAIL PROTECTED] www.linuxpro.co.za -- Gregory Machin [EMAIL PROTECTED] www.linuxpro.co.za
Re: regex and parsing config file directives..
here is basic config All lines starting with ; or # are to be regarded as commented out ... as are ignored.. client ### some of the directives are set jst by there pressence ;dev tap dev tun0 ;dev-node MyTap proto tcp ;proto udp remote 192.168.1.1 1194 ;remote my-server-2 1194 ;remote-random resolv-retry infinite nobind ;user nobody ;group nobody persist-key persist-tun ;http-proxy-retry # retry on connection failures ;http-proxy [proxy server] [proxy port #] ;mute-replay-warnings ca ca.crt cert greg.crt key greg.key ;ns-cert-type server ;tls-auth ta.key 1 cipher AES-128-CBC comp-lzo verb 3 ;mute 20 On 7/14/06, Jeff Peng [EMAIL PROTECTED] wrote: Could you paste your config file here?Then we could look at the situation more clearly. looks good but my configs don't us = there is just a space ... so could one use my ($key,$value) = split/\ /; to split the kay and the value ? -- Gregory Machin [EMAIL PROTECTED] www.linuxpro.co.za
Re: regex and parsing config file directives..
Just to check my understanding and that i'm learning this rite . :-) while(HD){ next if /^\s*#|^\s*;/; ignors any lines with # and ; next if /^\s*$/; ignores lines that start with a space .. my @array = split/\s+/;... puts each value seperated by a space into an array my $key = shift @array; gets the first value, of the array and sets key to this value $hash{$key} = [EMAIL PROTECTED] || 'nodefined'; ... sets the value of the hash to the array ?? } From: Gregory Machin [EMAIL PROTECTED] To: Jeff Peng [EMAIL PROTECTED] CC: beginners@perl.org Subject: Re: regex and parsing config file directives.. Date: Fri, 14 Jul 2006 12:36:55 +0200 here is basic config All lines starting with ; or # are to be regarded as commented out ... as are ignored.. client ### some of the directives are set jst by there pressence ;dev tap dev tun0 ;dev-node MyTap proto tcp ;proto udp remote 192.168.1.1 1194 ;remote my-server-2 1194 ;remote-random resolv-retry infinite nobind ;user nobody ;group nobody persist-key persist-tun ;http-proxy-retry # retry on connection failures ;http-proxy [proxy server] [proxy port #] ;mute-replay-warnings ca ca.crt cert greg.crt key greg.key ;ns-cert-type server ;tls-auth ta.key 1 cipher AES-128-CBC comp-lzo verb 3 ;mute 20 On 7/14/06, Jeff Peng [EMAIL PROTECTED] wrote: Could you paste your config file here?Then we could look at the situation more clearly. looks good but my configs don't us = there is just a space ... so could one use my ($key,$value) = split/\ /; to split the kay and the value ? -- Gregory Machin [EMAIL PROTECTED] www.linuxpro.co.za -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- Gregory Machin [EMAIL PROTECTED] www.linuxpro.co.za
regex and parsing config file directives..
Hi I'm writing a script to pass a config file and put the values in a hash, with the key being the directive and the value bing the options, but some directives don't have options, so in that case i want to store the directive as the value so that for completeness.. i'm using the follwing regex /(.+)[\s+\n](.+)/where $1 is the directive and $2 is the option for the directive user nobody group nobody persist-key persist-tun this is the logic that is suposed to do the work. if ($_ =~ /^persist-key/){ /(.+)[\s+\n](.+)/ ; if ( $2 == '' ) { $_ = $1} ; $directive{persist_key} = $_; } but I still end up with an empty field ... Any ideas.. -- Gregory Machin [EMAIL PROTECTED] www.linuxpro.co.za
Re: perl + ncurses turtorial ?
Thanks for the input ... The first place I looked was on cpan for the modules, and then for the related docs and then googled ... then I posted on this list then I googled more ... m So I have had a better Idea, do you know of a working perl application (GPL / BSD) that I can view the source code.. with menus and windows and popups etc ... Thanks On 7/7/06, JupiterHost.Net [EMAIL PROTECTED] wrote: Gregory Machin wrote: Hi Hello, I'm looking for an perl ncuses tutorial so I can write a remote admin app to work via ssh .. Not really a tutorial but Curses::UI is what you will want to use HTH -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- Gregory Machin [EMAIL PROTECTED] www.linuxpro.co.za
perl + ncurses turtorial ?
Hi I'm looking for an perl ncuses tutorial so I can write a remote admin app to work via ssh .. Many Thanks -- Gregory Machin [EMAIL PROTECTED] www.linuxpro.co.za