Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

fucking bash

Name: Anonymous 2009-08-18 18:48

soup /prog/?
I'm trying to lern bash but i fucking suck, can anyone tell me what the fuck is wrong with this script?
inb4 n00b, linux sucks, ect.


#!/bin/bash
TMPFILE="/tmp/$$"
trap "{ rm -f $TMPFILE; exit 255; }" SIGINT SIGTERM EXIT
touch $TMPFILE
for ((i=100;i<116;i++)); do
{ ping -c1 192.168.1.$i 1>/dev/null & }
if [ "$?" == "0" ];then
echo " ■  192.168.1.$i" >> $TMPFILE
else
echo " ■  192.168.1.$i" >> $TMPFILE
fi
done
sleep 2
clear
cat $TMPFILE
exit 0

also is there a simple bash one liner to determine dhcp hostnames?
(first post in the text boards btw, bbcode works here right?)

Name: Anonymous 2009-08-18 19:07

Your problem seems to be that your using bash.
Hint: man nmap

Name: Anonymous 2009-08-18 19:11

>>2
yeah i know `nmap -sP 192.168.1.0/24` will do the exact same thing, i'm just doing this to get some experience under mah belt.

Name: Anonymous 2009-08-18 19:17

>>3
Then this should already be a learning experience then.

Name: Anonymous 2009-08-18 20:04

You scheduled 16 background processes and immediately logged 16 lines of unrelated garbage.  You also have an irrational love of braces and believe `ect' is a word.

Name: Anonymous 2009-08-18 20:27

your making it harder than it has to be
- make your shit reusable
- never ever use temp files
- use the returned value of your tests as a flag
- use other utilities and pipes extensively that's what they are for

#!/bin/bash

i="192.168.1."

for j in $(seq 100 116) ; do

        PING_CHECK="$(ping -c 1 -W 3 $i$j | grep received | cut -d , -f2 | sed -e 's/received//g')"

        DNS_CHECK=$(host -a $i$j | grep -i host | cut -d " " -f5)

        if [ $PING_CHECK = 0 ] || [ "$DNS_CHECK" = "3(NXDOMAIN)" ]; then

                echo "host $i$j not in DNS or not pingable. Shit sucks"

        fi

done



[17:25][0.33][anon@laptop:~][^100%][1]
$ ./bar
host 192.168.1.100 not in DNS or not pingable. Shit sucks
host 192.168.1.101 not in DNS or not pingable. Shit sucks
host 192.168.1.102 not in DNS or not pingable. Shit sucks
host 192.168.1.103 not in DNS or not pingable. Shit sucks
host 192.168.1.104 not in DNS or not pingable. Shit sucks
host 192.168.1.105 not in DNS or not pingable. Shit sucks
host 192.168.1.106 not in DNS or not pingable. Shit sucks
host 192.168.1.107 not in DNS or not pingable. Shit sucks
host 192.168.1.108 not in DNS or not pingable. Shit sucks
host 192.168.1.109 not in DNS or not pingable. Shit sucks
host 192.168.1.110 not in DNS or not pingable. Shit sucks
host 192.168.1.111 not in DNS or not pingable. Shit sucks
host 192.168.1.112 not in DNS or not pingable. Shit sucks
host 192.168.1.113 not in DNS or not pingable. Shit sucks
host 192.168.1.114 not in DNS or not pingable. Shit sucks
host 192.168.1.115 not in DNS or not pingable. Shit sucks
host 192.168.1.116 not in DNS or not pingable. Shit sucks

Name: Anonymous 2009-08-18 20:29

>>1
A classic case of luser blaming the tool.

Name: Anonymous 2009-08-18 20:46

>>7
No, by "fucking bash" he simply was stating the topic for this thread.

Performing intercourse with bash.

Name: Anonymous 2009-08-18 20:57

>>6
Why the fuck are you parsing output?  That's what the exit status is for.

your making it harder than it has to be
i rony'd

Name: Anonymous 2009-08-18 21:00

>>9 one ... because I already have those bits and lots others in a text file
two... because sometimes you want the contents of that output
and three... lets see what you got

Name: Anonymous 2009-08-18 21:51

OP here, sorry i had to go run some errands  but I figured it out! The background process thingy was setting the error codes to 255 for some reason making it look like everything was down so i took off the trailing '&' (and the {}'s which i didn't even need in the first place)
... but now its slow as fuck :S

>>4
yes, yes it was. although it would be nice if it functioned also.(

>>5
1. making it a background process made it about 10x faster and the '1>/dev/null' should send stdout to /dev/null.
2. There fucking useful
3. Etc.*

>>6
thanks for the tips

>>7
eat me :)

>>8
gawk; talk; date; wine; grep; touch; unzip; touch; gasp; finger; gasp;mount;fsck; more; fsck; fsck; yes; fsck; fsck; gasp; umount; make clean; make mrproper; sleep

Name: Anonymous 2009-08-18 23:26

>>11
W-(

Name: Anonymous 2009-08-19 6:26

>>11
What you're trying to do can't be done with some kind of IPC.
Here's an idea: fire up ping in the background like you did but invoke it in such a way, that on exit ping writes it's status to a file (you can use one output file per process). You will have to figure out how to gather the results.
Just like a map ping <- foldl

Name: Anonymous 2009-08-19 13:28

>>13
over-engineering much?

Name: Anonymous 2009-08-19 14:51

>>14
It's only a freakin' exercise in pointlessness.

Name: Anonymous 2009-08-19 16:03

>>13
Why are you trying to reinvent pipes without understanding them?

Name: Anonymous 2009-08-19 18:58

Why are you trying to implement half of lisp in a buggy way without understanding it?

Name: Anonymous 2009-08-20 4:15

>>16
Good point

Name: ​​​​​​​​​​ 2010-10-24 21:53

Name: Anonymous 2010-12-21 6:05

Name: Anonymous 2010-12-22 19:06

Name: Anonymous 2011-01-31 21:09

<-- check em dubz

Name: tray 2012-03-14 15:39

you better be

Don't change these.
Name: Email:
Entire Thread Thread List