Mostrando las entradas con la etiqueta linux. Mostrar todas las entradas
Mostrando las entradas con la etiqueta linux. Mostrar todas las entradas

20130123

Share a console in linux with multiple users using screen

Sometimes you need to see or share some actions that you or somebody is doing in a remote server terminal (lx, mac..).
You can share your screen (join.me is a good solution) but the real way of doing it is to share you terminal / console.

The best way of doing this is using screen  multiuser option.
The procedure es staightforward:

1. open a screen session (-S give a session name):
screen -S screen-multi
2. activate multiuser mode
CTRL-A
 :multiuser on
3. the other user (connected to the same server) has to:
screen -x screen-multi
And thats it, both will see the same session and can write at the same time on it.

More detail about this procedure: http://ubuntuforums.org/showthread.php?t=299286

20121127

tmux magic



tmux es una herramienta increíble para los que usamos terminales todo el día. Si usas screen, y no conoces tmux, ponete las pilas.

Estos son los shortcuts que uso en todo momento:
  • Mostrar ayuda
    • Ctrl-b ? 
  • Crear una ventana nueva: 
    • Ctrl-b c 
  • Moverte a la siguiente ventana
    • Ctrl-b n 
  • Detach tmux
    • Ctrl-b d 

  • Partir el panel verticalmente
    • Ctrl-b % 
  • Partir el panel horizontalmente
    • Ctrl-b " 
  • Moverse de panel
    • Ctrl-b flechas 
  • Matar el panel actual
    • Ctrl-b x
  • Mostrar el numero de panel 
    • Ctrl-b q 
  • Cambiarnos al siguiente panel
    • Ctrl-b o 
  • Scroll dentro del panel
    • Ctrl-b + [ luego simplemente usar las flechas arriba y abajo. q para salir de este modo. 
  • Cambiar tamaño del panel
    • Ctrl-b + Alt-flecha (5 lineas a la vez)
    • Ctrl-b + Ctrl-flecha

20121104

Tools I use every day.


Here there is a list of tools i used almost every day:

For Everybody:

Choosy - https://www.choosyosx.com/ - Instead of opening links in the default browser, Choosy sends them to the right browser. Every time.

Dropbox - https://www.dropbox.com - No explanation needed :)

Instapaper - http://www.instapaper.com - A simple tool to save web pages for reading later.

Skitch - http://skitch.com - Annotate, edit and share your screenshots and images. I like the pre Evernote version more, but what the hell, its a very handy app.

Evernote - http://evernote.com - Makes it easy to remember things big and small from your everyday life using your computer, phone, tablet and the web.

BufferApp - http://bufferapp.com - A Smarter Way to Share.

Circular - http://circular.io - Circular, an open source Buffer app.  Stock up some great tweets and have them automatically shared throughout the day.

Draw.io - https://www.draw.io - Nice diagraming tool (can be installed in your google apps account).

Simple Mind - www.simpleapps.eu/simplemind - Mind mapping tool for your desktop, ipad and android device. It has Dropbox integration, pretty nice.

Rapportive - http://rapportive.com - Get rich contact profiles right inside Gmail. Shows you everything about your contacts right inside your inbox.

Boomerang for Gmail - http://www.boomeranggmail.com - Schedule an email to be sent later. Easy email reminders. It is a Firefox / Chrome plugin that lets you take control of when you send and receive email messages.

Tabman Tab Manager for Chrome - Faster navigation between multiple chrome tabs. View all your open tabs in a beautiful list.

Grammarly - Grammarly makes sure everything you type is clear, effective, and mistake-free.

Gmail Notes - Add annotations on your emails to remember something, or to coach how to craft a good email.

Assistant.to - Book meetings with one email. No back & forth. No double bookings. And it's free!

Mac Tools:

Alfred - http://www.alfredapp.com - Productivity app for Mac, a launcher at its core.

Divvy - http://mizage.com/divvy - Window management at its finest.

FluidApp - http://fluidapp.com - Turn Your Favorite Web Apps into Real Mac Apps.

AirDisplay - http://avatron.com/apps/air-display - Ever wish you had an extra monitor for your Mac or PC? I use my ipad as a second monitor a lot (mainly for irc / skype / chat)

LICEcap - http://www.cockos.com/licecap/ - can capture an area of your desktop and save it directly to .GIF

PosteRazor - http://posterazor.sourceforge.net/ - cuts a raster image into pieces which can afterwards be printed out and assembled to a poster.

For Developers

mycli - http://mycli.net/ - Mycli is a command line interface for MySQL, MariaDB, and Percona with auto-completion and syntax highlighting. (Check pgcli for Postgres)

httpie - http://httpie.org - CLI HTTP client; user-friendly cURL replacement featuring intuitive UI, JSON support, syntax highlighting, wget-like downloads, extensions, etc.

Postman - https://www.getpostman.com/ - Build, test, and document your APIs faster. 

iterm2 - http://www.iterm2.com - iTerm2 is a replacement for Terminal.

GitRay - http://gitray.com/ - Easy navigation of projects on Github.

localtunnel - http://localtunnel.me/ - The easiest way to share localhost web servers to the rest of the world

vagrant / puppet / php - https://puphpet.com - A simple GUI to set up virtual machines for Web development. Check http://rove.io too. If you use Ansible check http://phansible.com/

vagrantmanager - http://vagrantmanager.com - Manage your vagrant machines in one place with Vagrant Manager for OS X.

nutty.io - https://nutty.io/ - Share your terminal using your browser.
tmate.io - http://tmate.io/ - Share your terminal.

octotree - https://github.com/buunguyen/octotree - Browser extensions to display GitHub code in tree format

octolinker - http://octolinker.github.io/ - Navigate through projects on GitHub.com efficiently (compoer, npm packages etc..)

asciinema - https://asciinema.org - Record and share your terminal sessions, the right way.

mitmproxy - https://mitmproxy.org - free and open source interactive HTTPS proxy.



I will update this list often.

Updated 2020-03

20120716

Resume scp transfer AAARRRGGGG

Had to upload a big file (300MB yeah its a big file for the kind of connection we have down here) to a remote server via scp. When it reached like 50% (1 hour after initiated) the connection drops!!! DAMN!

So after some research i found this :
rsync --partial --progress my_local_file.gz --rsh ssh user@server:my_remote_file.gz

yessss!!

If your ssh connection needs to use a port you can use
rsync --partial --progress my_local_file.gz --rsh 'ssh -pMY_PORT' user@server:my_remote_file.gz

20120712

sudo without password on Ubuntu

First edit your sudoers file:
sudo visudo
Add this line
your_username ALL=(ALL) NOPASSWD: ALL
Save it, and that's it!

20110811

Sphinx Search - why and how to use sphinx search delta indexes

Problem:
Anybody who used sphinx search knows that reindexing big indexes takes a long time. The main problem here is that the whole index is recreated every time you execute a reindexing.

Solution:
The way of handling this is by using delta index updates with index merging. The idea is to have 2 indexes:
  • the "main" and big index for the old (unchanged) data, and 
  • a small "delta" for the new (recently changed) data.  So, instead of reindexing the "main" index, you should only reindex the "delta" one every few minutes.
After a while (once a day) you should merge the "delta" and the "main" index (depending of the size of the delta).
This is called "main+delta" scheme.

How-to:
Having a table "documents" with fields: "id, title, body",  we create the sphinx search index as follows:


As you can see the main sql_query give us all the documents from the documents table. The idea of the "main+delta" scheme is that every time you reindex main, you will have to store the last id processed somewhere, so delta can start from there and process a little amount of records.

So first,  create this table in mysql to store that id:

Then in sphinx.conf:

How does this work? As you can see in main specification a pre-fetch query called sql_query_pre appears. That query is executed before the main query (you can have a bunch of those).
REPLACE INTO sph_counter SELECT 1, MAX(id) FROM documents
Our pre-fetch query, updates a record in the sph_counter table to be used later by delta.  This record will store the max(id) from our documents table in the moment of indexing, so the main query will get documents with id less than or equal to that maximum and delta query with ids bigger than that max.

In brief, you update main once in a while, and delta every so often. main will get ALL the documents till the time you update it, and delta will get all the new ones.

In your code you will have to search in both indexes:
$sphinxClient->Query(“this is my search query”, “main delta”);
Indexing main will take a long time too, but you will be sort of "live" because delta will update very quickly.
Instead of reindexing main you can merge both indexes, and only update delta. I will write about merging in a future post.

Links:

20110128

Tips and Tricks - MYSQL - how to dump a database

So you want to backup your mysql database??? Mysql has many ways of doing it, i will explain the easier one: mysqldump.


Being strict, msqldump is not a "backup utility", it creates a script with  "CREATE TABLE" and "INSERT INTO" commands that you can run in your server to re-create your database.  mysqldump  is shipped with MYSQL so everybody should have it installed.

Using mysqldump command line is very straightforward, just type this in your command line or terminal (using your username and password):
mysqldump -u USERNAME -pPASSWORD OUR_DATABASE > filename.sql
This will give us a file (filename.sql) containing "CREATE TABLE" and "INSERT INTO" commands for OUR_DATABASE.
Some times you need to dump ALL your databases (you are moving you dev machine) in your MYSQL server:
mysqldump -u USERNAME -pPASSWORD --all-databases > filename.sql
If you are using MAMP (in macOS), your mysqldump binary is located in /Applications/MAMP/Library/bin/mysqldump.


There is a lot more options here in the official MYSQL documentation: http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html


To restore our database, we have to we have to run this script in our MYSQL server. You can do it using any utility (phpmyadmin for instance) or jus (again) the command line:
mysql -u USERNAME -pPASSWORD DATABASE_NAME < filename.sql
So, good backup!! ;-)



  

20110122

Howto: Share a directory between a Mac OS X machine and Ubuntu over NFS

Today I needed to share a directory between my macbook and a ubuntu virtual machine, I'll show you how. The main idea is to share the directory from my mac and then mount it in the linux machine. This is done using nfs, and here are the steps:

In our mac, open a Terminal and edit /etc/exports:

sudo vi /etc/exports
Add a line with the directory you want to share, and the network you want to grant access, in this case 192.168.0.0/16
/directory_to_share/ -network 192.168.0.0 -mask 255.255.0.0
Restart nfsd service (maybe you should enable this service with: sudo nfsd enable)
sudo nfsd restart
Check if everything is correct
showmount -e
After this you can mount that directory over nfs in another machine, to do this on Linux:

Check if you can reach the Mac and see the exported directories:
showmount -e my_mac_ip_address
If you see the directory in the list you can try to mount it:
sudo mount my_mac_ip_address:/directory_shared/ /mount_point/

Thats all the magic..

20101117

login ssh sin clave

Es muy común preguntarse como hacer para conectarnos de forma automática a equipos remotos para por ejemplo correr procesos.
O simplemente cómo hacer para entrar a otro equipo desde el nuestro sin tener que poner la clave continuamente. Normalmente uno hace lo siguiente para hacer esta conexión:
usuarioA@diego:~$ ssh usuarioB@servidor
usuarioB@servidor's password:  
Luego ingresamos la clave de usuarioB.  Si tenemos que hacer esto todo el tiempo llega un momento que es bastante tedioso, y peor si tenemos que conectarnos a muchos equipos todos con diferentes claves.

Para solucionar esto, primero tenemos que crear un par de claves en nuestro equipo (o desde donde nos queremos conectar) de la siguiente forma (mi sistema operativo es Ubuntu 10.10):

usuarioA@diego:~> ssh-keygen -t rsa

Si no queremos que nos pida una clave cuando nos conectemos simplemente presionar Enter (esto es muy útil para hacer scripts luego). Esto genera una clave pública y una privada en el directorio ~/.ssh

Luego tenemos que copiar la clave publica al equipo al que queremos conectarnos, en este caso el equipo se llama "servidor" con el usuario "usuarioB". Primero tenemos que crear la carpeta ~/.ssh en servidor:
usuarioA@diego:~> ssh usuarioB@servidor mkdir -p .ssh 
usuarioB@servidor's password: 
Luego hay que agregar nuestra clave publica al  .ssh/authorized_keys de servidor :

usuarioA@diego:~> cat .ssh/id_rsa.pub | ssh usuarioB@servidor 'cat >> .ssh/authorized_keys'
usuarioB@servidor's password: 
Ahora nos podemos conectar directamente sin ingresar la clave

usuarioA@diego:~$ ssh usuarioB@servidor
usuarioB@servidor:~$