Hi. I have a server with multiple network ports that need to be tested to a list of destinations. I'm trying to write a scripts to automate this but can't seem to get past an error and could use some help.
I have two test files one contains the ip addresses of the onboard NICs and the other text file has the destinations that I am trying to reach. I read the contents of the files it variables then use them in a ping command. Here is the script so far.
#!/bin/sh
for nic in `cat nic.txt`
do
for dest in `cat dest.txt`
do
echo ping -c2 -I "$nic $dest"
ping -c2 -I "$nic $dest"
done
echo ""
done
The echo command prints out the command just as it should be but the actual ping command errors like I'm not using the command correctly. I can even copy what is echoed and paste it and the ping command works correctly.
I changed the quotes and no dice. I put that echo statement in before the ping command so I could see if the variables were correct because the ping command dosent show me what I put in. So the first line is the echo command and the second line is the output of the ping command. I'm not sure where it is getting the -- - from. It is like the variable is not transfering to that line of the script.
Conoraa688, thanks for that and I will try it once I get it to work. I dont script that often and dont know all that much so thanks for giving me another tool to use.
Please post the actual script you ran. My correction was subtle because it presents two parameters to "ping" not one.
Imho. Corona688's pedantic change to avoid valid Shell constructs, includes the original problem.
There is much variation in the "ping" command and we don't know what Operating System and version you have or exactly what Shell this is.
Can you show us the command-line example which works?
That is the actual script above. The only thing that I changed is the quotes like you suggested. Here is what the output looks like when run. The first line is from the echo and the rest is from ping.
First impresssion is that "ping" does not like the hyphen character in your Shell script. I have read that Plan 9 used a different character set from unix (UTF-8) which could affect quote characters. Also, are you sure that you are running the correct Shell and the correct editor?
There is more than one ancient O/S called Plan 9. I've assumed that you mean the Bell Labs one.
Methyl,
Well, after I took out the quotes, it works fine. Here is the working script. Yes, it is from the Bell Labs version. For some reason when those quotes were in there, it screwed everything up. Thanks for your help!.
#!/bin/sh
for nic in `cat nic.txt`
do
for dest in `cat dest.txt`
do
ping -c2 -I $nic $dest
done
done
I actually thought it was a flavor of Unix but just read a little about it and it does seem different. It's running on an nCUBE box. I tried to PM you the back story but I don't have enough posts.
Unix developed in many directions but those which were difficult to use or had obscure or illogical syntax died. Plan 9 was one of them.
Imho. If you have low-level code expertise the most useful problem to work on is the file size limits in versions of tar and umpteen other unix commands in light of modern tetrabyte filesystems.