Useful scripts

This is the first script I've ever written. It's not that pretty, it isn't overly user friendly, and I borrowed [stole] a lot of it from taz - http://forums.freebsd.org/showpost.php?p=194445&postcount=5

It is based on taz's script but allows me to quickly set up different VirtualBox VMs without having to edit the script:

Code:
#!/bin/sh

#-----------------------------------------------------------------------
#CONFIG
#-----------------------------------------------------------------------

echo "Type name of new VM:" 
read vmName

echo "Type full path for new VM:"
read hdPath

echo "Type VM disk size in megabytes:"
read hdSize

echo "Type amount of RAM to use in megabytes:"
read ramSize

echo "Type amount of RAM for GPU to use in megabytes:"
read gpuRamSize

echo "Type VM OS Type:"
read osType

echo "Type full path to guest installtion media or ISO:"
read guestISO

echo "Type host network interface name:"
read nic

#create folder for virtual hard disk image
if [ ! -d $hdPath ]
then 
    mkdir $hdPath
fi

#-----------------------------------------------------------------------
#CREATE
#-----------------------------------------------------------------------

#create a new virtual hard disk image.
VBoxManage createhd --filename $hdPath/$vmName.vdi --size $hdSize

#create a new XML virtual machine definition file
VBoxManage createvm --name $vmName --ostype $osType --register

#add an IDE controller with a DVD drive attached, and the install ISO inserted into the drive. Set "--medium none" to detach all.
VBoxManage storagectl $vmName --name "IDE Controller" --add ide
VBoxManage storageattach $vmName --storagectl "IDE Controller" --port 0 --device 0 --type hdd --medium $hdPath/$vmName.vdi
VBoxManage storageattach $vmName --storagectl "IDE Controller" --port 1 --device 0 --type dvddrive --medium $guestISO

#set boot order
VBoxManage modifyvm $vmName --boot1 dvd --boot2 disk --boot3 none --boot4 none

#set I/O APIC support
VBoxManage modifyvm $vmName --ioapic on

#set the amount of RAM
VBoxManage modifyvm $vmName --memory $ramSize

#set the amount of RAM for virtual graphics card
VBoxManage modifyvm $vmName --vram $gpuRamSize

#set network mode(briged,NAT...)
VBoxManage modifyvm $vmName --nic1 bridged --bridgeadapter1 $nic

#enable USB support
VBoxManage modifyvm $vmName --usb on

#enable sound
VBoxManage modifyvm $vmName --audio oss --audiocontroller ac97

I decided not to make it too fancy, requiring user to write full paths because the default machine directory may vary from machine to machine.
 
Here are some really really simple ones I used before as a basis for some of my other more specific scripts;

This one just check online status using tcp connect; returns online/offline.
Code:
#!/bin/sh
result="offline"
for i in 1 2 3; do      
        /usr/local/bin/netcat -w 5 -z www.google.com 80 2>/dev/null
        if [ $? = "0" ]; then
    result="online"
                break
        fi
done
echo $result

This one uses above script; It checks every 5 min for external IP and compares with last stored IP in a file. If it changes, send me an email and store new IP as well as date of change. Over time you get a bunch of different IPs you ever used (if you aren't on static that is).

Code:
#!/bin/sh
test=`$HOME/bin/test-if-online`
if [ $test = "online" ]; then
        current_IP=`tail -1 /var/tmp/current_ip_address.tmp | awk '{print $3}'`
        new_IP=`/usr/local/bin/curl -s ifconfig.me/ip`
        if [ $current_IP != $new_IP ]; then
                current_index=`tail -1 /var/tmp/current_ip_address.tmp | awk '{print $1}'`
                new_index=`expr $current_index + 1`
                new_date=`date "+%Y-%m-%d_%H.%M"`
                echo "$new_index $new_date $new_IP" >> /var/tmp/current_ip_address.tmp
                # -- Send mail
                tail -1 /var/tmp/current_ip_address.tmp | /usr/local/sbin/ssmtp me@gmail.com
        fi
fi

This one for ports, doesn't need explaining
Code:
#!/bin/sh
#update
/usr/local/bin/svn update /usr/ports
#any new?
pkg version -o -l \< | sed 's/[ <]//g' | tee $HOME/newports.001
#any vulns?
pkg audit -F | tee /var/tmp/portaudit_report.tmp
#any new updating?
pkg updating -d $(date -j -f "%s" "$(pkg query -a %t | sort | tail -1)" "+%Y%m%d")

One liner that shows total amount used by zfs snapshots on whole pool (not sure if there's an actual command for this)

Code:
#!/bin/sh
echo "$(zfs get -t filesystem -r -H -p usedbysnapshots zpool | awk '{print $3}' | awk '{total = total + $1}END{print total}') \
        / 1024 / 1024 / 1024" | bc
 
Reinstalling FreeBSD and the ports and the updates can become a real pain in the ass. I wrote this script up to assist me with exactly that. This script makes clang the default compiler, applies optimizations to make.conf, installs updates via freebsd-update and updates the port tree with portsnap, installs xorg, i3 window manager, installs transmission, install firefox (or chromium), installs the linux base files, installs and sets up flash player 11, configure xorg, and configure rc.conf to enable hald,dbus and the linux compatibility layer. It also installs utilities like subversion, wget, nano, bash, portmaster and portupgrade. Tested on FreeBSD 9.1 RC3 install. :)

fbsd_setup.sh
Code:
#!/bin/sh
#By Naveen Mathew of the year 1998! :p

echo 'Configuring make.conf ....'
#Lets get rid of God forsaken gcc...
echo 'Changing default compiler from gcc to clang llvm ....'
echo '#Use the clang llvm compiler instead of gcc' >> /etc/make.conf
echo 'CC=clang' >> /etc/make.conf
echo 'CXX=clang++' >> /etc/make.conf
echo 'CPP=clang-cpp' >> /etc/make.conf

#Here we start optimizing
echo 'Adding optimization flags ....'
echo ' ' >> /etc/make.conf
echo '#Optimizations' >> /etc/make.conf
echo 'CFLAGS=-O2 -pipe -fno-strict-aliasing' >> /etc/make.conf
echo 'COPTFLAGS=-O2 -pipe -funroll-loops -ffast-math -fno-strict-aliasing' >> /etc/make.conf
echo 'OPTIMIZED_CFLAGS=YES' >> /etc/make.conf
echo 'BUILD_OPTIMIZED=YES' >> /etc/make.conf
echo 'WITH_OPTIMIZED_CFLAGS=YES' >> /etc/make.conf
echo '#Compiler options and optimizations added by the Jarvian OS configuration script' >> 
/etc/make.conf

#Update the system and ports tree
echo 'Updating system via freebsd-update ....'
freebsd-update fetch install
echo 'Updating ports tree ....'
cd /usr/ports && portsnap fetch update

#Installation of applications
echo 'Installing basic GUI applications ....'
cd /usr/ports/x11/xorg && make BATCH=Yes install clean
cd /usr/ports/x11-wm/i3 && make BATCH=Yes install clean
cd /usr/ports/x11/dmenu && make BATCH=Yes install clean
cd /usr/ports/x11/i3status && make BATCH=Yes install clean

echo 'Installing utilities ....'
cd /usr/ports/devel/subversion && make BATCH=Yes install clean
cd /usr/ports/ftp/wget && make BATCH=Yes install clean
cd /usr/ports/editors/nano && make BATCH=Yes install clean
cd /usr/ports/shells/bash && make BATCH=Yes install clean
cd /usr/ports/ports-mgmt/portmaster && make BATCH=Yes install clean
cd /usr/ports/ports-mgmt/portupgrade && make BATCH=Yes install clean

echo 'Installing everyday applications ....'
cd /usr/ports/net-p2p/transmission25 && make BATCH=Yes install clean #Transmission25 because the 
other one is broken...
cd /usr/ports/multimedia/vlc && make BATCH=Yes install clean
#Choose either one. Or install both :p
#If you prefer Chromium, comment the Firefox line and uncomment the Chromium line
#cd /usr/ports/www/chromium && make BATCH=Yes install clean #Chromium line
cd /usr/ports/www/firefox && make BATCH=Yes install clean #Firefox line

#Install linux base files and flash
echo 'Installing and setting up Linux base files and flash ....'
cd /usr/ports/emulators/linux_base_f10 && make BATCH=Yes install clean
cd /usr/ports/www/nspluginwrapper && make BATCH=Yes install clean
cd /usr/ports/www/linux-f10-flashplugin11 && make BATCH=Yes install clean
mkdir /usr/local/lib/browser_plugins
cd /usr/local/lib/browser_plugins && ln -s 
/usr/local/lib/npapi/linux-f10-flashplugin/libflashplayer.so
echo ''
echo 'Activating linux module with kldload ....'
kldload linux
echo 'Installing flash player plugin for user ....'
nspluginwrapper -v -a -i
echo ''

#Configure installed programs
echo "Configuring Xorg ...."
echo ' ' >> /etc/rc.conf && echo '#Added by Jarvian OS configuration script" >> /etc/rc.conf
echo 'hald_enable="YES"' >> /etc/rc.conf
echo 'dbus_enable="YES"' >> /etc/rc.conf
echo 'linux_enable="YES"' >> /etc/rc.conf
Xorg -configure
cp ~/xorg.conf.new /etc/X11/xorg.conf

#Below is code for the future. You can just uncomment it and use it now though. It works.
#echo 'Configuring i3 window manager. Windows (Super) key is the default modifier'
#echo 'The config file is located in ~/.i3/config'
#mkdir ~/.i3
#cp jconfig/config ~/.i3/config
 
Chromium in root mode

Here is another script I use. Its for chromium to launch in root mode. Before launching the script, create a user with username chrome and everything else as default. Put whatever you want for full name. Then place this script in /usr/local/bin and just execute 'chrome-root' in a terminal.

chrome-root
Code:
#!/bin/sh
#Chrome with data dir execution 
#For root accounts

echo 'Launching Google Chrome for root ....'
chrome --user-data-dir=/home/chrome

Put the code into a file called chrome-root and chmod 777 it. Then place it in /usr/local/bin and enjoy life. :p
 
Second revision of reinstall script.

The second version of my initial reinstall script.
It now installs and configures nearly everything for a day to day FreeBSD use.
It also now provides to methods of installing packages. Pkg_add or Ports.
It also does a bunch of other stuff.
To install, just extract the attachment below and run the setup0.setup file.
It will do everything else. :)
P.S pkg_add is too outdated for my preference so I recommend ports by all chances.
View attachment Blackfire.tar.gz
 
naveenbeast said:
The second version of my initial reinstall script.
It now installs and configures nearly everything for a day to day FreeBSD use.
It also now provides to methods of installing packages. Pkg_add or Ports.
It also does a bunch of other stuff.
To install, just extract the attachment below and run the setup0.setup file.
It will do everything else. :)
P.S pkg_add is too outdated for my preference so I recommend ports by all chances.
View attachment 1730

The fact that it copies (actually it would fail) hidden directory makes me suspicious about this scripts.
And while I looked briefly at source and it looks ok, I would never ever use it (because of style how it's "installed", not to mention it will modify every aspect of system).
If anyone want's to try out, I recommend you check entire source (looks safe, but you never know)


@naveenbeast, check how I solve app configuration problem:
https://github.com/graudeejs/dot.files
https://github.com/graudeejs/dot.vim
https://github.com/graudeejs/dot.fvwm
https://github.com/graudeejs/desktop (needs updating)

System config is different matter, and I won't discuss it here (don't have that much time).

P.S.
At first I thought your setup0.setup will prepare environment to install some root-kit. No joking.
 
naveenbeast said:
Reinstalling FreeBSD and the ports and the updates can become a real pain in the ass. I wrote this script up to assist me with exactly that. This script makes clang the default compiler, applies optimizations to make.conf, installs updates via freebsd-update and updates the port tree with portsnap, installs xorg, i3 window manager, installs transmission, install firefox (or chromium), installs the linux base files, installs and sets up flash player 11, configure xorg, and configure rc.conf to enable hald,dbus and the linux compatibility layer. It also installs utilities like subversion, wget, nano, bash, portmaster and portupgrade. Tested on FreeBSD 9.1 RC3 install. :)

fbsd_setup.sh
Code:
...

-fno-stict-aliasing isn't an optimization. It will disable aliasing by type for C/C++ compiler. Aliasing by type actually optimizes, because it assumes that different type pointers won't point to same address. If you need this option for your programs, address the issue in the code. There are a lot of different examples for C, like simply using those pointers in union.

IMHO, it's only safe to put these gcc flags in /etc/make.conf : -pipe (forces programs in compilation process to communicate via pipes rather than temporary files), -O[n] (optimization level). Be sure to check out what flags are automatically enabled by various optimization levels. Even -march should be set by CPUTYPE variable, not CFLAGS.

Actually, it's best to leave out CFLAGS completely for standard FreeBSD usage.
 
You're asking for a lot of trouble by running www/chromium as root, please don't do that. Whatever problems you have with it that could be solved by running it as root, find a another safer solution.
 
mode-line script

Here is a script that gives me the x11-wm/stumpwm mode-line below.

modeline.png


I'm very new to shell scripting, so there is likely a better way to do much of what I did. Criticism is welcomed. I hard coded a few things that are specific to my system (e.g. I know the network interfaces are either wlan0 or em0), but it shouldn't too difficult to adapt to different setups. I also use net/ifstat to get the network traffic data, because I couldn't get it to work with netstat().

ml
Code:
see next post
 
Take two. The io and istat scripts are no longer needed and the script processes die when you exit x11-wm/stumpwm.

ml.sh
Code:
#!/usr/bin/env sh

stump_pid=`pgrep -a -n stumpwm`

mem_tot=`awk '/real memory/ {print $4;exit}' /var/run/dmesg.boot`
mem_tot=$(( ${mem_tot}/1024/1024 ))

# while stumpwm is still running
while kill -0 $stump_pid > /dev/null 2>&1; do
	hn=`hostname -s`
	date=`date '+%a %b %e %H:%M:%S'`
	disk=`df -t ufs -h | awk 'END{print $3" "$2" "$4}'`
	set -- $disk; ds_usd=$1; ds_tot=$2; ds_avl=$3;
	ds_usd_val=${ds_usd%?}; ds_usd_unt=${ds_usd#$ds_usd_val}
	ds_tot_val=${ds_tot%?}; ds_tot_unt=${ds_tot#$ds_tot_val}
	ds_avl_val=${ds_avl%?}; ds_avl_unt=${ds_avl#$ds_avl_val}
	io=`iostat -x -w2 -c2 ada0 | awk 'END{print $4" "$5}'`
	set -- $io; dr=$1; dw=$2
	net=
	if ifconfig wlan0 2> /dev/null | grep -q inet; then
		ifn="wlan0"
		net=`/usr/local/bin/ifstat -i wlan0 1 1 | awk 'END{print $1" "$2}'`
	elif ifconfig em0 | grep -q inet; then
		ifn="em0"
		net=`/usr/local/bin/ifstat -i em0 1 1 | awk 'END{print $1" "$2}'`
	fi
	[ -z "$net" ] || { set -- ${net}; if_dl=$1; if_ul=$2; }
	sysctl=`sysctl -n dev.cpu.0.freq hw.acpi.thermal.tz0.temperature\
    hw.acpi.battery.life hw.acpi.battery.state hw.pagesize\
    vm.stats.vm.v_inactive_count vm.stats.vm.v_free_count\
    vm.stats.vm.v_cache_count`;
	set -- $sysctl; cpu_freq=$1; cpu_tmp=${2%?}; bat_lf=$3; bat_st=$4;
	page_siz=$5; inct_cnt=$6; free_cnt=$7; cach_cnt=$8
	mem_use=$(( ${mem_tot}-(${inct_cnt}+${free_cnt}+${cach_cnt})*${page_siz}/1024/1024 ))
	vol=`mixer -s vol | sed 's/vol [0-9]*://'`
	ML="^[^B^7*$hn^] ^[^8*C^] %4d^[^9*MHz^] ${cpu_tmp}^[^9*C^] ^[^8*M^]\
 %4d^[^9*M^]/${mem_tot}^[^9*M^] ^[^8*D^] ${ds_usd_val}^[^9*${ds_usd_unt}^]/\
${ds_tot_val}^[^9*${ds_tot_unt}^] ${ds_avl_val}^[^9*${ds_avl_unt}^] %8.1f^[^9*K/s^] %8.1f^[^9*K/s^]"
	[ -z "${net}" ] || ML="${ML} ^[^8*$ifn^] %6.1f^[^9*K/s^] %6.1f^[^9*K/s^]"
	ML="${ML} ^[^8*B^] ${bat_lf}"
	if [ ${bat_st} = '0' ] || [ ${bat_st} = '2' ]; then
		ML="${ML}^[^9*-^]"
	else
 		ML="${ML}^[^9*+^]"
	fi
	ML="${ML} ^[^8*V^] ${vol} | ^[^B^7*${date}^]"
	if [ -z "${net}" ]; then
		printf "$ML" ${cpu_freq} ${mem_use} ${dr} ${dw} > /tmp/ml-info.txt
	else
		printf "$ML" ${cpu_freq} ${mem_use} ${dr} ${dw} ${if_ul} ${if_dl} > /tmp/ml-info.txt
	fi
done
 
script to start/stop wireless connections

Code:
#!/usr/bin/env sh

# set this to your wireless interface
wl_if=iwn0

# Usage: ws [start <ssid> | stop | list]

if [ -z $wl_if ]; then
	printf "wl_if is not set to the wireless interface.\n"
	exit
fi

extra() { printf "Extra arguments are being ignored.\n"; }

stop_ws()
{ 
	ifconfig wlan0 destroy
	printf "wlan0 destroyed\n"
}

usage() { printf "Usage: ws [start <ssid> | stop | list]\n"; exit; }

[ $# -eq 0 ] && usage

if [ $1 = 'start' ]; then
	[ $# -lt 2 ] && usage
	[ $# -gt 2 ] && extra
	ifconfig wlan0 > /dev/null 2>&1 && stop_ws
	ifconfig wlan0 create wlandev ${wl_if}
	ifconfig wlan0 ssid $2
	if !(grep -q "^[[:space:]]*ssid=['\"'']\?$2['\"'']"\
 /etc/wpa_supplicant.conf); then
		printf "Adding an entry for $2 in /etc/wpa_supplicant...\n"
		stty -echo
		read -p "Passphrase: " ps_phr
		stty echo
		printf "\n** If password is incorrect, you have to fix\
 /etc/wpa_supplicant.conf before running "
		printf `basename $0`; printf " again. **\n"
		printf "\nnetwork={\n\tssid=\"$2\"\n\tpsk=\"${ps_phr}\"\n}\n" >>\
 /etc/wpa_supplicant.conf
	fi
	wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant.conf
	printf "Associating with $2"
	while !(ifconfig wlan0 | grep -q associated); do
		printf "."
		sleep 1
	done
	printf "\nAssociated to $2\nFlushing route...\nCalling dhclient...\n"
	dhclient wlan0
	route change default -ifp wlan0
elif [ $1 = 'stop' ]; then
	[ $# -gt 1 ] && extra
	if ifconfig wlan0 > /dev/null 2>&1; then stop_ws
	else printf "The interface wlan0 does not exist.\n"
	fi
elif [ $1 = 'list' ]; then
	[ $# -gt 1 ] && extra
	ifconfig wlan0 > /dev/null 2>&1 || ifconfig wlan0 create wlandev ${wl_if}
	ifconfig wlan0 | grep -q 'status: associated' || ifconfig wlan0 up
	ifconfig wlan0 list scan
else
	usage
fi
 
Just discovered this, very handy (please excuse if its a repeat):

Code:
# obtain console screen width/height

w=$(tput cols)   # width
h=$(tput lines)  # height
x=$(expr $w / 2) # 1/2 width
y=$(expr $h / 8) # 1/8 height, etc...
 
This simple script allow you to surf in ports tree and discover wonderful applications by reading pkg-descr:


Code:
#!/bin/sh
trap 'exit 0' 2

for i in $1/*
do
  if [ -d $i ] ; then
       cd $i
       clear
       echo -e "Name: $i\n"
        if [ -f pkg-descr ]; then
               less pkg-descr
        else
               echo -e "pkg-descr not found!\n"
        fi
        cd ..
  fi
done

Usage:
% ./script /usr/ports/category

To read next pkg-descr just press q, to quit the program press CTRL+C.
HTH
 
Very nifty script. =)

(Just thinking aloud here) would be handy if the end user could install a given package/port using your idea. Something like:

Code:
[color="Red"]<pseudo-code>[/color]

dialog --yesno --title "Install $PKG_NAME?" "$PKG_DESCR" $HEIGHT $WIDTH
[ $? -eq 0 ] && func_add_pkg $PKG_NAME || func_next_routine

[color="Red"]</pseudo-code>[/color]
 
I once cat-ed together all the pkg-descr in a category or two so I could read them all at once; though had to script something up in a wrapper to put the port pwd below or above each snippet (file), so one could ascertain the port one was reading of... that was many years ago though.
 
Instead of decoding URL hex codes manually or relying on JavaScript-based online decoders, you can use the following one liner:
Code:
#!/bin/sh

echo "$1" | sed 's/%24/$/g;s/%26/\&/g;s/%2B/+/g;s/%2C/,/g;s/%2F/\//g;s/%3A/:/g;s/%3B/\;/g;s/%3D/=/g;s/%3F/?/g;s/%40/@/g;'
Example:
Code:
urldec.sh 'http%3A%2F%2Fforums.freebsd.org%2Fshowthread.php%3Ft%3D737'
(sorry for the second code tag, but the URL is not displayed properly in a cmd tag)
 
Apologies if this is a repost. I have several directories each containing .tbz which unfortunately accumulate several versions of each without an easy method of parsing out the extra ones. This week discovering that
Code:
bsddiff /dir1 /dir2
enables easy copy to-fro so that both are in sync, the only remaining task is to delete the older versions.
Two ports necc. for the following...
Code:
/usr/local/bin/gnuls -oSr | sort -k 4 | sort -k 8 | /usr/local/bin/lookat
[two xterm/screen/tmux/or the first .tbz directory ]
[ then the delete is already in history for the next .tbz directory ]
...after the following is complete [If I've explained it adequately]

That is in one xterm. In the first .tbz directory, parsing down thru the lookat in one terminal, one can construct a long delete-older /bin/rm -v line in a different xterm/tmux/screen [...and recall it from history to delete from any/all the additional tbz
directories.] [Very handy here, where a thumbdrive also is a repository for them.] I
had thought of constructing a perl equivalent, but the certainty of knowing that the
task is done without error at the command line is worth the additional time to
delete manually, at least for now... [Someday... pkg_info for example wants to unextract the .tbz to find its origin, making the process somewhat
too costly in CPU time...]

This is also useful if one wishes to purge older distfiles from /usr/ports/distfiles, (just one instance though) though usually one may not need to do that often [and it should then be repeated in /usr/ports/distfiles/gnome2 etc.]
 
Beastie said:
Instead of decoding URL hex codes manually or relying on JavaScript-based online decoders, you can use the following one liner:
Code:
#!/bin/sh

echo "$1" | sed 's/%24/$/g;s/%26/\&/g;s/%2B/+/g;s/%2C/,/g;s/%2F/\//g;s/%3A/:/g;s/%3B/\;/g;s/%3D/=/g;s/%3F/?/g;s/%40/@/g;'
Example:
Code:
urldec.sh 'http%3A%2F%2Fforums.freebsd.org%2Fshowthread.php%3Ft%3D737'
(sorry for the second code tag, but the URL is not displayed properly in a cmd tag)

Here's a much better ruby script
Code:
#!/usr/bin/env ruby

require 'cgi'

ARGV.each do |encoded_url|
  puts CGI::unescape(encoded_url)
end
 
Beastie said:
Instead of decoding URL hex codes manually or relying on JavaScript-based online decoders, you can use the following one liner:
Code:
#!/bin/sh

echo "$1" | sed 's/%24/$/g;s/%26/\&/g;s/%2B/+/g;s/%2C/,/g;s/%2F/\//g;s/%3A/:/g;s/%3B/\;/g;s/%3D/=/g;s/%3F/?/g;s/%40/@/g;'
Example:
Code:
urldec.sh 'http%3A%2F%2Fforums.freebsd.org%2Fshowthread.php%3Ft%3D737'
(sorry for the second code tag, but the URL is not displayed properly in a cmd tag)

You may want to decode all possible characters:
http://sourceforge.net/apps/trac/shweb/browser/trunk/shweb/shweb_urldec

Code:
s/%25/%/g
s/%20/ /g
s/%09/	/g
s/%21/!/g
s/%22/"/g
s/%23/#/g
s/%24/\$/g
s/%26/\&/g
s/%27/'/g
s/%28/(/g
s/%29/)/g
s/%2a/\*/g
s/%2b/+/g
s/%2c/,/g
s/%2d/-/g
s/%2e/\./g
s/%2f/\//g
s/%3a/:/g
s/%3b/;/g
s/%3e/>/g
s/%3f/?/g
s/%40/@/g
s/%5b/\[/g
s/%5c/\\/g
s/%5d/\]/g
s/%5e/\^/g
s/%5f/_/g
s/%60/`/g
s/%7b/{/g
s/%7c/|/g
s/%7d/}/g
s/%7e/~/g
 
vermaden said:
You may want to decode all possible characters:
http://sourceforge.net/apps/trac/shweb/browser/trunk/shweb/shweb_urldec

Code:
s/%25/%/g
s/%20/ /g
s/%09/	/g
s/%21/!/g
s/%22/"/g
s/%23/#/g
s/%24/\$/g
s/%26/\&/g
s/%27/'/g
s/%28/(/g
s/%29/)/g
s/%2a/\*/g
s/%2b/+/g
s/%2c/,/g
s/%2d/-/g
s/%2e/\./g
s/%2f/\//g
s/%3a/:/g
s/%3b/;/g
s/%3e/>/g
s/%3f/?/g
s/%40/@/g
s/%5b/\[/g
s/%5c/\\/g
s/%5d/\]/g
s/%5e/\^/g
s/%5f/_/g
s/%60/`/g
s/%7b/{/g
s/%7c/|/g
s/%7d/}/g
s/%7e/~/g

These are not All possible characters (this is small and very common subset of characters)
 
graudeejs said:
These are not All possible characters (this is small and very common subset of characters)

But have dependence only on POSIX sed/sh, You do not need to have whole Ruby to do that ;)

Its the same reason I use portmaster instead of (IMHO a lot overrated) portupgrade.
 
Back
Top