×
Create a new article
Write your page title here:
We currently have 3,189 articles on s23. Type your article name above or create one of the articles listed here!



    s23
    3,189Articles

    Bash Scripts: Difference between revisions

    Content added Content deleted
    imported>mutante
    mNo edit summary
    imported>mutante
    mNo edit summary
    Line 55: Line 55:
    [[User:mutante|mutante]] 02:33, 25 Feb 2005 (CET)
    [[User:mutante|mutante]] 02:33, 25 Feb 2005 (CET)



    === Schwanzersatzfaktor-Berechnung ===

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

    <pre>
    #!/bin/sh
    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' \
    |awk '{print $3"/1024/3+"}'; df -P -k -x nfs | grep -v 1k \
    | awk '{if ($1 ~ "/dev/(scsi|sd)"){ s+= $2} s+= $2;} END \
    {print s/1024/50"/15+70";}'`|bc|sed 's/\(.$\)/.\1cm/'
    </pre>

    from [http://www.geekpeitsche.de/shell.html]


    [[Category:Programming]]
    [[Category:Programming]]

    Revision as of 21:45, 12 September 2005

    Question from Pastebin

    #!/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
    
    # -----------------
    # I need to display all ips like this to user:
    #
    # 1. 123.123.123.123
    # 2. 22.22.22.22
    # 3. 32.32.32.222
    #
    # Please choose which IP address to use:
    # Prompt user here
    
    
    

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

    Answer

    #!/bin/bash
    
    # IPS=$(ifconfig | awk '/inet/ { print $2 }' | awk -F ":" '{ print $2 }')
    IPS="192.168.23.5 47.45.56.11 189.67.24.21"
    count=1
    
    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 "
    
    
    # ifconfig ...
    

    mutante 02:33, 25 Feb 2005 (CET)


    Schwanzersatzfaktor-Berechnung

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

    #!/bin/sh
    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' \
    |awk '{print $3"/1024/3+"}'; df -P -k -x nfs | grep -v 1k \
    | awk '{if ($1 ~ "/dev/(scsi|sd)"){ s+= $2} s+= $2;} END \
    {print s/1024/50"/15+70";}'`|bc|sed 's/\(.$\)/.\1cm/'
    

    from [1]

    Cookies help us deliver our services. By using our services, you agree to our use of cookies.
    Cookies help us deliver our services. By using our services, you agree to our use of cookies.