Diferencia entre revisiones de «Comandos varios»

De gacq wiki
Saltar a: navegación, buscar
 
Línea 152: Línea 152:
 
<pre><nowiki>
 
<pre><nowiki>
 
* * * * *      root if ! ping -c 2 -n 195.22.220.52 >> /dev/null; then aplay informational.au; fi
 
* * * * *      root if ! ping -c 2 -n 195.22.220.52 >> /dev/null; then aplay informational.au; fi
 +
</nowiki></pre>
 +
 +
= Filter =
 +
en /etc/aliases
 +
<pre><nowiki>
 +
gacq:          gacq,"| /usr/bin/filter -o /tmp/filter.err -f /.elm/filter-rules.gacq"
 
</nowiki></pre>
 
</nowiki></pre>

Revisión del 17:11 27 jul 2006

Time Syncronization

ntpdate time.sinectis.com.ar
hwclock --systohc
tzconfig

Recursive find and replace string in files

#!/bin/sh
for tfile in `find . -type f`
do
   cat $tfile | sed "s^$1^$2^" > $tfile.junk
   mv -f $tfile.junk $tfile
done

Usar una unidad de cinta remota

rsh host dd if=/dev/rmt ibs=10k | tar xobf

Una forma de copiar archivos con ssh pero sin scp

Util para cuando tenemos archivos muy grandes y el scp se queda en "stalled"

tar cvzf - dir-o-file | ssh servidor tar xCzf directorio -

delete files older than 7 days

find . -ctime +7 -print | xargs rm -f

Para encontrar IP Address

find / -type f -print | xargs egrep '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+'

Lista de parametros muy grande

intranet:/# grep regexp *
-su: /bin/grep: Argument list too long

Se resuelve con

intranet:/# ls | xargs grep -i regexp

Velocidad de la placa de red

mii-tool

Borrar algo de un archivo

# echo 'g/non-free/d
wq'|ed - /etc/apt/sources.list

Partir un archivo en partes del tamaño de un CD de 700 MB

split -b 

httptunnel

If you are placed behind an HTTP-proxy (with or without user-authentication), you can not simply use ssh to connect to an outside server. Everything else but HTTP is locked.
If for some reason you desperately need to get out, do the following:

server (outside the proxy):
  apt-get install httptunnel
  hts -F localhost:22 1234

client (inside the proxy):
  apt-get install httptunnel
  htc -F 5678 -A proxyuser:proxypwd -P proxy-server remote-host:1234
  ssh -p 5678 localhost

With this, the local port "5678" is tunnelled to "remote-host's" port "22" via an HTTP-protocol-based "connection" between the HTTP-Tunnel-Client and the HTTP-Tunnel-Server (port "1234").
SSH connects to localhost:5678 and reaches remote-host:22 (in this configuration). 

Cambiar hostname

1. Cambiarlo de /etc/hostname
1. init 6

Convertir los archivos txt de DOS a UNIX

Hay varias opciones para sacar los ^M del final de las lineas

# Con tr
tr -d '\15\32' < archivo-dos > archivo-unix

# Con vi
1,$s/^M//g

# Con dos2unix
apt-get install sysutils
dos2unix winfile.txt unixfile.txt

# Con awk
awk '{ sub("\r$", ""); print }' winfile.txt > unixfile.txt

# Con perl
perl -p -e 's/\r$//' < winfile.txt > unixfile.txt

Convertir los archivos txt de UNIX a DOS

Hay varias opciones para sacar los ^M del final de las lineas

# Con unix2dos
apt-get install sysutils
unix2dos unixfile.txt winfile.txt

# Con awk
awk 'sub("$", "\r")' unixfile.txt > winfile.txt

# Con Perl
perl -p -e 's/\n/\r\n/' < unixfile.txt > winfile.txt

Renombrar muchoas archivos a la vez

for i in 'ls *.<oldextension>'; do mv $i ${i/<oldextension>/<newextension>}; done
# Ejemplo:
for i in `ls *.shtml` ; do mv $i ${i/shtml/html}; done


Duplicando una maquina con rsync

rsync -v -r -p -o -g -D -t -S -l -H \
--exclude /mnt/   \
--exclude /proc/ \
--exclude /tmp/ \
--exclude /home/ / /mnt/fireball/

Boot from a CD-ROM and mount the target-disk. Fix fstab and lilo.conf. Create /mnt and /proc and set the right permissions (for this directories). Then run lilo and reboot. Next time you run rsync, add these option to the command-line:

--exclude /etc/fstab \
--exclude /etc/lilo.conf \
--delete 

Duplicando discos sobre la red

#dd if=/dev/hda bs=10k | ssh <IP_DESTINO> dd of=/dev/hda bs=10k

Avisar con sonido cuando se corta la red

En el crontab se puede poner algo como

* * * * *       root if ! ping -c 2 -n 195.22.220.52 >> /dev/null; then aplay informational.au; fi

Filter

en /etc/aliases

gacq:           gacq,"| /usr/bin/filter -o /tmp/filter.err -f /.elm/filter-rules.gacq"