Wednesday, 22 July 2009

More simple bash scripts

Script for start X session automatically, after making login ( without using any login manager)
#!/bin/bash
if (($(ps -A | grep -c X) > 0));
then
echo starting X....;startx;
fi

Script for unzip multiple files. Replacing "zip" extension name and "unzip" command on script, we can change to open other files as well.
#!/bin/bash
for file in *zip
do
unzip "$file"
done

Script to get links from an list every X time, for example, usefull to automatically open download links like rapidshare, netload, megaupload,...
Changing time and application, it can be useful to do lots of things =)
#!/bin/bash
waitTime=3600
app="/usr/bin/firefox"

cat $1 | while myLine=`line`
do
echo "Requesting" $myLine
$app $myLine;
sleep $waitTime && echo ""
done

Some usefull commands
Play random mp3
slocate *.mp3 | mpg321 -@ - -z

Play random mp3 from specific folder
slocate *.mp3 | grep /home/user/files/mp3/new/ | mpg321 -@ - -z

Download links from an text file list
wget -i file.txt

Download recursively all page files
wget -r http://url/folder/

Download sequentially files
curl -O http://url/img[01-99].png

Saturday, 11 July 2009

Mount FTP as filesystem


CurlFtpFS is a filesystem for accessing FTP hosts based on FUSE and libcurl.

[Install]

localhost ~ # emerge net-fs/curlftpfs in gentoo
localhost ~ # apt-get install curlftpfs in ubuntu/debian
localhost ~ # ./configure && make && make install by the manual way

[Mount]

localhost ~ # modprobe fuse if you dont have fuse module loaded
localhost ~ # curlftpfs ftp://user:pass@site.com /mnt/mountpoint

[Umount]]

localhost ~ # fusermount -u /mnt/mountpoint

Thats it, now you can access with any file explorer like konqueror, nautilus…..we can do almost everything like edit source code

Adding on fstab
curlftpfs#ftp.host.com /mnt/mountpoint fuse rw,uid=500,user,noauto 0 0

or Making alias
alias mHost=’curlftpfs ftp://user:pass@site.com /mnt/mountpoint’

More int at http://curlftpfs.sourceforge.net/

Mount SSH as filesystem

SSHFS is a filesystem client based on the SSH File Transfer Protocol.

[Install]

localhost ~ # emerge sys-fs/sshfs-fuse in gentoo
localhost ~ # apt-get install sshfs in ubuntu/debian
localhost ~ # ./configure && make && make install manual way

[Mount]

localhost ~ # modprobe fuse if you dont have fuse module loaded
localhost ~ # sshfs user@site.com: /mnt/mountpoint use “-o allow_other” for share between multiple users

[Umount]

localhost ~ # fusermount -u /mnt/mountpoint

Thats it, now you can access with any file explorer like konqueror, nautilus…..we can do almost everything like edit source code, create, delete….

Adding on fstab
sshfs#USERNAME@REMOTE_HOST: REMOTE_PATH MOUNT_POINT fuse SSHFS_OPTIONS 0 0

or Making alias
alias mHost=’modprobe fuse;sshfs user@site.com: /mnt/mountpoint -o allow_other’

More info at http://fuse.sourceforge.net/

Friday, 10 July 2009

Simple CTRL ALT DEL in linux




Install xkill
Attribute an shortcut to a key for xkill


And voilĂ , just click on window do you want to kill :D
(In picture on right, gimp is being killed)


Description: kill a client by its X resource

How to compile kernel script

Download here


cd
/usr/src/linux &&

echo "Running kernel configuration..." &&
make menuconfig &&

echo "Compiling kernel..." &&
make &&

echo "Installing kernel modules..." &&
make modules_install &&

echo "Making backup of old kernel..." &&
mv /boot/config /boot/config-old &&
mv /boot/System.map /boot/System.map-old &&
mv /boot/kernel /boot/kernel-old &&

echo "Installing new kernel..." &&
cp /usr/src/linux/System.map /boot &&
cp /usr/src/linux/.config /boot/config &&
cp /usr/src/linux/arch/i386/boot/bzImage /boot/kernel &&

echo done

Usefull bookmarks

archive.org (internet archive) --> see offline/old pages that is no longer online/available.
translate.google.com --> translate text, web pages and act as proxy =)

pastebin.com --> paste code
imageshack.us --> host images
sendspace.com --> upload files
filewatcher.com --> find files

whatismyip.com --> my ip
ipcalc --> calculate mask, wildcard mask, network address, min host, max host...
default_pass --> default passwords

Tuesday, 5 May 2009

Simple text extraction from images

You must have an screenshot tool and an OCR tool, the tools i use is imagemagick to take screenshots and gocr to recognize characters.

import -quality 100 /tmp/scan.png && gocr /tmp/scan.png


For example, testing with this example the output was :
Linux, ubuntu, gentoo, scripts, security, networks, digg, sIashdot, engadget, youtube.

Doesnt work 100% but can be usefull :)