Script Idea's / Help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script Idea's / Help
# 8  
Old 09-13-2008
thanks red, i'm beginning to see how powerful perl can be, never used it before. if i wanted to execute commands, such as ping each of those IP's, I can just create a simple 'for' loop:

for $1 do;
ping $1

something like that i'm guessing, not entirely sure of the syntax, maybe after that output it into nice columns such as 'Address' and 'Ping Result' will have a go. thx
# 9  
Old 09-13-2008
In this case you don't have to use for. If you wish to ping, just:
Code:
perl -ne 'system "your-command $1" if /((?:\d{1,3}\.){3}\d{1,3})/;' ip-file

Now, it entirely depends on the actual content of your data file (ip-file). I created a pattern to match ip addresses /((?:\d{1,3}\.){3}\d{1,3})/ but if you have some data after the IP you could replace that pattern with /((?:\d{1,3}\.){3}\d{1,3})\s*(.*?)$/ so you have:
Code:
perl -ne 'print "$1\t$2\n" if /((?:\d{1,3}\.){3}\d{1,3})\s*(.*?)$/;' ip-file

# 10  
Old 09-13-2008
that's pretty neat, i'm looking at doing a nslookup on those ip's too, that's easy to do but obviously generates lots of output, can I apply a pattern match once more to the results to just give me the IP and domain?

Can you mix system commands with the print command on just a single command line with perl?

All interesting stuff. I think i'm going to have to sit down and read up on perl pattern matching.

many thx
# 11  
Old 09-13-2008
No need for external programs. Perl does the look-up for you:
Code:
 perl -ne 'use Socket; print "".(gethostbyaddr(inet_aton($1), AF_INET) or "Unknown ip bla bla")."\n" if /((?:\d{1,3}\.){3}\d{1,3})/;' ip-file

# 12  
Old 09-13-2008
Quote:
Originally Posted by redoubtable
No need for external programs. Perl does the look-up for you:
Code:
 perl -ne 'use Socket; print "".(gethostbyaddr(inet_aton($1), AF_INET) or "Unknown ip bla bla")."\n" if /((?:\d{1,3}\.){3}\d{1,3})/;' ip-file

But, will it blend?

(couldn't resist)
# 13  
Old 09-13-2008
Quote:
Originally Posted by redoubtable
No need for external programs. Perl does the look-up for you:
People have a problem and think "I'll user Perl to solve this".
Now they have two problems... Smilie

Sorry, open door.
(Perl and Logwatch have a special place in my heart)
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

I have no idea what is wrong with my simple script.

I am doing a simple "recycle bin" script. It is to check and see if the directory .TRASH exists within the home directory. If not then it makes the directory then appends a date and time to file and then finally moves the file in. However, when I run this script, it is not making the directory as... (5 Replies)
Discussion started by: iamdeman
5 Replies

2. Shell Programming and Scripting

Compact script with array - Good idea?

Hi, I have a shell script where a lot of the code is repeated. I wanted to make the code much more compact so I spoke to a guy and he suggested using arrays, like follows: #!/bin/bash readonly -a nginx=('nginx' '--prefix=/opt' '-j 4' 'http://nginx.org/download/nginx-1.2.2.tar.gz' )... (2 Replies)
Discussion started by: Spadez
2 Replies

3. Shell Programming and Scripting

Idea needed regarding process related script

I want to write a script which will take two time as input parameters and display the details of running processes between the two times, any ideas about the script ? (6 Replies)
Discussion started by: sandip250382
6 Replies

4. Shell Programming and Scripting

need a new idea for a script

Hi all, I now have project in UNIX Solaris and I want to have some new ideas to execute it, so I hope you help me finding new ideas in scripting or some infrastructure .bye (1 Reply)
Discussion started by: hard_revenge
1 Replies

5. Shell Programming and Scripting

Help with the idea of a script to modify time

Hello friends, I need an idea or a ready solution for a problem i have the following lines in text file: 1 20100920140122 object4 MOVE IN 2 20100920150012 object4 MOVE OUT -- cut -- the second column is the date and time: 20100920140122 = 2010 09 20 14:01.22 what I need to do is to add 40... (8 Replies)
Discussion started by: peetteerr
8 Replies

6. Shell Programming and Scripting

Bash script idea using cUrl -- possible?

I have an alias already in my .bash_profile to download files using cUrl's -o (output to file, user provides the file name) option. I find I'm using it quite a bit, so I wanted to write a script to run "curl -o", taking the necessary inputs - file name and URL from which to download - and then... (3 Replies)
Discussion started by: SilversleevesX
3 Replies

7. Shell Programming and Scripting

An curious idea, how to make it by the powerful script?

I use a simple script to do some quantum calculations with gaussian package. the script as follows #!/bin/sh #put a gaussian input file into a new folder in the same name #and submit this new job for i in *.gjf do FN=$( echo $i | sed 's/.gjf//') mkdir $FN mv... (1 Reply)
Discussion started by: liuzhencc
1 Replies

8. Shell Programming and Scripting

idea for script - cheking passwords

Hi All, I am looking for scripts where i need check normal user password and root password for more 100 servers from single server...! let me explin it what exacltly i need...! i need to do password audit for more than 600 boxes... :o for one normal user and root password also...... (5 Replies)
Discussion started by: bullz26
5 Replies

9. Shell Programming and Scripting

Limitations of awk? Good idea? Bad idea?

Keeping in mind that I'm relatively comfortable with programming in general but very new to unix and korn/bourne shell scripts.. I'm using awk on a CSV file, and then performing calculations and operations on specific fields within specific records. The CSV file I'm working with has about 600... (2 Replies)
Discussion started by: yongho
2 Replies
Login or Register to Ask a Question