![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Adding specific text and spaces to each line in a text file | hertingm | Shell Programming and Scripting | 4 | 08-25-2008 02:34 PM |
| parse through one text file and output many | sophiadun | UNIX for Dummies Questions & Answers | 14 | 02-20-2008 06:08 AM |
| Extract text in 2 columns of output file. | Danish Shakil | Shell Programming and Scripting | 2 | 10-19-2007 10:03 AM |
| I want to copy the text output from a 'nohup.out' file. | Iamthe great | UNIX for Dummies Questions & Answers | 3 | 05-01-2007 12:41 PM |
| grep multiple text files in folder into 1 text file? | coppertone | UNIX for Dummies Questions & Answers | 7 | 08-23-2002 02:50 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Ping text file of ip addressese and output to text file
I am basically a scripting noob, I have some programming logic, and I wouldn't post here if my 3 hours of searching actually found something.
So far this is what I have: " #! /bin/ksh List=./pinglist1.txt cat $List | while read ip do Pingable="" ping $ip -n 2 | awk '/100%/ {print "no"}' |read Pingable if [[ "$Pingable" != "no" ]] then print $ip "PINGS">>pingresults.txt else print $ip "DOESN'T PING">>pingresults.txt fi done " pinglist1.txt is just a plain file with IP addresses. I just want the script to ping each IP address and report if it is pinging or not to a text file. Please and thanks. |
|
||||
|
Could you provide the output of your script?
Also, the 'dotslash' isn't necessary in Code:
List=./pinglist1.txt Is the pinglist1.txt file in the same directory as the script? |
|
||||
|
I went ahead and got rid of the ./
and yes, the .txt is in the same directory These are the results: usage: ping [-LRdfmnqrtv] [-T ttl] [-I addr] [-c count] [-i wait] [-l preload] [-p pattern] [-s packetsize] host|[!]@hop1@hop2@...[@|:]dst UX:sh (ping.sh): ERROR: [[: not found UX:sh (ping.sh): ERROR: print: not found usage: ping [-LRdfmnqrtv] [-T ttl] [-I addr] [-c count] [-i wait] [-l preload] [-p pattern] [-s packetsize] host|[!]@hop1@hop2@...[@|:]dst UX:sh (ping.sh): ERROR: [[: not found UX:sh (ping.sh): ERROR: print: not found usage: ping [-LRdfmnqrtv] [-T ttl] [-I addr] [-c count] [-i wait] [-l preload] [-p pattern] [-s packetsize] host|[!]@hop1@hop2@...[@|:]dst UX:sh (ping.sh): ERROR: [[: not found UX:sh (ping.sh): ERROR: print: not found usage: ping [-LRdfmnqrtv] [-T ttl] [-I addr] [-c count] [-i wait] [-l preload] [-p pattern] [-s packetsize] host|[!]@hop1@hop2@...[@|:]dst UX:sh (ping.sh): ERROR: [[: not found UX:sh (ping.sh): ERROR: print: not found |
|
||||
|
Well, I have minimal experience with shell scripting, but from the output, I see that it's erroring that your `ping' syntax is incorrect. Analyzing the script, you have the IP address of the host before `-n 2', which I believe to be incorrect.
Either way, I cannot help with `awk' syntax. |
|
||||
|
Thanks, now I can tell it is running the ping, and I went ahead and modified my code to this now:
#! /bin/ksh List=pinglist1.txt cat $List | while read ip do Pingable="" ping -c 2 $ip | awk '/100%/ {print "no"}' |read Pingable if [ "$Pingable" != "no" ] then print $ip "PINGS">>pingresults.txt else print $ip "DOESN'T PING">>pingresults.txt fi done AND the results: UX:sh (ping1.sh): ERROR: print: not found Do I need to have a print.pl or something uploaded to that directory? |
|
||||
|
Quote:
try echo... Code:
echo "$ip PINGS" >> pingresults.txt else echo "$ip DOESN'T PING" >> pingresults.txt |
| Sponsored Links | ||
|
|