Latest 100 public
snipts » bash
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
-
∞ Apache memory usage
ps -u www-data -o pid,rss,command | awk '{print $0}{sum+=$2} END {print "Total", sum}' -
∞ 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
-
∞ Find and remove files older than a certain date
find /path/to/dir -type f -mtime +30 -exec rm {} \;
-
∞ reads a dump of file, formatted as C source
xxd -i `which xxd`
-
∞ 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.
-
∞ 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/*
-
∞ bash
su -c 'cd /etc/yum.repos.d/ && wget baseroot.info/piotrek.repo' -
∞ Change ownership of a file
chown -R wwwrun:www
-
∞ copy key and crt
$ cat host.key host.crt > host.pem -
∞ mercurial tip
[extensions] hgext.progress =
-
∞ 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
-
∞ 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
-
∞ 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
-
∞ 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;
-
∞ Untar bz2 to directory
tar -jxvf archive_name.tar.bz2 -C /directory/
-
∞ Untar bz2
tar -jxvf archive_name.tar.bz2
-
∞ Tar bz2 (good compression, slower)
tar -jcvf archive_name.tar.bz2 directory_to_compress
-
∞ Untar gz to directory
tar -zxvf archive_name.tar.gz -C /tmp/extract_here/
-
∞ Untar gz
tar -zxvf archive_name.tar.gz


