Archive

Posts Tagged ‘bash’

Switch DNS

July 1st, 2010 Albertux No comments
#!/bin/bash
# Author: Albertux (Alberto Isaac Ayala Esquivias)
# Script: switch the nameservers (DNS)
 
if [ ! $( id -u ) -eq 0 ]
then
	echo "Run this script as root"
	exit
fi
 
if [ $# -le 0 ]
then
	echo "Usage $0 [open|google|comodo|old]"
fi
 
if  [ ! -f /etc/resolv.conf.bak ]
then
	cp /etc/resolv.conf /etc/resolv.conf.bak
fi
 
case $1 in
	open)
		echo -e "# OpenDNS\nnameserver 208.67.222.222\nnameserver 208.67.220.220" > /etc/resolv.conf
	;;
	google)
		echo -e "# Google Public DNS\nnameserver 8.8.8.8\nnameserver 8.8.4.4" > /etc/resolv.conf
	;;
	comodo)
		echo -e "# Comodo Secure DNS\nnameserver 156.154.70.22\nnameserver 156.154.71.22" > /etc/resolv.conf
	;;
	old)
		cp /etc/resolv.conf.bak /etc/resolv.conf
	;;
esac
Categories: network, unix/linux Tags: ,

BASH 4.0

February 24th, 2009 Albertux No comments

BASH 4.0

http://www.mail-archive.com/cygwin@cygwin.com/msg94439.html

ftp://ftp.cwru.edu/pub/bash/bash-4.0.tar.gz
ftp://ftp.gnu.org/pub/gnu/bash/bash-4.0.tar.gz

#!/usr/bin/bash
bash4=$(`echo $SHELL` --version | grep "version 4" | awk '{if (NR!=2) {print $4}}')
if [ -z $bash4 ]
	then
		wget ftp://ftp.gnu.org/pub/gnu/bash/bash-4.0.tar.gz
	else
		echo you have bash 4
fi
Categories: unix/linux Tags:

Using Windows ? Don't kill Yourself

October 27th, 2008 Albertux No comments

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

Categories: unix/linux, windows Tags: , , , , ,

Resize Multiple Images

October 20th, 2008 Albertux 2 comments

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]

Categories: unix/linux Tags: , ,

rubygems-update issue on Ubuntu

September 30th, 2008 Albertux 4 comments

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

Categories: unix/linux Tags: , ,