martes, 20 de noviembre de 2012

Guia de programación Bash-Scripting



Advanced Bash-Scripting Guide

An in-depth exploration of the art of shell scripting

Mendel Cooper

6.5
05 Apr 2012
Revision History
Revision 6.327 Apr 2011Revised by: mc
'SWOZZLEBERRY' release
Revision 6.430 Aug 2011Revised by: mc
'VORTEXBERRY' release
Revision 6.505 Apr 2012Revised by: mc
'TUNGSTENBERRY' release

This tutorial assumes no previous knowledge of scripting or programming, but progresses rapidly toward an intermediate/advanced level of instruction . . . all the while sneaking in little nuggets of UNIX® wisdom and lore. It serves as a textbook, a manual for self-study, and a reference and source of knowledge on shell scripting techniques. The exercises and heavily-commented examples invite active reader participation, under the premise that the only way to really learn scripting is to write scripts.
This book is suitable for classroom use as a general introduction to programming concepts.


http://tldp.org/LDP/abs/html/

viernes, 9 de noviembre de 2012

Linux Pipe


 echo ""> command.txt    //Borra el contenido del archivo

asterisk -rx "core show channels" >command.txt  // manda  la salida de este commando al archivo txt


asterisk -x "core show help" | less // Nos muesta la lista de commandos en Asterisk con pausa en el sistema


 cat /etc/asterisk/sip.conf | grep -i 102


resultado
[102]
username=102
secret=102


Linux PIPE


Standard output >

Many Linux commands print their output to screen. For example, ls does this when it lists the contents of a directory: you see the output, the directory listing, on your screen. cat does the same: it concatenates a file and sends the results to your screen, and thus you can see the file's contents. But the screen isn't the only place where the commands can print their output because you canredirect the output of several commands to files, devices, and even to the input of other commands.
The CLI programs that display their results do so usually by sending the results to standard output, or stdout for short. By default, standard output directs its contents to the screen, as you've seen with the ls and cat commands. But if you want to direct the output to somewhere else, you can use the > character. For example, to redirect the output to a file, you can use the > character like this:
ls > dir_listing.txt
The above redirects the output of the ls command to a file called dir_listing.txt. Because the output is redirected to a file, you don't see any results of ls on your screen.
Each time you repeat the above command, the file dir_listing.txt is overwritten with the results of the ls command. If you want to append the new results to the file instead of rewriting it, you can use >> instead:
ls >> dir_listing.txt
Each time you repeat the above command, the new output of ls is added at the end of the dir_listing.txt file instead of overwriting the file.
The following adds the contents of File1 at the end of File2:
cat File1 >> File2
Like I told you before, files aren't the only places where you can redirect the standard output. You can redirect it to devices, too:
cat sound.wav > /dev/audio
As you saw, in the above example the cat command concatenates a file named sound.wav and the results are sent to a device called /dev/audio. What's the fun here, then? /dev/audio is the audio device, and when you send there the contents of a sound file, that file is played. So if your sound is properly configured, the above command plays the file sound.wav!

sábado, 3 de noviembre de 2012

Linux Grep Command


HowTo: Use grep Command In Linux / UNIX [ Examples ]

by  on AUGUST 2, 2007 · 221 COMMENTS· last updated at DECEMBER 11, 2011
How do I use grep command in Linux and Unix like operating systems? Can you give me a simple example of grep command?

Como ve el espacio disponible en el Disco Duro y el tamañod de los archivos y directorios



root@Asterisk-PBX:~# df  -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1              36G  4.7G   30G  14% /
udev                  490M  4.0K  490M   1% /dev
tmpfs                 199M  280K  199M   1% /run
none                  5.0M     0  5.0M   0% /run/lock
none                  497M     0  497M   0% /run/shm

Para ver el tamaño de los archivos en una carpeta en formato KB,MB,GB
corremos el commando  ls -lah
 
Para ver el tamaño de los directorios o carpeta corremos el comando  du -h /carpeta-a-mostrar
 Ejemplo : du -h /var