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 » linux The latest public linux snipts.

showing 1-20 of 181 snipts for linux
  • 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
  • monitor keyboard activity and disables the touchpad
    syndaemon -i 1 -d -k
    

    copy | embed

    0 comments - tagged in  posted by tlevine on Aug 10, 2010 at 5:18 p.m. EDT
  • Iptables map port 8080 to privileged port 80
    sudo iptables -t nat -A PREROUTING -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 8080
    sudo iptables -t nat -A OUTPUT -p tcp -m tcp -d $HOST --dport 80 -j REDIRECT --to-ports 8080
    

    copy | embed

    0 comments - tagged in  posted by Fotinakis on Aug 09, 2010 at 6:02 p.m. EDT
  • mount hfs+ (mac) file system on an external drive as read write in ubuntu (linux). depends on: hfsprogs
    sudo fsck.hfsplus /dev/sdc1
    

    copy | embed

    0 comments - tagged in  posted by defyenterprises on Aug 05, 2010 at 3:15 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
  • Configurar interfaz virtual en Linux
    ; Importante si te quieres comunicar con otra red :D
    
    # ifconfig ethx:1 IP
    

    copy | embed

    0 comments - tagged in  posted by edh on Jul 14, 2010 at 1:18 p.m. EDT
  • Cambiar MAC Adress en Linux
    ; El cambio no es permanente 
    
    # ifconfig ethx down
    # ifconfig ethx hw ether 00:AA:BB:CC:11:22
    # ifconfig ethx up
    

    copy | embed

    1 comment - tagged in  posted by edh on Jul 14, 2010 at 1:05 p.m. EDT
  • Comandos comunes seteando redes locales en linux
    # Donde está la configuración de red? /etc/network/interfaces
    auto eth0
    iface eth0 inet static
    address 192.168.1.100
    netmask 255.255.255.0
    gateway 192.168.1.1
    
    # desde la consola seria
    
    ifconfig - revisar rdatos de red
    ifconfig eth0 {IP} - cambiar el IP local, ejemplo ifconfig eth0 192.168.1.2
    ifconfig eth0 network {IP} - cambiar mascara de red
    
    # extra
    lsb_release -a | saber version del SO de la maquina 
    hostname | saber el nombre de la maquina
    

    copy | embed

    0 comments - tagged in  posted by ecwpa on Jul 09, 2010 at 12:24 p.m. EDT
  • instalacja ekg2
    instalacja libgadu, potem:
    sudo apt-get install libncursesw5-dev
    ./configure --enable-unicode
    make
    sudo make install
    
    
    temat:
    cat /usr/local/share/ekg2/themes/peres2.theme
    message %n<< %g%|%b%2%r%3\n
    chat %4: %|%n%2%3\n
    sent %K%4: %n%|%K%2%3\n
    conference %c %Y%2%n (%y%3%n) has joined %4\n
    

    copy | embed

    0 comments - tagged in  posted by rif on Jun 11, 2010 at 4:29 p.m. EDT
  • application framework - linux install script
    PRODUCT="myproject"
    VERSION="1.0.0"
    FILE="/your/path/to/software/releases/$PRODUCT-$VERSION.tar.gz"
     
    rm -R /opt/app/$PRODUCT-$VERSION
    mkdir /opt/app/$PRODUCT-$VERSION
    cd /opt/app/$PRODUCT-$VERSION
     
    tar xvf $FILE
     
    rm /opt/$PRODUCT-beta
    ln -s /opt/$PRODUCT-$VERSION /opt/$PRODUCT-beta
    

    copy | embed

    0 comments - tagged in  posted by pixeldude on Jun 08, 2010 at 9:19 a.m. EDT
  • ntfs partition format in linux console
    #format a ntfs partition in linux console
    
    mkntfs /dev/sdxx
    

    copy | embed

    0 comments - tagged in  posted by sayajin on May 26, 2010 at 6:57 a.m. EDT
  • linux console partitioning
    #type the following commands as seen below in order...it will all make sense.
    
    mount #display mounted partition
    umount /dev/sdxx #unmount the partition if mounted
    
    fdisk /dev/sdxx #access the selected drive with fdisk
    p #display partition's for current drive
    d #delete available selected partition's
    n #create new partition/s on drive
    p (primary) or e (extended) #select what partition table you want to create
    1-4 #what the number of the partition will be
    
    t #create a new file system on the selected partition
    L #view a list of available file systems
    
    w #to write partition table and file system to drive and exit
    

    copy | embed

    0 comments - tagged in  posted by sayajin on May 26, 2010 at 6:55 a.m. EDT
  • Combine PDFS
    gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=finished.pdf file1.pdf file2.pdf
    

    copy | embed

    0 comments - tagged in  posted by n0dl on May 17, 2010 at 12:50 p.m. EDT
  • CPU Monitoring
    #!/bin/bash
    # by Paul Colby (http://colby.id.au), no rights reserved ;)
    
    PREV_TOTAL=0
    PREV_IDLE=0
    
    while true; do
      CPU=(`cat /proc/stat | grep '^cpu '`) # Get the total CPU statistics.
      unset CPU[0]                          # Discard the "cpu" prefix.
      IDLE=${CPU[4]}                        # Get the idle CPU time.
    
      # Calculate the total CPU time.
      TOTAL=0
      for VALUE in "${CPU[@]}"; do
        let "TOTAL=$TOTAL+$VALUE"
      done
    
      # Calculate the CPU usage since we last checked.
      let "DIFF_IDLE=$IDLE-$PREV_IDLE"
      let "DIFF_TOTAL=$TOTAL-$PREV_TOTAL"
      let "DIFF_USAGE=(1000*($DIFF_TOTAL-$DIFF_IDLE)/$DIFF_TOTAL+5)/10"
      echo -en "\rCPU: $DIFF_USAGE%  \b\b"
    
      # Remember the total and idle CPU times for the next check.
      PREV_TOTAL="$TOTAL"
      PREV_IDLE="$IDLE"
    
      # Wait before checking again.
      sleep 1
    done
    

    copy | embed

    0 comments - tagged in  posted by yvoictra on May 13, 2010 at 8:06 a.m. EDT
  • Copy current playing song to clipboard
    #!/usr/bin/env python
    #
    #       playCopy 1.0 (python script)
    #       
    #       Copyright 2009 Vladimir Kolev <admin@vladimirkolev.com>
    #       
    #       This program is free software; you can redistribute it and/or modify
    #       it under the terms of the GNU General Public License as published by
    #       the Free Software Foundation; either version 2 of the License, or
    #       (at your option) any later version.
    #       
    #       This program is distributed in the hope that it will be useful,
    #       but WITHOUT ANY WARRANTY; without even the implied warranty of
    #       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    #       GNU General Public License for more details.
    #       
    #       You should have received a copy of the GNU General Public License
    #       along with this program; if not, write to the Free Software
    #       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
    #       MA 02110-1301, USA.
    #	
    #	Special thanks to Umang <umang.me@gmail.com> for the changes in the script.
    #	See section 4. in INSTALL file for the changes
    #
    
    
    import os
    import commands
    # python-dbus used for getting the information from Audaicous
    import dbus
    
    # Set show_not to 0 to disable the notifications
    show_not = 1
    
    def cur_song():
    	"""Attempts to find the name of the song playing by checking which music player is running and retreiving the song name from the application.
    	
    	Players currently supported: Rhythmbox, mocp, Exaile, Banshee, Audacious"""
    	if "banshee" in os.popen('ps -A | grep banshee').readline():
    		# Get the banshee artist and title and replace the unneccessery tiles from the string
    		artist = os.popen('banshee --query-artist').readline().replace('artist: ', '').replace('\n', '')
    		title = os.popen('banshee --query-title').readline().replace('title: ', '').replace('\n', '')
    		song = "%s - %s" % (artist, title)
    	elif "exaile" in os.popen('ps -A | grep exaile').readline():
    		# Get the exaile artist and title and replace the unneccessery tiles from the string
    		artist = os.popen('exaile --get-artist').readline().replace('artist: ', '').replace('\n', '')
    		title = os.popen('exaile --get-title').readline().replace('title: ', '').replace('\n', '')
    		song = "%s - %s" % (artist, title)
    	elif "rhythmbox" in os.popen('ps -A | grep rhythmbox').readline():
    		# Get the rhythmbox current playing information and set it to artist
    		song = os.popen('rhythmbox-client --print-playing').readline().replace('\n', '')
    	elif "mocp" in os.popen('ps -A | grep moc').readline():
    		# Get the information from mocp
    		info = commands.getoutput("mocp --info").splitlines()
    		if info == ["State: STOP"]:
    			#If mocp is stopped, then change the artist to Nothing to show
    			song = "moc is stopeed"
    		else:
    			# If there is a song information split it and formatid for the final string
    			artist = info[3].replace('Artist:', '')
    			title = info[4].replace('SongTitle:', '')
    			song = "%s - %s" % (artist, title)
    	elif "audacious" in os.popen('ps -A | grep audacious').readline():
    		 # initialise the dbus
    		 session_bus = dbus.SessionBus()
    		 # create two proxies 
    		 # proxy_obj1 gets integer for the current playing track in the playlist
    		 proxy_obj1 = session_bus.get_object('org.mpris.audacious', '/TrackList')
    		 selecter = dbus.Interface(proxy_obj1, 'org.freedesktop.MediaPlayer')
    		 # store the integer for the playing track so to be sended to proxy_obj2
    		 ct = selecter.GetCurrentTrack()
    		 # proxy_obj2 retrieves the title of the current playing track
    		 proxy_obj2 = session_bus.get_object('org.mpris.audacious', '/org/atheme/audacious')
    		 player = dbus.Interface(proxy_obj2, 'org.atheme.audacious')
    		 # Store the title in the song variable
    		 song = player.SongTitle(ct)
    	elif "listen" in os.popen('ps -A | grep listen').readline():
    		# Get the current song from the commandline interface
    		info = commands.getoutput("listen -c")
    		if info == ["No song playing"]:
    			# If No song playing create song variable with "Listen player is paused"
    			song = "Listen player is not playing"
    		else:
    			# if Listen is playing then create the song variable with the information:
    			song = info.replace("\n", "")
    	elif "quodli" in os.popen('ps -A | grep quodli').readline():
    		# Get the current playing song from the command line
    		info = os.popen('quodlibet --print-playing').readline()
    		song = info.replace('\n', '')
    	elif "bluemindo" in os.popen('ps -A | grep bluemin').readline():
    		# Get the current playing song from the command line
    		info = os.popen('bluemindo --current').readline()
    		song = info.replace('\n', '')
    	elif "jajuk" in os.popen('ps -A | grep jajuk').readline():
    		session_bus = dbus.SessionBus()
    		proxyobj1 = session_bus.get_object('org.jajuk.dbus.DBusSupport', '/JajukDBus')
    		selected = dbus.Interface(proxyobj1, 'org.jajuk.services.dbus.DBusSupport')
    		song = selected.current()
    	else:
    		if show_not == 1:
    			import pynotify
    			pynotify.init("playCopy")
    			ne = pynotify.Notification("playCopy", "\nNo supported player running", "error")
    			ne.show()
    	return song
    
    if __name__ == "__main__":
    	import pygtk
    	import gtk	
    	# Define the clipboard
    	clipboard = gtk.clipboard_get()
    	# Get the song name from cur_song(), copy the string to the clipboard and store it
    	clipboard.set_text(cur_song())
    	clipboard.store()
    	if show_not == 1:
    		try:
    			import pynotify
    			if pynotify.init("playCopy"):
    				n = pynotify.Notification("playCopy", "\n%s" % clipboard.wait_for_text(), "audio-volume-medium")
    				n.show()
    		except:
    			print "You don't have pynotify installed!"
    	
    

    copy | embed

    0 comments - tagged in  posted by vkolev on May 11, 2010 at 3:46 a.m. EDT
  • .htaccess rewrite url
    # check for form/thanks with or without trailing slash,
    # and rewrite to /form?m=thanks
    RewriteRule ^form/thanks(/$|$) /form?m=thanks
    

    copy | embed

    0 comments - tagged in  posted by robertbanh on Mar 30, 2010 at 12:19 p.m. EDT
  • Linux: Dateien nach Inhalt suchen
    find -type f|xargs grep $keyword
    

    copy | embed

    0 comments - tagged in  posted by cbeier on Mar 07, 2010 at 2:23 p.m. EST
  • suchen in linux
    grep -H -r "muster" *
    

    copy | embed

    0 comments - tagged in  posted by toledot on Mar 07, 2010 at 7:06 a.m. EST
  • .htaccess file to lock down files with db or secure in the prefix
    <FilesMatch "^(db|secure).*$">
    deny from all
    </FilesMatch>
    

    copy | embed

    0 comments - tagged in  posted by robertbanh on Mar 02, 2010 at 11:17 a.m. EST
  • Correct permissions for svn files in project
    find -name .svn -exec sudo chmod 777 {} \;
    find $(find -name .svn) -type d -exec sudo chmod 777 {} \;
    find $(find -name .svn) ! -type d -exec sudo chmod 664 {} \;
    

    copy | embed

    0 comments - tagged in  posted by mailo on Mar 02, 2010 at 8:25 a.m. EST
Sign up to create your own snipts, or login.