Results 1 to 4 of 4

Thread: [HowTo] Bash beliebig erweitern

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2007
    Location
    Austria
    Posts
    1,336

    [HowTo] Bash beliebig erweitern

    Viele von uns benutzen zwar die Bash, weil diese mehr Moeglichkeiten als die Bourne Shell bietet, aber wenige nutzen auch die Moeglichkeiten der Bash.
    Installation nach Wengi ist Bedingung.
    ACHTUNG: die alte /opt/etc/profile vorher sichern!
    Nachdem die Bash mit
    Code:
    ipkg install bash
    installiert wurde und die alte, vorher gesicherte Profile in /opt/etc/profile wieder zurueck gespielt wurde, kann man die bash um beliebige, eigene Befehle selbst erweitern oder ergaenzen. So werden z.Bspl. Ausgaben (STDOUT) in verschiedenen Farben zum Kinderspiel. Selbst ganze Backups kann man mit einem einfachen Befehl erledigen.
    Weiters sind natuerlich auch Aliase moeglich, sowie komplette Ergaenzungen von z.Bspl. bereits vorhandenen Befehlen moeglich. Als Beispiel habe ich den exit Befehl in der Bash ergaenzt.
    Diese Aenderungen stehen in der bashrc - man legt dazu im jeweiligen Heimatverzeichnis diesen File an. Das Heimatverzeichnis fuer admin ist /tmp/local/root
    Code:
    touch .bashrc
    und danach mit scp oder vi die bashrc ergaenzen:
    Code:
    #bashrc file, collection of useful bash extensions
    #Newbiefans bash, mostly overtaken from different sources
    #feel free to copy and modify
    #a good place to get more is http://bashscripts.org
    
    # EXPORTS
    
    #export PS1="[\[\033[1;34m\w\[\033[0m]\n[\t \u]$ "
    #export HISTFILESIZE=3000 # the bash history should save 3000 commands
    export HISTCONTROL=ignoredups #don't put duplicate lines in the history.
    #export PATH
    
    # Define a few Color's
    BLACK='\e[0;30m'
    BLUE='\e[0;34m'
    GREEN='\e[0;32m'
    CYAN='\e[0;36m'
    RED='\e[0;31m'
    PURPLE='\e[0;35m'
    BROWN='\e[0;33m'
    LIGHTGRAY='\e[0;37m'
    DARKGRAY='\e[1;30m'
    LIGHTBLUE='\e[1;34m'
    LIGHTGREEN='\e[1;32m'
    LIGHTCYAN='\e[1;36m'
    LIGHTRED='\e[1;31m'
    LIGHTPURPLE='\e[1;35m'
    YELLOW='\e[1;33m'
    WHITE='\e[1;37m'
    NC='\e[0m'              # No Color
    # Sample Command using color: echo -e "${CYAN}This is BASH ${RED}${BASH_VERSION%.*}${CYAN} - DISPLAY on ${RED}$DISPLAY${NC}\n"
    
    # Source global definitions
    if [ -f /etc/bashrc ]; then
       . /opt/etc/bashrc
    fi
    
    # enable programmable completion features
    if [ -f /etc/bash_completion ]; then
       . /opt/etc/bash_completion
    fi
    
    # ALIAS
    #alias playw='for i in *.wav; do play $i; done'
    #alias playo='for i in *.ogg; do play $i; done'
    #alias playm='for i in *.mp3; do play $i; done'
    #alias backup='dd if=/dev/discs/disc0/part$1 of=/dev/discs/disc1/part$2' #Copy Partition: backup 2 1 (copy part2 to part1)
    alias home='cd /tmp/local/root'
    alias pg='ps aux | grep'  #requires an argument
    alias un='tar -zxvf'
    alias mti='df -hT' #mounted_info
    alias ping1='ping -c 1'
    alias pingx='ping -c $1'  #parameter needed, how often to ping syntax: pingx 3 192.168.x.x
    alias openports='netstat -nape --inet'
    alias ns='netstat -alnp --protocol=inet | grep -v CLOSE_WAIT | cut -c-6,21-94 | tail +2'
    alias du='du -h --max-depth=1'
    alias da='date "+%Y-%m-%d %A    %T %Z"'
    alias la='ls -Al'               # show hidden files
    alias lx='ls -lXB'              # sort by extension
    alias lk='ls -lSr'              # sort by size
    alias lc='ls -lcr'      # sort by change time  
    alias lu='ls -lur'      # sort by access time   
    alias lr='ls -lR'               # recursive ls
    alias lt='ls -ltr'              # sort by date
    alias lm='ls -al |more'         # pipe through 'more'
    alias ls='ls --color=auto -la'
    alias ps='ps axf'
    alias pss='ps axf | grep'
    alias df='df -h'
    alias mc='mc -c'
    alias ipt='iptables -nv -L'
    alias wi='whereis'
    alias n='nano'
    export TERMINFO=/opt/share/terminfo
    
    # FUNCTIONS
    backup ()
    {
      ok1=false
      ok2=false
      if [ -z $1 ] ; then
         echo "No source partition determined"
       else
         ok1=true
      fi
      if [ -z $2 ] ; then
         echo "No target partition determined"
       else
         ok2=true
      fi   
      if [ $ok1 = true ] && [ $ok2 = true ] ; then 
         #check it before!!
         #dd if=/dev/discs/disc0/part$1 of=/dev/discs/disc1/part$2
         echo -e "${GREEN}backup from $1 to $2${NC}"
         ok1=false ; ok2=false
       else
         echo "Syntax; 'backup 2 1' where 2 is partition 2 of the first disc resp. /opt on an asus router"
         echo "and 1 is the target partition of the next disc!"
         echo "Read at http://wl500g.info Thread 'ultimative bash'"
      fi
    }
    
    netinfo ()
    {
      echo "--------------- Network Information ---------------"
      /sbin/ifconfig | awk /'inet addr/ {print $2}'
      /sbin/ifconfig | awk /'Bcast/ {print $3}'
      /sbin/ifconfig | awk /'inet addr/ {print $4}'
    
      #/sbin/ifconfig | awk /'HWaddr/ {print $4,$5}'
      echo "---------------------------------------------------"
    }
    
    spin ()
    {
      echo -ne "${RED}-"
      echo -ne "${GREEN}\b|"    
      echo -ne "${BLUE}\bx"
      sleep .02
      echo -ne "${RED}\b+${NC}"
    }
    
    function _exit() #run upon exit of bash
    {
      echo -e "${RED}Leaving bash - See you soon honey, take care${NC}"
    }
    trap _exit EXIT
    
    #start screen
    clear
    for i in `seq 1 15` ; do spin; done
    echo -ne "${GREEN} Bash on Asus-Routers ${NC}" 
    for i in `seq 1 15` ; do spin; done ; echo
    echo -e "Kernel Information: " `uname -a`
    echo -e ${LIGHTBLUE}`bash --version`
    echo -ne "Hello $USER today is "; date
    echo -e "${GREEN}"; cal
    echo -ne "${CYAN}"; netinfo
    echo -ne "${LIGHTBLUE}Uptime for this router at"; uptime
    for i in `seq 1 15` ; do spin; done
    echo -ne "${GREEN} http://wl500g.info ${NC}"
    for i in `seq 1 15` ; do spin; done
    echo
    Die Bash startet man mit: bash von der Komandozeile
    Man verlaesst die Bash mit: exit
    Welche Shell wird soeben benutzt: echo $0

    Fast haette ich vergessen - natuerlich im Flash speichern mit:
    Code:
    flashfs save
    flashfs commit
    flashfs enable
    reboot
    Natuerlich kann jeder die bash beliebig erweitern - ich wuerde mich freuen einige nuetzliche Erweiterungen hier zu finden.
    Die neuen Befehle und Aliase usw. bitte dem File entnehmen - diese sind eigentlich selbsterklaerend.

    Anregungen und Ergaenzungen, Fehlerberichte, Korrekturen sind natuerlich wie immer gerne willkommen!
    have fun
    newbiefan
    Last edited by carterb; 02-11-2009 at 09:37.
    Alle HowTo's, all howto's

    RT-N16 1.9.2.7-rtn-r3121, Samba, VSFTP, Lightthpd, PHP, Perl, MySQL, Serendipity, Aria2web, HDD 640GB
    RT-N66U, 16GB MicroSD/ 2 Partitions, 2,5" HDD 1TB, running with Merlin's FW and Entware, 16 Mbit A1,
    Netgear DGND 3700V2, QNAP TS119PII 4 TB, QNAP TS209 2 TB Raid1, Backup Synology DS107+ 1 TB, HP CP1515n

Similar Threads

  1. Âîïðîñû ïî ñêðèïòàì íà bash (shell)
    By Mam(O)n in forum Russian Discussion - РУССКИЙ (RU)
    Replies: 126
    Last Post: 23-12-2014, 15:35
  2. ipkg-Web-Managment cgi-bin Script von NSLU2 auf WL-HDD + ASUS umbauen
    By WLAN-Fan in forum German Discussion - Deutsch (DE)
    Replies: 62
    Last Post: 03-01-2011, 17:08
  3. [HOWTO] WL-500g bridgen met Tele2 / DV-201AMR
    By Chemist in forum Dutch Discussion - Nederlands
    Replies: 2
    Last Post: 29-09-2010, 17:20
  4. Reichweite erweitern
    By Pedalo in forum German Discussion - Deutsch (DE)
    Replies: 2
    Last Post: 24-10-2007, 14:25
  5. Can I give root the bash shell? Savely...?
    By mumsoft in forum WL-700g Q&A
    Replies: 0
    Last Post: 08-08-2007, 14:10

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •