Loading...

Category: Bash/shell

  • The SourceBench 1:53 pm on February 1, 2010 Permalink | Reply
    Tags: jobs, multiple, parallel, process, threading, wait   Posted in Bash/shell

    Simple parallel processing with Bash using “wait” and “jobs” 

    #!/bin/bash
    # this is a simple helper script that can be used when you are in need of running multiple processes at once
    # simply run your command with an ampersand at the end and after this
    # execute forky with the number of parallel processes as argument.
    
    function forky() {
    	local num_par_procs
    	if [[ -z $1 ]] ; then
    		num_par_procs=3
    	else
    		num_par_procs=$1
    	fi
    
    	while [[ $(jobs | wc -l) -ge $num_par_procs ]] ; do
    		sleep 1
    	done
    }
    
    # below is an example - make sure to change this to your needs
    for fname in `ls -1`; do
    	echo "`jobs | wc -l` jobs in spool"
    	echo -e "processing $fname\n"
    	# below should be the command you like to execute. in this example it's a php script that would do something with a file.
    	# important is the & at the end of the command which sends the command to the background
    	php ~/a_script_that_does_something_with_the_file --file=$fname &
    	# after this call the forky function with the amount of parallel processes as parameter
    	forky 5
    done
    
    wait

     
  • The SourceBench 11:52 pm on January 19, 2010 Permalink | Reply
    Tags: dns, , nameserver, ns, whois   Posted in Bash/shell

    Test if a nameserver change is done right 

    # imagine you just updated your whois data so it will point your domain to an other nameserver and you want to know if that worked out
    # this little command lets you know on *nix based machines
    for i in a b c d e f g h i j k l; do dig +short ns domainname.com @$i.GTLD-SERVERS.NET; done

     
  • The SourceBench 9:15 am on December 9, 2009 Permalink | Reply
    Tags: , time machine   Posted in Bash/shell

    command line real-time view of what files Time Machine is copying 

    sudo fs_usage -w -f filesys backupd | grep open

     
  • The SourceBench 11:49 pm on December 6, 2009 Permalink | Reply
    Tags: connections, listening, netstat, ports   Posted in Bash/shell

    Print the number of established and listening connections to your server on port 80 per each IP address 

    netstat -plan|grep :80|grep -E "(EST|LIST)"|awk {'print $5'}|cut -d: -f 1|sort|uniq -c|sort -nk 1

     
  • The SourceBench 11:05 pm on December 4, 2009 Permalink | Reply
    Tags: , , list, sed,   Posted in Bash/shell

    Get a list of urls/domains from a text file 

    sed 's/http/\^http/g' FILENAME | tr -s "^" "\n" | grep http| sed 's/[\ |\\\|\"].*//g' | sed "s/['].*//g" | sort | uniq

     
  • The SourceBench 10:03 pm on December 3, 2009 Permalink | Reply
    Tags: launch application, open,   Posted in Bash/shell

    Start an application from the command line in OSX 

    # use open -a followed by the program name and optionally a file name for an output log file
    open -a /Applications/TextEdit.app logfile.txt

     
  • The SourceBench 9:49 pm on December 3, 2009 Permalink | Reply
    Tags: proxy, socks5, ssh   Posted in Bash/shell

    Simple Socks5 Proxy connection with SSH 

    # Sometimes you want to get a simple proxy to fake your IP or encrypt your connection
    # in case you are surfing in an insecure space. All you need is a server which you can access via ssh.
    # then use the following command to open a ssh proxy connection with this command
    ssh -ND 9999 your_user@your_ssh_remote_host
    # after this you will have SOCKS5 server on localhost port 9999 which you can enter as your browser proxy

     
  • The SourceBench 11:30 pm on November 27, 2009 Permalink | Reply
    Tags: download, mirror, recursive, wget   Posted in Bash/shell

    Download (mirror) an entire website with wget 

    wget \
         --recursive \
         --no-clobber \
         --page-requisites \
         --html-extension \
         --convert-links \
         --restrict-file-names=windows \
         --domains website.org \
         --no-parent \
             http://www.website.org/tutorials/html/
    # found at http://www.linuxjournal.com/content/downloading-entire-web-site-wget

     
  • The SourceBench 1:40 pm on November 27, 2009 Permalink | Reply
    Tags: find, function, , linux, PHP, search   Posted in Bash/shell

    Search for a function definition in a bunch of php files 

    find . -name *.php -exec grep -HE "function FUNCTION_NAME" {} \;

     
  • The SourceBench 3:36 am on November 27, 2009 Permalink | Reply
    Tags: , certificate, crt, csr, key, ssl   Posted in Bash/shell

    Create a self signed SSL Certificate (server.key/pem/csr/crt file) 

    #The following commands will generate you server.key/pem/csr/crt files, needed for working with apache/ssl on port 443. You can replace -days #365 with any value you want.
    openssl genrsa -des3 -rand file1:file2:file3:file4:file5 -out server.key 1024
    openssl rsa -in server.key -out server.pem
    openssl req -new -key server.key -out server.csr
    openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
    #If you plan using valid SSL certificate, signed by thawte for example, then when entering data for creating .csr file, you have to enter valid data, #and then send this file to them. They will return the .crt file.

     
c
compose new post
j
next post/next comment
k
previous post/previous comment
r
reply
e
edit
o
show/hide comments
t
go to top
l
go to login
h
show/hide help
esc
cancel