Almacenar variables con AWK


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Almacenar variables con AWK
# 1  
Old 04-20-2010
Almacenar variables con AWK

Hola a todos, soy nuevo en el foro y también en programación Shell Script.

El problema es el siguiente:
necesito hacer un Script que busque todos los procesos del sistema y me muestre de forma jerárquica la cantidad de Bytes que ocupa cada una de las regiones del mapa de memoria de cada proceso.

Actualmente he conseguido que me muestre la cantidad de regiones en el mapa de memoria, esto lo hice solo para checar si en realidad esta funcionando el AWK, ahora lo que no he logrado es almacenar en 2 variables las direcciones de memoria que aparecen en la primera cadena de cada linea del fichero MAPS, entiendo que la dirección está en hexadecimal debo restar la dirección "menor" a la "mayor" pero primero cambiar la cadena a mayúsculas separarla en dos variables (así lo entiendo) y luego realizar la operación para que ahora si me muestre los dichosos BYtes que necesito jeje

Aqui les dejo Parte del fichero MAPS:

00110000-00126000 r-xp 00000000 08:01 8051 /usr/lib/libnssutil3.so
00126000-00129000 r--p 00015000 08:01 8051 /usr/lib/libnssutil3.so
00129000-0012a000 rw-p 00018000 08:01 8051 /usr/lib/libnssutil3.so
0012a000-0012d000 r-xp 00000000 08:01 7711 /usr/lib/libgmodule-2.0.so.0.2200.2
0012d000-0012e000 r--p 00002000 08:01 7711 /usr/lib/libgmodule-2.0.so.0.2200.2


El Script es el siguiente:
#!/bin/sh
#!/bin/bash

filtrado()
{
RES=0
echo "PROCESO $n"
cat /proc/"$n"/maps |sed 's/-/ /' | awk 'END {print "TOTAL:",NR;}'

awk '$2~/[p]/{ RES=RES+1;};END{print " PRIVADOS:",RES;}' /proc/"$n"/maps

awk '$2~/[p]/ && $4~/[1]/ {RES=RES+1;};END{print " CON SOPORTE:",RES;}' /proc/"$n"/maps

awk '$2~/[w]/ && $2~/[p]/ && $4~/[1]/ {RES=RES+1;};END{print " MODIFICABLES:",RES;}' /proc/"$n"/maps

awk '$2~/[x]/ && $2~/[p]/ && $4~/[1]/ {RES=RES+1;};END{print " EJECUTABLES:",RES;}' /proc/"$n"/maps

awk '$2~/[r]/ && $2!~/[w]/ && $2~/[p]/ && $4~/[1]/ {RES=RES+1;};END{print " SOLO LECTURA:",RES;}' /proc/"$n"/maps

awk '$5!~/[1-9]/ && $2~/[p]/ {RES=RES+1;};END{print " ANONIMOS:",RES;}' /proc/"$n"/maps

awk '$2~/[w]/ && $2~/[p]/ && $5!~/[1-9]/ {RES=RES+1;};END{print " MODIFICABLES:",RES;}' /proc/"$n"/maps

awk '$2~/[x]/ && $2~/[p]/ && $5!~/[1-9]/ {RES=RES+1;};END{print " EJECUTABLES:",RES;}' /proc/"$n"/maps

awk '$2~/[r]/ && $2!~/[w]/ && $2~/[p]/ && $5!~/[1-9]/ {RES=RES+1;};END{print " SOLO LECTURA:",RES;}' /proc/"$n"/maps

awk '$2~/[s]/{ RES=RES+1;};END{print " COMPARTIDOS:",RES;}' /proc/"$n"/maps

awk '$2~/[s]/ && $4~/[1]/ {RES=RES+1;};END{print " CON SOPORTE:",RES;}' /proc/"$n"/maps

awk '$2~/[w]/ && $2~/[s]/ && $4~/[1]/ {RES=RES+1;};END{print " MODIFICABLES:",RES;}' /proc/"$n"/maps

awk '$2~/[x]/ && $2~/[s]/ && $4~/[1]/ {RES=RES+1;};END{print " EJECUTABLES:",RES;}' /proc/"$n"/maps

awk '$2~/[r]/ && $2!~/[w]/ && $2~/[s]/ && $4~/[1]/ {RES=RES+1;};END{print " SOLO LECTURA:",RES;}' /proc/"$n"/maps

awk '$5!~/[1-9]/ && $2~/[s]/ {RES=RES+1;};END{print " ANONIMOS:",RES;}' /proc/"$n"/maps

awk '$2~/[w]/ && $2~/[s]/ && $5!~/[1-9]/ {RES=RES+1;};END{print " MODIFICABLES:",RES;}' /proc/"$n"/maps

awk '$2~/[x]/ && $2~/[s]/ && $5!~/[1-9]/ {RES=RES+1;};END{print " EJECUTABLES:",RES;}' /proc/"$n"/maps

awk '$2~/[r]/ && $2!~/[w]/ && $2~/[s]/ && $5!~/[1-9]/ {RES=RES+1;};END{print " SOLO LECTURA:",RES;}' /proc/"$n"/maps

echo " "

}

clear
for n in `seq 1 10000`;
do
m=/proc/$n/maps
if [ -f $m ]; then
filtrado $n
fi
done
exit



de antemano gracias, espero haberme dado a entender

---------- Post updated at 01:08 PM ---------- Previous update was at 01:05 PM ----------

sorry, I can´t put post in spanish Smilie
# 2  
Old 04-20-2010
Hello.

Per our forum rules, all posts must be in English.

We do provide translation services for posts from English to a number of languages as a benefit to users. However, posts must be in English.

Please repost in English.

Thank you for your cooperation.

The UNIX and Linux Forums.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Passing awk variables to bash variables

Trying to do so echo "111:222:333" |awk -F: '{system("export TESTO=" $2)}'But it doesn't work (2 Replies)
Discussion started by: urello
2 Replies

2. Shell Programming and Scripting

awk - Why can't value of awk variables be passed to external functions ?

I wrote a very simple script to understand how to call user-defined functions from within awk after reading this post. function my_func_local { echo "In func $1" } export -f my_func_local echo $1 | awk -F"/" '{for (k=1;k<=NF;k++) { if ($k == "a" ) { system("my_local_func $k") } else{... (19 Replies)
Discussion started by: sreyan32
19 Replies

3. Shell Programming and Scripting

ksh passing to awk multiple dyanamic variables awk -v

Using ksh to call a function which has awk script embedded. It parses a long two element list file, filled with text numbers (I want column 2, beginning no sooner than line 45, that's the only known thing) . It's unknown where to start or end the data collection, dynamic variables will be used. ... (1 Reply)
Discussion started by: highnthemnts
1 Replies

4. Shell Programming and Scripting

estrarre più righe con awk da files html

salve a tutti, sono nuovo di questo forum e sono nuovo anche come shell scripter diciamo. il mio problema è quello di avere dei files html in una directory e da questi vorrei estrarre un dato che si trova tra due righe differenti Ecco la mia situazione <td align="default">ossidabilità (mg/l): ... (1 Reply)
Discussion started by: sbobotex
1 Replies

5. Shell Programming and Scripting

Eliminar lineas con ******

Hola. Tengo un problema. En un archivo tengo distintos campos y en alguno de ellos y en alguna linea me aparecen ******. ej: hola 0.1 ****** 85 adios 1.2 9650 23 gracias 2 ****** 54 bye 87 5666 89 hi ... (1 Reply)
Discussion started by: kekaes
1 Replies

6. Shell Programming and Scripting

Almacenar variables con AWK

Hola a todos, soy nuevo en el foro y también en programación Shell Script. El problema es el siguiente: necesito hacer un Script que busque todos los procesos del sistema y me muestre de forma jerárquica la cantidad de Bytes que ocupa cada una de las regiones del mapa de memoria de cada... (1 Reply)
Discussion started by: cougar_rea
1 Replies

7. Shell Programming and Scripting

Almacenar variables con AWK

Hola a todos, soy nuevo en el foro y también en programación Shell Script. El problema es el siguiente: necesito hacer un Script que busque todos los procesos del sistema y me muestre de forma jerárquica la cantidad de Bytes que ocupa cada una de las regiones del mapa de memoria de cada proceso. ... (1 Reply)
Discussion started by: cougar_rea
1 Replies

8. Shell Programming and Scripting

prime armi con sed e awk

Salve sono alle prime prese con i comandi sed e awk. Nel primo caso vorrei creare uno script in cui viene estratto la partizione maggiore. in più ci deve essere un messaggio d'avviso se supera l' 80 % dello spazio occupato. Ho pensato di usare il comando df -h, e l' awk. Mi potete dire come?... (1 Reply)
Discussion started by: L_92
1 Replies

9. UNIX for Dummies Questions & Answers

Parse XML e report con AWK

Thanks in advance who can answer. I have to make a small shell that after reading an XML file and extract the fields I create a text file with the same fields taken previously in tabular form. I did this parse.awk ---------------------- BEGIN { FS="" } { for(i=2; i<=NF; i+=2) { ... (1 Reply)
Discussion started by: mcarlo65
1 Replies

10. What is on Your Mind?

BT Internet con - a warning

A warning... I used to be a BT Broadband customer, but changed to Sky in February. BT withdrew the service with the cutover and that was that. But I've just checked my credit card statements, and they've billed me for the service again for the past two months! (2 Replies)
Discussion started by: prowla
2 Replies
Login or Register to Ask a Question