I have a log file with several entries which need to be converted in a different format:
A)
log "tcp://1.2.3.4:80"
should be translated to --> Logged this from host 1.2.3.4 port 80
B)
log "tcp://1.2.3.4:*" --> Logged this from host 1.2.3.4
C)
log "tcp://1.2.3.4:80,8080" -->
Logged this from host 1.2.3.4:80 port 80
Logged this from host 1.2.3.4:80 port 8080”
D)
log "tcp://1.2.3.4:80-101" --> Logged this from host 1.2.3.4 range 80 101
.................................................................................................
Could you please guide me on this?
Best Regards.
Last edited by morningSunshine; 03-29-2010 at 08:34 AM..
Reason: Updated: To present the actual thought.
I know basic scripting only. Honestly, I am looking at each line right now to understand what it means. Please, if it's possible, can you remark on regex used here.
Also, I checked this script. There are some points I observed during testing:
a. When I execute the script with parameter of 'log tcp://1.2.3.4:80', it throws syntax error.
b. There's no check on IP octet / values; i.e. if we give an i/p of 1.2.3.4.5.6.7.8.9.0, then it will be printed as is.
c. When there are more than 2 ports, the second line puts p2, p3 n so on together, instead of on separate lines.
d. There are 100s of entries in a log file, so instead of feeding an IPort one by one, I want to automate it.
e. How can I add more conditional checks in the script. For example, if I see a record -> log tcp://1.2.3.4:3389 -> then I'd want to put it as -> RDP from home system 1.2.3.4 port 3389.
f. is there a way without regex :-P
Update:
I read the regex and just wanted to add what I understood from the script components above. Running the script for 2 ports -> log tcp://1.2.3.4:100-110:
Best Regards.
Last edited by morningSunshine; 03-29-2010 at 06:16 PM..
elif I=$(expr index $P ',')
then # case C echo -e "$IP port ${P:0:$((I-1))}\n$IP port ${P:$I}"
when there are more than 2 ports separated by comma, the logic does not work. For example, for tcp://1.2.3.4:10,20,30, this is returned
Logged this from host 1.2.3.4 port 10
Logged this from host 1.2.3.4 port 20,30
Secondly, is there a way I can take out 'tcp' in a var instead of removin it. Then I think I will be able to put an -> if [ "$var" eq "tcp" ] then do the flow1 else do flow2...
Here is a powershell script to use restful API to create ticket in our ticketing tool. Can anyone please convert it to a shell script sothat, I can run it in Unix servers,
below is the code:
$body = @{
Customer= ''test'
Summary= 'test summary'
Impact= '4-Minor/Localized'
... (2 Replies)
Hi Guys
I am having a perl script that fetches exclude list from a unix client and I trying it to convert it to shell script but I am having issues please help me...
#!/usr/bin/perl
use strict;
use warnings;
use Getopt::Std;
# To turn on debuging (i.e. more information) specify... (29 Replies)
Hello all,
I am working on a perl script which will read weblogic logfile and send the error messages to Zenoss Monitoring tool. At present the script works and it can able to send the error messages to Zenoss. The problem comes when the logrotate has been applied to the weblogic log file. At... (3 Replies)
Hi,
I have some files being sent to me that have dates in them in this format:
from
1/8/2011 15:14:20
and I need the dates in this format (mysql date format)
To
2011-01-08 15:14:20
all I have so far is the regexp that detects the format:
sed -r -e 's@\1/\2/\3\4\5\6]::$@do... (7 Replies)
hi Gurus,
Need to pick your brains on this minor script project.
I would like to continuously monitor a log file with sample log messages as below, and if PSOldGen percentage is either 99% or 100% for consecutively 10 times, alert someone.
{Heap before gc invocations=46516:
PSYoungGen ... (6 Replies)
Request if some one could provide me shell script that converts the below "input file" to "CSV format file" given
Name Domain Contact Phone Email Location
----------------------- ------------------------------------------------ ------- ----- ---------------------------------... (7 Replies)
I have a file say "codefile" here ,contains data like this
Hi! How are you?
I need to covert this data into stram of equivalant ASCII values
I wrote follwoing script.
#!/bin/bash
while read -n1 char
do
printf "%d" \'$char
done < codefile
this gives me output
... (4 Replies)
I have a ping script I use on an old Open Step box (I guess its closely related to Mac OS X) and it runs fine, but now I built a system as a backup with Ubuntu 8.10 client and the script needs to be adapted a bit. Can anyone see where or how this needs to be done? The script starts and assigns the... (14 Replies)