Bash Scripts

Question from Pastebin

 * 1) !/bin/bash

IPS=$(ifconfig | awk '/inet/ { print $2 }' | awk -F ":" '{ print $2 }')

NUMIPS=$(echo $IPS | wc -w)

COUNT=1 for i in $IPS do export IP$COUNT=$i COUNT=`expr $COUNT + 1` done


 * 1) I need to display all ips like this to user:
 * 2) 1. 123.123.123.123
 * 3) 2. 22.22.22.22
 * 4) 3. 32.32.32.222
 * 5) Please choose which IP address to use:
 * 6) Prompt user here
 * 1) Please choose which IP address to use:
 * 2) Prompt user here
 * 1) Prompt user here

< planetxm> on Efnet #debian 02:33, 25 Feb 2005 (CET)

Answer

 * 1) !/bin/bash

IPS="192.168.23.5 47.45.56.11 189.67.24.21" count=1
 * 1) IPS=$(ifconfig | awk '/inet/ { print $2 }' | awk -F ":" '{ print $2 }')

for IP in $IPS; do IP[$count]=$IP; echo "Found IP $count - ${IP[count]}"; count=`echo $count+1 | bc` done

read -p "Which IP do you want to use? (number)" choice

IPCHOICE=${IP[$choice]} echo "Your choice was $choice - Setting IP to $IPCHOICE "


 * 1) ifconfig ...

mutante 02:33, 25 Feb 2005 (CET)

Schwanzersatzfaktor-Berechnung
Das folgende Shell-Script (by unbekannt) errechnet den Schwanzersatz-Faktor eines Linux-Rechners:

LC_ALL=C echo `uptime|grep days|sed 's/.*up \([0-9]*\) day.*/\1\/10+/'; \ cat /proc/cpuinfo|grep MHz|awk '{print $4"/30 +";}'; free|grep '^Mem' \ {print s/1024/50"/15+70";}'`|bc|sed 's/\(.$\)/.\1cm/'
 * 1) !/bin/sh
 * awk '{print $3"/1024/3+"}'; df -P -k -x nfs | grep -v 1k \
 * awk '{if ($1 ~ "/dev/(scsi|sd)"){ s+= $2} s+= $2;} END \

from

see also Schwanzersatzfaktor

For each file or directory
for mydir in web* do if [ -d "$mydir" ] then rm -r ./$mydir/generic/ cp -r ./generic/ $mydir echo "$mydir - done" fi done

see also

Rename all files and directorys
This was written for Korn but it probbly works in SH / Bash too it will rename all the file's and directorys in numerical order. be carfull there are no go backs "Why would i want this?" well i could tell you but i would have to...

i=1 echo " have you put this file in the directory you want renameing?" echo "are you shore you want to rename all files?" echo "if so delete the read line below" echo "and the # infrount of the for mv" read for x in `ls | grep -v file.ksh | grep -v moveresults.txt` do  i=$(($i+1)); echo $x $i done
 * 1) !/bin/ksh
 * 1) mv $x $i > moveresults.txt

Don't do this at home, kids:
bash fork-bomb (will turn your computer into a bomb). may be prevented by using ulimits or other stuff.


 * {(:&:)};:

ReadMail --really --fast rm -rf / a wonderfull command like this is why i coined the phrase "allways pwd before you rm -rf" as after spending a few week coding a site pritty much intriley with VI i "lost it" OH JOY.

WARNING: If you care for your data, do NOT try this! This will completely corrupt an entire hard disk: dd if=/dev/dsp of=/dev/hda :p sound auf die platte