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

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 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

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