how to kill your bash

I have a wlan router in my LAN where I switched of the WLAN functionality because I have a faster one. Today I wanted to get access to the admin interface of the router. The problem was I forgot the ip adress of the router.
So I’m trying to write a little script which pings all hosts in my ip range and prints out the ip if the host exists.
I came up with this:

    > for i in $(seq 1 255); do 
    > ping -c 1 -q -t 1 192.168.0.$i | grep -A1 -B1 ” 0%” | head -n1
    > done

Which gives me sometinh like:
— ping statistics —
— ping statistics —

Which is enough for my needs.
Problem is that it’s running to slow. So why not send the command to backround using normal ‘&’ operator. 

Another problem is that a for loop like this won’t work

> for i in $(seq 1 5); do
> echo $i &
> done 
-bash: syntax error near unexpected token `;’ 

So I need a workaround that simply send’s the process to backround.
I decided to ‘echo’ the command to bash itself.
for i in $( seq 1 255); do 
    echo “ping -c 1 -q -t 1 192.168.0.$i | grep -A1 -B1 \” 0%\” | head -n 1 &” | /bin/bash

This is real nice because the script starts and ping some host’s. For some reason I don’t understand I then get an
“/bin/bash: fork: Resource temporarily unavailable ” Error
And then suddenly for some reason:
/bin/bash: fork: Resource temporarily unavailable-bash: fork: Resource temporarily unavailable
Snowball:~ cbo$ logout
[Prozess beendet]

So the simple ping command not only crashes but it also kills my bash. 

I believe it might be that fork is getting in trouble because the main program, in this case the for loop, finishes before the inner code is finished.
But why the does it kill my shell ? 😉

Note that when you replace 
echo “ping -c 1 -q -t 1 192.168.0.$i | grep -A1 -B1 \” 0%\” | head -n 1 &” | /bin/bash
echo “ping -c 1 -q -t 1 192.168.0.$i | grep -A1 -B1 \” 0%\” | head -n 1 &” | /bin/bash &
It’s still not working 😉 but it’s not crashing your whole bash.

hope this information is not too useless ;D



Leave a Reply