9/25/2009

JAVA - Listar/Recuperar processos em execução do Windows

// Checar a existencia do executável : tasklist.exe

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class ListarProcessosWindows {


public static void main(String[] args) {

try {

String command = "c:\\windows\\system32\\tasklist.exe";
Process child = Runtime.getRuntime().exec(command);

InputStream in = child.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
ArrayList saida = new ArrayList();
String linha = "";
while( ( linha = reader.readLine() ) != null ){
String[] str = linha.split(" ");
saida.add(str[0]);
}
in.close();

for (String s : saida) {
System.out.println(s);
}

} catch (IOException e) {
}


}


}

10/05/2007

Squid Autenticando no MySQL

Requisitos:
- Base MySQL com "alguma" tabela/view que contenha usuário e senha, para fazer a autenticacao;
- Squid instalado;

Script de Autenticação em Shell
- Criar o script, por exemplo:
touch > /etc/squid/auth_squid.sh
chmod 775 /etc/squid/auth_squid.sh

- Editar o script: vi /etc/squid/auth_squid.sh e adicionar o seguinte conteúdo no arquivo.

#!/bin/sh

MY="mysql -u root nomebasededados -e "
i=0
while [ $i -lt 4 ]
do
QRY="SELECT IF(COUNT(*) = 0,'ERR','OK') as NUM
FROM tabela_de_auth
WHERE LOWER(login) = LOWER('pLOGIN') AND
LOWER(senha) = LOWER('pSENHA')"

read vlr;

LOGIN=`echo $vlr | awk '{print $1}'`
SENHA=`echo $vlr | awk '{print $2}'`

if [ -z "$LOGIN" ]
then
echo "ERR"
i=$((i+1))
elif [ -z "$SENHA" ]
then
echo "ERR"
i=$((i+1))
else

QRY=`echo $QRY | sed "s/pLOGIN/$LOGIN/g"`
QRY=`echo $QRY | sed "s/pSENHA/$SENHA/g"`

$MY "$QRY" | while read res;
do

if test $res != "NUM"
then
echo $res

if test $res == "ERR"
then
i=$(expr $i + 1)
fi

fi

done

fi

done

10/08/2006

Primeira postagem

Primeira Postagem :)