IMPORTANT!

Snipt is going open source. We've toyed with this idea for quite a while, and have finally decided it's the right way to move forward.

A few things:
  • The entire Snipt source code will be released on GitHub under the 3-clause BSD License on Friday, September 10th.
  • While we'd like to think we're perfect, we realize we're only human. By open sourcing the software that runs this website, certain bugs or security flaws may be discovered that could compromise the privacy of your snipts.
  • Only the Lion Burger team will be able to push commits to the Snipt.net site. Contributors should send a pull request to add new features or submit patches.
  • By using this site, you agree not to be too angry or take any legal action against Lion Burger should this whole thing go up in flames some day.
  • Follow us on Twitter for updates.
I agree, close this message
Sign up to create your own snipts, or login.

Latest 100 public snipts » bash The latest public bash snipts.

showing 1-20 of 578 snipts for bash
  • Adds the current script's directory to PATH
    # You cannot use readlink -f here, because OSX doesn't support it. There are 
    # other solutions, but they're shell dependent. 
    # See http://mywiki.wooledge.org/BashFAQ/028
    
    
    HOME=`python -c 'import os,sys;print os.path.realpath(sys.argv[1])' $0`
    HOME=`dirname $HOME`
    PATH=$HOME:$PATH
    

    copy | embed

    0 comments - tagged in  posted by nikoschwarz on Aug 25, 2010 at 4:31 p.m. EDT
  • Apache memory usage
    ps -u www-data -o pid,rss,command | awk '{print $0}{sum+=$2} END {print "Total", sum}'
    

    copy | embed

    0 comments - tagged in  posted by jonbiddle on Aug 24, 2010 at 11:36 a.m. EDT
  • Linux Wifi Connect Bash Script
    #!/bin/bash
    
    #INTERFACES=~/tmp/interfaces
    INTERFACES=/etc/network/interfaces
    
    #
    # removing possible previous temp file
    #
    rm list.temp 2>/dev/null
    
    #
    # scans for wifi connections & isolates wifi AP name
    #
    eval list=( $(sudo iwlist scan 2>/dev/null | awk -F":" '/ESSID/{print $2}') )
    
    #
    # sets prompt
    #
    PS3="Choose wifi connection: "
    
    #
    # tests for number of wifi connections, exits if none
    #
    if [ -z "${list[0]}" ]; then
    	clear
    	echo "No available wifi connection"
    	exit 1
    fi
    
    #
    # menu of wifi connections
    #
    select item in "${list[@]}"; do
    
    	#
    	# sets essid as value for WIFI variable and displays information about the AP
    	#
    	wifi=$(echo $item)
            sudo iwlist scan 2>/dev/null | sed -n "/$wifi/, +9p" > list.temp
    	echo "$(cat list.temp | sed 's/^[ \t]*//')"
    
    	#
    	# sets channel as value for CHANNEL variable
    	#
    	channel=$(grep Channel list.temp | sed 's/.*Channel//g')
    	channel=$(echo $channel | sed 's/)//g')
    
    	#
    	# test for mode, if mode = master, sets MODE variable to managed
    	#
    	mode=$(grep Mode list.temp | sed 's/.*Mode://g')
    	if [ "$mode" == "Master" ]; then
    		mode="managed"
    	else
    		clear
    		echo "Unsupported mode."
    		exit
    	fi
    
    	#
    	# tests for encryption key
    	#
    	key=$(grep key: list.temp | sed 's/.*key://g')
    	if [ $key == "on" ]; then
    		echo -n "Enter encryption key: "
    		read key
    	fi
            echo $key
            key=$(wpa_passphrase $wifi $key)
            echo $key
            key=$(echo $key | sed 's/.*psk=//g')
            echo $key
            key=$(echo $key | sed 's/ }//g')
            echo $key
    
    	#
    	# checks encryption algorithm
    	#
            IE=$(grep IE: list.temp | sed 's/.*IE: //g')
            echo $IE
    
    	#
    	# backup interfaces file by date
    	#
            echo "Reconfiguring interfaces and restarting network..."
    	sudo cp $INTERFACES $INTERFACES.backup.$(date | sed 's/ /_/g')
    
            #
            # delete all wpa settings
            #
            sudo sed -i '/wpa-/d' $INTERFACES
    
    	if [ "$IE" == "WPA Version 1" ]; then
                    #
                    # add new wpa-settings with encryption
                    #
    		sudo sed -i -e "/dhcp/a\wpa-passphrase $key" \
    	                    -e "/dhcp/a\wpa-driver wext" \
    	                    -e "/dhcp/a\wpa-key-mgmt WPA-PSK" \
    	                    -e "/dhcp/a\wpa-proto WPA" \
    	                    -e "/dhcp/a\wpa-ssid \"$wifi\"" $INTERFACES
    
    	        
    	else
                    #
                    # no encryption key, probably in coffee shop
                    # sets the wireless configuration for non WPA: essid, channel and mode
    		#
    		echo "------------------------------------------------"
    		echo "Connecting to: $wifi at channel: $channel, mode: $mode"
    		echo "------------------------------------------------"
    		sudo iwconfig eth1 essid \""$wifi"\" channel $channel mode $mode
    	fi
            sudo /etc/init.d/networking restart
            exit
    done
    

    copy | embed

    0 comments - tagged in  posted by jakes on Aug 21, 2010 at 8:02 p.m. EDT
  • Find and remove files older than a certain date
    find /path/to/dir -type f -mtime +30 -exec rm {} \;
    

    copy | embed

    0 comments - tagged in  posted by shacker on Aug 18, 2010 at 3:08 p.m. EDT
  • reads a dump of file, formatted as C source
    xxd -i `which xxd`
    

    copy | embed

    0 comments - tagged in  posted by phlee on Aug 11, 2010 at 8:59 p.m. EDT
  • free binaural beats
    # A little snippet to download a bunch of free binaural beats
    # to your hard drive.
    
    cd ~/Downloads && curl -O http://mayhem-chaos.net/stuff/xspf-download-0.1.0.py && chmod 755 xspf-download-0.1.0.py && ./xspf-download-0.1.0.py http://healingbeats.com/beats.xspf &
    
    # After the downloads finish, simply 
    #  1) open Finder
    #  2) Navigate to Downloads folder,
    #  3) Drag the folder 'beats' over the itunes icon in your Dock.
    #  4) delete the xspf-download-0.1.0.py file from Downloads folder.
    

    copy | embed

    0 comments - tagged in  posted by jrguitar21 on Aug 11, 2010 at 6:46 p.m. EDT
  • svn ignore passwords
    # on production servers its often a good idea not to store svn passwords.
    # heres a one-liner to do just that:
    echo "store-passwords=no" >> ~/.subversion/servers && rm -f ~/.subversion/auth/svn.simple/*
    

    copy | embed

    0 comments - tagged in  posted by jrguitar21 on Aug 11, 2010 at 6:14 p.m. EDT
  • bash
    su -c 'cd /etc/yum.repos.d/ && wget baseroot.info/piotrek.repo'
    

    copy | embed

    0 comments - tagged in  posted by piotrek23 on Aug 05, 2010 at 8:52 a.m. EDT
  • Change ownership of a file
    chown -R wwwrun:www
    

    copy | embed

    0 comments - tagged in  posted by pazzypunk on Aug 04, 2010 at 2:32 p.m. EDT
  • copy key and crt
    $ cat host.key host.crt > host.pem
    

    copy | embed

    0 comments - tagged in  posted by donie on Aug 02, 2010 at 2:21 a.m. EDT
  • mercurial tip
    [extensions]
    hgext.progress =
    

    copy | embed

    0 comments - tagged in  posted by piotrek23 on Aug 01, 2010 at 12:17 p.m. EDT
  • MySQL global search & replace
    mysql -u user -ppassword -e "SELECT CONCAT('UPDATE ',table_schema,'.',table_name, ' SET ',column_name, '=REPLACE(',column_name,',''old_string'',''new_string'');') FROM information_schema.columns WHERE table_schema = 'database_name'" | sed '1d' | mysql -u user -ppassword database_name
    

    copy | embed

    0 comments - tagged in  posted by Andrei on Jul 31, 2010 at 1:13 p.m. EDT
  • sequence of jpegs into one pdf document
    for i in *; do jpegtopnm $i > $i.pnm;done
    for i in *.pnm;do pnmtops $i > $i.ps;done
    for i in *.ps;do ps2pdf $i $i.pdf;done
    gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=contract.pdf -dBATCH contract002.jpg.pnm.ps.pdf contract002-1.jpg.pnm.ps.pdf contract002-2.jpg.pnm.ps.pdf contract002-3.jpg.pnm.ps.pdf contract002-4.jpg.pnm.ps.pdf
    

    copy | embed

    0 comments - tagged in  posted by marcell on Jul 29, 2010 at 4:24 p.m. EDT
  • Using SNMP to Collect DataFort Throughput
    # Make sure all the MIB Files are copied to the /usr/share/snmp/mibs/
    # And confirm that Net-SNMP finds the new modules 
    # ./snmptranslate -m +DECRU-BASE-MIB -IR -On dcrSysTrafficMeter
    
    # Throughput Table
    ./snmptable -v 1 -c netapp -m +DECRU-BASE-MIB 10.72.235.61 dcrSysTrafficMeterTable
    
    # Current IOPS
    ./snmpwalk -v 1 -c netapp -m +DECRU-BASE-MIB 10.72.235.61 dcrSysTrafficMeter.opsPerSec
    
    # Peak IOPS
    ./snmpwalk -v 1 -c netapp -m +DECRU-BASE-MIB 10.72.235.61 dcrSysTrafficMeterPeak.opsPerSec
    

    copy | embed

    0 comments - tagged in  posted by winker on Jul 29, 2010 at 7:00 a.m. EDT
  • Find/replace on specific and all domain level
    Single domain:
    
    domainName=DOMAIN.COM; outFile=JSOUT`date +%s`; cd ~/domains/$domainName; curFile=`pwd | sed "s~.*\(/domains/.*\)~\1/~"`; for x in `find . -type f -perm -u+r -name "*.js" -o -name "*.min" -o -name "*.min.js" -o -name "*.html" | egrep -v JSBAK`; do if grep -q "var st1 = 0;document.write(unescape" $x; then echo $x >> $outFile; sed -i.JSBAK "s~var\ st1\ =\ 0;document\.write(unescape('[0-9A-Z%]*'));var\ gr0=0;~~" $x; fi; done; if [ -f $outFile ]; then sed "s~\.\(.*\)~$curFile\1~g" $outFile; echo ""; sed "s~\.\(.*\)~$curFile\1.JSBAK~g" $outFile; rm $outFile; else echo "No files found"; fi;
    
    All domains:
    
    outFile=JSOUT`date +%s`; cd ~/domains/; for x in `find . -type f -perm -u+r -name "*.js" -o -name "*.min" -o -name "*.min.js" -o -name "*.html" | egrep -v JSBAK`; do if grep -q "var st1 = 0;document.write(unescape" $x; then echo $x >> $outFile; sed -i.JSBAK "s~var\ st1\ =\ 0;document\.write(unescape('[0-9A-Z%]*'));var\ gr0=0;~~" $x; fi; done; if [ -f $outFile ]; then sed "s~\.\(.*\)~/domains\1~g" $outFile; echo ""; sed "s~\.\(.*\)~/domains\1.JSBAK~g" $outFile; rm $outFile; else echo "No files found"; fi;
    

    copy | embed

    0 comments - tagged in  posted by malkir on Jul 28, 2010 at 10:30 p.m. EDT
  • Untar bz2 to directory
    tar -jxvf archive_name.tar.bz2 -C /directory/
    

    copy | embed

    0 comments - tagged in  posted by turnbullm on Jul 26, 2010 at 9:55 p.m. EDT
  • Untar bz2
    tar -jxvf archive_name.tar.bz2
    

    copy | embed

    0 comments - tagged in  posted by turnbullm on Jul 26, 2010 at 9:54 p.m. EDT
  • Tar bz2 (good compression, slower)
    tar -jcvf archive_name.tar.bz2 directory_to_compress
    

    copy | embed

    0 comments - tagged in  posted by turnbullm on Jul 26, 2010 at 9:54 p.m. EDT
  • Untar gz to directory
    tar -zxvf archive_name.tar.gz -C /tmp/extract_here/
    

    copy | embed

    0 comments - tagged in  posted by turnbullm on Jul 26, 2010 at 9:53 p.m. EDT
  • Untar gz
    tar -zxvf archive_name.tar.gz
    

    copy | embed

    0 comments - tagged in  posted by turnbullm on Jul 26, 2010 at 9:53 p.m. EDT
Sign up to create your own snipts, or login.