Archive

Posts Tagged ‘bash’

Using Windows ? Don’t kill Yourself

October 27th, 2008

Using Windows ? Don’t Kill Yourself

Supose you are Linux user and you have a Windows system.

Alternatives: Cygwin, Mingw or Colinux

You need some (or all) of this interpreters:

Perl, PHP, Python and Ruby

Modify the %PATH%

Example you have a bin dir, on C:\ to include the executables on the %PATH% do this:

set PATH=%PATH%;C:\bin\

On Windows Vista, you can use your mouse:

computer > properties > Advances system settings > (continue) > Advanced > Enviroment Variables > System Variables > Path (edit)

Example run Kompozer on cmd.exe but no modify %PATH%

: kompozer.bat save on %WINDIR%
@"C:\Program Files\Kompozer\kompozer.exe"

Doble click on your scripts to run:

: Perl Scripts
 assoc .pl=Perl.File
 ftype Perl.File=C:\strawberry\perl\bin\perl.exe "%1" %*
 set PATHEXT=%PATHEXT%;.pl
: Python Scripts
 assoc .py=Python.File
 ftype Python.File=C:\Python26\python.exe "%1" %*
 set PATHEXT=%PATHEXT%;.py

Note:

On Windows Vista you need run cmd.exe as Administrator don’t work as normal user

Apache, PHP and MySQL ?

XAMPP and Server2Go

Notes:

XAMPP: simple, quick and easy install.

Server2Go: is great to make CD demo of a Web Application.

Using Perl or Python as CGI on Windows ?

Using Python 2.6

#!\python26\python.exe

Using Strawberry Perl:

#!\strawberry\perl\bin\perl.exe

Now your script works on http://localhost/cgi-bin/script.cgi

develop, unix/linux, windows , , , , ,

Resize Multiple Images

October 20th, 2008

Resize Multiple Images

In my case i need to change the size of more than 1,000 pictures so using gimp and scale everyone is not a good solution.

You need ImageMagick and Bash.

Subfolders:

script.sh:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/bin/bash
# fotos
IFS=$'\t\n'; # Algunas fotos puede que tengan espacios
for i in `ls`; do
    for j in `ls $i `; do # fotos/098-001/ fotos/098-002/ fotos/097-001/ etc...
    if [ "$j" = "Thumbs.db"  ]; then  # garbage file on win32
        echo "Nothing to do..."
    elif [ "$j" = "script.sh" ]; then # this script file :D
        echo "Nothing to do..."
    else
        echo "Working ..." # do the job
        #convert "$i/$j" -resize 500 "$i/new_$j"
        #mv "$i/new_$j" "$i/$j"
        mogrify -resize 500 "$i/$j"
    fi
    done
done

Now all images are width: 500.

Now supose you have a lot of sub directories, you can use this script:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/bin/bash
IFS=$'\t\n'
EXTS=( jpg gif png JPG GIF PNG )
for EXT in ${EXTS[@]};
do
	for f in `find . -name "*.$EXT" -type f`;
	do
		dir=`dirname $f`
		ff=`basename $f`
		echo "Working ..."
		#convert "$f" -resize 500 "$dir/new_$ff"
		#mv "$dir/new_$ff" "$f"
                mogrify  -resize 500 "$f"
	done
done

[thanks for the advice CyX]

develop, unix/linux , ,

rubygems-update issue on Ubuntu

September 30th, 2008

rubygems-update issue on Ubuntu

If you have this problem on your computer:

sudo gem update --system
Updating RubyGems
Bulk updating Gem source index for: http://gems.rubyforge.org/
Updating rubygems-update
ERROR:  While executing gem ... (Gem::GemNotFoundException)
    could not find rubygems-update locally or in a repository

The problem is RubyGems you need to install manually or use this script solution:

#!/bin/bash
#(download the latest on http://rubyforge.org/frs/?group_id=126)
wget http://rubyforge.org/frs/download.php/43984/rubygems-update-1.3.0.gem
sudo gem install rubygems-update-1.3.0.gem
sudo update_rubygems
# now this work:
sudo gem update --system
echo "done."

I found this solution on this web:

http://rubyglasses.blogspot.com/2008/08/updating-gem-to-120-on-ubuntu.html

develop, unix/linux , ,

Toshiba Fan On Ubuntu

September 28th, 2008

Toshiba Fan On Ubuntu

You need to install toshset include on toshutils (do you have lm-sensors ?)

sudo apt-get install toshutils

This script make the fan run high, low or normal

#!/bin/bash
case $1 in
	h) sudo toshset -fan 4 # high
	;;
	n) sudo toshset -fan 5 # normal
	;;
	l) sudo toshset -fan 6 # low
	;;
esac

If you live in warn places, “~$ script.sh h” could be help you a little don’t use all time this option, to normalize your fan run “~$script.sh n”.

There are other tools on toshset “man toshset”.

hardware, unix/linux , , , ,

MySQL Workbench (Linux)

September 24th, 2008

MySQL Workbench (Linux)

What is MySQL Workbench ?

MySQL Workbench is a cross-platform, visual database design tool developed by MySQL. It is the highly anticipated successor application of the DBDesigner4 project. MySQL Workbench will be available as a native GUI tool on Window, Linux and OS X.

For Ubuntu (8.04) users i made this install script (run as root):

#!/bin/bash
# This script tested only on Ubuntu 8.04 (32 bits)
# You need some extra libs to run MySQL Workbench
sudo apt-get install liblua5.1-0 libzip1 libmysqlclient15off
# Download MySQL Workbench Ubuntu 8.04 Bin Files
wget -c ftp://ftp.mysql.com/pub/mysql/download/gui-tools/mysql-workbench-5.1.2-alpha-ubuntu8-i386.tar.gz
# Download the md5 checksum file
wget -c ftp://ftp.mysql.com/pub/mysql/download/gui-tools/mysql-workbench-5.1.2-alpha-ubuntu8-i386.tar.gz.md5
# Check md5sum
real=`md5sum mysql-workbench-5.1.2-alpha-ubuntu8-i386.tar.gz | awk '{ print $1 }'`
confirm=`cat mysql-workbench-5.1.2-alpha-ubuntu8-i386.tar.gz.md5 | awk '{ print $1 }'`
if [ "$real" = "$confirm" ]
then
	# Extract (/usr/local/bin/ /usr/local/lib/mysql-workbench/ /usr/local/share/mysql-workbench/)
	tar xvzf mysql-workbench-5.1.2-alpha-ubuntu8-i386.tar.gz -C /
else
	echo "Wrong MD5, run the script again."
fi

Note: MySQL Workbench is alpha on Linux

More information about MySQL Workbench

database, develop , , ,

About NetCat

September 11th, 2008

About NetCat

NetCat a great network tool checkout this examples:

Create a Small WebServer:

while true; do nc -l -p 80 -q 1 < error.html; done

Transfer Files:

nc -lp $PORT > $FILE
cat $FILE | nc -w 1 $HOST $PORT

Chat Server:

nc -lp $PORT
nc $HOST $PORT

Spoof Headers:

echo -e "GET / HTTP/1.1\n\n" | nc -v $HOST 80

Backup System:

nc -lp $HOST > backup.tar.gz
tar cf - $DIR  | gzip  | nc -w 1 $HOST $PORT

Remote Shell:

nc -lp $PORT -e $CMD
nc $HOST $PORT

Clonning Hard Drive:

nc -l -p $PORT | dd of=/dev/sda
dd if=/dev/sda | nc $HOST $PORT

Port Scanner:

nc -vz $HOST 21-80

Web: http://netcat.sourceforge.net/

network, unix/linux ,

JSC JavaScript Collection

August 24th, 2008

JSC JavaScript Collection

We need jsmin and gzip, compile the jsmin.c:

gcc -o jsmin jsmin.c

Script to generate a collection of the javascript files:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/bin/bash
 
echo "JavaScript Collection"
 
  EXPECTED_ARGS=1
  E_BADARGS=65
 
if [ $# -ne $EXPECTED_ARGS ]
then
  echo "Usage: `basename $0` {path of the javascripts}"
  exit $E_BADARGS
fi
 
# Join the javascript scripts in one file
cat $1/*.js >> $1/.__fullscripts.tmp
 
# use JSMIN to minifier the script
cat $1/.__fullscripts.tmp | jsmin > $1/.__fullscripts.min.tmp
 
# awk remove the first blank line, gzip compress the script
awk 'FNR>1{print}' $1/.__fullscripts.min.tmp | gzip > $1/collection_scripts.js.gz
 
# remove temporal files
rm $1/.__fullscripts.tmp $1/.__fullscripts.min.tmp

Howto: jsc public_html/web/js/

Now create one php script to replace all javascripts:

<script type="text/javascript" src="collection_scripts.php"></script>

Content of collection_scripts.php:

<?php
    header("Content-type: text/javascript; charset: UTF-8?");
    header("Content-Encoding: gzip");
    readfile("collection_scripts.js.gz");
?>

unix/linux , ,