Usually I read a lot of bash tips, codes, snippets, but some tips are hard to find, let see 2 tips:
Read Line
The ideia is, read each line of a file using bash, some people use terrible ways to do this job.
Bash has a simple way, $(< filename)
echo $(< file.txt)
Apparently the command did’n work, but the fact’s, the command worked, but printed line by line without ‘\n’.
This for show how to work with each line.
for i in $(<file); do echo $i; done
Rename only the extension
This is simple, some tasks need a in file and a out file, the two files can be different, if we need a ‘for’ we need create a good number of files.
Instead of create something like foo.txt and foo.txt.xml, you can create one foo.xml.
Let’s use ${//} to improve your work.
$variable = name.foo
echo ${variable/foo/bar}
Inside a for, is awesome:
for i in */*.xml; do xml2xsd $i ${i/xml/xsd}; done
Thanks
This is a fast tutorial to set up, quick and fast, a mercurial server at Snow Leopard using Apache and cgi(the dirty party).
We need:
- One apache server, we’ll use the apache shipped with Snow Leopard
- Install the mercurial
- And the CGI script provide by Mercurial
First, install the mercurial, I used the macports version
sudo port install mercurial
Second, configure the httpd.
Create /etc/apache2/extra/httpd-hg.conf
ScriptAliasMatch ^/hg(.*) /var/hg/hgwebdir.cgi$1 #the last one is the the cgi file location
<Directory /var/hg>
AuthType Basic
AuthName "Mercurial repositories"
AuthUserFile /var/hg/.htpasswd # the user file
Require valid-user
Options ExecCGI FollowSymLinks
Order allow,deny
Allow from all
AllowOverride all
AddHandler cgi-script .cgi
</Directory>
Include at /etc/apache2/httpd.conf
Include /etc/apache2/extra/httpd-hg.conf
Third, create the repository, I’m using /var/hg.
sudo mkdir -p /var/hg/repos
Create the cgi configure file hgweb.config at /var/hg
[collections]
repos/ = repos/
[web]
style = gitweb
Download the cgi file from http://www.selenic.com/repo/hg-stable/raw-file/tip/hgwebdir.cgi and put at /var/hg
Uncomment the follow lines at hgwebdir.cgi and put the python location:
import sys
sys.path.insert(0, "/System/Library/Frameworks/Python.framework/Versions/2.6/bin")
Create the .htpasswd to authenticate users
htpasswd -c /var/hg/.htpasswd user
At /var/hg/repos, create a repository
hg init /var/hg/repos/<repository-name>
Edit the hgrc under /.hg
[web]
push_ssl = false #allow push using non-ssl connection
contact = user
description = teste
allow_push = user user2 #user allowed to push, must exist at .htpasswd
Do not forget to change the permissions at /var/hg to user _www and group _www
sudo chown -R _www:_www /var/hg
Start the apache server
sudo apachectl -k start
Now you have one repository, you can access using http://127.0.0.1/hg/
More info at http://mercurial.selenic.com/wiki/HgWebDirStepByStep
Filed under: Uncategorized
Big changes, new city, strange job, nice coworkers, new stuff, old friends
The only problem, my girlfriend lives far, far way
Uma das coisas mais comuns no uso do gentoo, principalmente quando mistura pacotes estáveis, testings e unstables (como eu costumo fazer), é o downgrade de algum pacote para alguma versão anterior sem uma razão aparente, como o downgrade de uma versão estável para uma antiga versão.
Isso ocorreu comigo quando fui realizar um emerge -NDuav word:
hellboy ~ # emerge -NDuav world
These are the packages that would be merged, in order:
Calculating world dependencies... done!
[ebuild UD] dev-util/bzr-1.1 [1.5] USE="bash-completion -curl -emacs -sftp -test" 3,346 kB
[ebuild U ] app-text/poppler-0.8.6 [0.8.5] USE="jpeg zlib -cjk" 1,435 kB
[ebuild U ] app-text/poppler-bindings-0.8.6 [0.8.5] USE="cairo gtk -qt3 -qt4 -test" 0 kB
Total: 3 packages (2 upgrades, 1 downgrade), Size of downloads: 4,781 kB
Would you like to merge these packages? [Yes/No]
Vejam o caso do bazaar (dev-util/bzr), mas acontece que a versão 1.5 é uma versão estável como aponta o eix:
hellboy ~ # eix dev-util/bzr
[I] dev-util/bzr
Available versions: 0.17 1.1 ~1.3 ~1.4 1.5 [M]~1.6_rc5 {bash-completion curl emacs sftp test}
Installed versions: 1.5(07:43:31 PM 08/23/2008)(bash-completion -curl -emacs -sftp -test)
Homepage: http://bazaar-vcs.org/
Description: Bazaar is a next generation distributed version control system.
A razão deste comportamento é sempre por causa de algum pacote já instalado ou que vai ser instalado, eu acho que a maneira abaixo a mais simples para descobrir qual o pacote esta forçando o downgrade.
Primeiro eu mascaro o todas as versões abaixo da versão já instalada do programa que esta sendo forçado o downgrade, no caso, todas as versões do bazaar abaixo do 1.5.
sudo echo '<=dev-util/bzr-1.4' >> /etc/portage/package.mask
Feito isso, refaço o comando que originou o pedido de downgrade e vejo o resultado:
hellboy ~ # emerge -NDuav world
These are the packages that would be merged, in order:
Calculating world dependencies /
!!! All ebuilds that could satisfy "=dev-util/bzr-1.1*" have been masked.
!!! One of the following masked packages is required to complete your request:
- dev-util/bzr-1.1 (masked by: package.mask)
For more information, see MASKED PACKAGES section in the emerge man page or
refer to the Gentoo Handbook.
(dependency required by "dev-util/bzrtools-1.1.0" [installed])
!!! Problem resolving dependencies for dev-util/bzrtools
!!! Depgraph creation failed.
Dai eu observo que o responsável pelo downgrade é o pacote dev-util/bzrtools, que consta com todas as versões consideradas como instáveis:
hellboy ~ # eix bzrtools
[I] dev-util/bzrtools
Available versions: ~0.17.1 (~)1.1.0 ~1.3.0 ~1.4.0 ~1.5.0
Installed versions: 1.1.0(02:34:38 AM 02/06/2008)
Homepage: http://bazaar.canonical.com/BzrTools
Description: bzrtools is a useful collection of utilities for bzr.
Como é um caso de pacotes instáveis, uma maneira seria apagar o pacote instável ou utilizar a keyword, como eu estou querendo aprender mais do bazaar, prefiro arriscar utilizar o pacote instável.
sudo echo '=dev-util/bzrtools-1.5.0 ~*' >> /etc/portage/package.keywords
Com isso elimino a fonte do downgrade e refaço o meu comando sem medo de downgrades
.
hellboy ~ # emerge -NDuav world
These are the packages that would be merged, in order:
Calculating world dependencies... done!
[ebuild U ] dev-util/bzrtools-1.5.0 [1.1.0] 82 kB
[ebuild U ] app-text/poppler-0.8.6 [0.8.5] USE="jpeg zlib -cjk" 1,435 kB
[ebuild U ] app-text/poppler-bindings-0.8.6 [0.8.5] USE="cairo gtk -qt3 -qt4 -test" 0 kB
Total: 3 packages (3 upgrades), Size of downloads: 1,517 kB
Would you like to merge these packages? [Yes/No]
Filed under: nerd
Your Mind is Green |
|
You are able to see all sides to most problems and are a good problem solver. You need time to work out your thoughts, but you don’t get stuck in bad thinking patterns. You tend to spend a lot of time thinking about the future, philosophy, and relationships (both personal and intellectual). |
As vezes é necessário copiar uma quantidade bizarra de arquivos, uma maneira simples de colocar em batch esta tarefa.
1 #!/bin/bash 2 3 device="hpaio:/usb/Photosmart_C3100_series?serial=BR73NGQ13X04KV"; 4 5 while true; 6 7 do if [[ -a stop_file ]]; 8 then break ; 9 fi; 10 11 echo "scanning" ; 12 name=`date +%s` ; 13 scanimage -d $device -p >$name.pnm; 14 15 convert $name.pnm $name.jpg; 16 rm $name.pnm; 17 18 echo "sleeping" ; 19 sleep 10s; 20 21 do if [[ -a stop_file ]]; 22 then break ; 23 fi; 24 25 done
Filed under: work
Yes, tomorrow I’ll restart working at Brazil Telecom, as , again, security analyst.
But what I really want say is “I HATE HUMAN RESOURCES”, yes, beautiful girls that don’t know nothing trying hire someone for something that they don’t give a shit.
My former boss invited me to work with him, again, at Brazil Telecom’s SOC, and at the interview with the HR (they don’t know nothing about computers & security , but I expected at least that they would read my resume before the interview, I was wrong)
HR: You’ll work at Brt
Me: I already worked at Brt, actuality, I worked at this same position there.
HR: Really?? Did work at Brt???
Me: Yes, look at my resume.
HR: OH, Yes, you worked there. So, What’s your expectations at Brt??
Me: ???? I’ve already worked there, I already know at will find there, I don’t have any new expectations.
One of the mostly annoying thinks about gtk is ‘ç’, especially when you are a Portuguese speaker and use US keyboard + gtk, this is because someone on the past made this choice
at us-intl keyboards, acute+c = ć
I’m not arguing against Polish, Bosnian, Croatian or Serbian, but is a stupid choice when we compare the use of ç in the Latin World (Brazil, France, Spain, Portugal, etc) , even English has some ç.
My way to solve that is simple.
diff gtk.immodules.old /etc/gtk-2.0/gtk.immodules
14c14
< "cedilla" "Cedilla" "gtk+" "/usr/share/locale"
"az:ca:co:fr:gv:oc:pt:sq:tr:wa"
---
> "cedilla" "Cedilla" "gtk+" "/usr/share/locale" "az:ca:co:fr:gv:oc:pt:sq:tr:wa:en"
I hope that, some day, someone will fix that or put at the gtk ebuild a flag like us_latin_cedilla
180 millions of Brazilians will love it.
Gentoo is know as a hard linux distribution, in fact, only the installation is a hard process, everything else is just a piece of cake.
Ok, it’s not easy as ubuntu, but with the right tools, everyone can make magic.
IMHO, no one can have all Gentoo experience without:
- equery (useful when you need information, as USE flags, depends, package contents, etc)
- eix ( excellent search packages program )
- euse (USE flags )
- revdep-rebuild (after an emerge -NDuav world, to fix broken packages)
- module-rebuild rebuild -X ( after an kernel update, rebuild old modules to fit with your new kernel)
Equery, euse and revdep-rebuild are part of gentoolkit ( emerge gentoolkit), eix and module-rebuild have their own package.
And, of course, vim for everything else
Zenity is a great tool, it creates a gtk dialog box using shell commands.
The following line shows how you can make a emerge without worry waiting for a terminal response.
emerge -NDupv world >/tmp/newpackage && zenity --text-info --filename=/tmp/newpackage && zenity --question --text="emerge?" && emerge -NDuv world
