Script about Remote logging control

Per poter svolgere un task a lavoro mi son fatto questo script che controlla se le macchine loggano remotamente, lo posto nel caso a qualcuno servisse per prenderne spunto.
Eccolo.

#!/bin/bash

RLF="macchina remota per il logging"
LIST_FILE=$1

rm CHECKED ERRORS >/dev/null
for hosts in $(cat ${LIST_FILE})
do
	echo "################ START ${hosts} ################"
	echo "Controllo ${hosts}"
	if ! ping -c1 ${hosts} >/dev/null
	then
		echo "Host: ${hosts}, non risponde al ping... Provo gli altri domini"
		for domains in lista di domini alternativi
		do
			c_host=`echo ${hosts} |cut -d. -f1`
			tmp_host="$c_host.${domains}"
			echo "Provo ${tmp_host}"
			if ping -c1 ${tmp_host} >/dev/null
			then
				echo "Trovato! Imposto hosts a ${tmp_host}"
				hosts=${tmp_host}
				break
			fi
		done
	fi
	if ! ssh -o StrictHostKeyChecking=no -o ConnectTimeout=30 root@${hosts} echo
	then
		echo "Errore nella connessione alla macchina ${hosts}"
	fi

	echo "Eseguo il controllo su macchina remota di logging..."
	file_to_find=`echo ${hosts} |cut -d. -f1`

	remote_logging_file=`ssh -o StrictHostKeyChecking=no -o ConnectTimeout=30 root@${RLF} ls /var/remotelog/${file_to_find}*`
	if [ $(echo ${remote_logging_file} |sed -e "s/ /\\n/g" |wc -l) -gt 1 ]
	then
		echo "Occorrenza doppia, provo ${hosts}.log"
		remote_logging_file="/var/remotelog/${hosts}.log"
		result=`ssh root@${RLF} -o StrictHostKeyChecking=no -o ConnectTimeout=30 cat ${remote_logging_file}  |egrep ".*logger.*Rocchi$" |wc -l`
	elif [ -z ${remote_logging_file} ]
	then
		result=0
		MSG_ERR="E_NO_REMOTE_FILE"
	else
		result=`ssh root@${RLF} -o StrictHostKeyChecking=no -o ConnectTimeout=30 cat ${remote_logging_file}  |egrep ".*logger.*Rocchi$" |wc -l`
	fi

	if [ ${result} -lt 1 ]
	then
		echo "CRITICAL ! ${hosts} non sta loggando! check manuale!!"
		echo "${hosts} ${MSG_ERR}" >> ERRORS
	else
		echo "OK! Go On!"
		echo ${hosts} >> CHECKED
	fi
	echo "################ END ${hosts} ################"
done

Stargate Universe e` finalmente arrivato!

Tratto da Wikipedia:

Stargate Universe (abbreviato in SGU) è una serie televisiva di genere fantascientifico (space opera militare), la terza appartenente al franchise di Stargate.

Prodotta dalla Metro-Goldwyn-Mayer e ideata da Brad Wright e Robert C. Cooper, Stargate Universe è trasmessa in prima visione su Syfy dal 2 ottobre 2009.[1] La serie, come le due precedenti, viene girata a Vancouver, in Canada, nei Bridge Studios.

Trama:

Grazie alla scoperta dell’uso del nono Chevron dello Stargate un team di esploratori raggiunge una nave disabitata chiamata Destiny, lanciata dagli Antichi milioni di anni prima in un viaggio esplorativo attraverso le galassie. Frutto di un esperimento iniziato ma mai completato, la Destiny ha il compito di seguire le tracce delle navi che l’hanno preceduta di un milione di anni, “seminando” gli Stargate nei pianeti di numerose galassie. Il gruppo di civili e scienziati raggiungono la Destiny per sfuggire da un attacco alla base segreta in cui si trovano. Molti di loro non sono addestrati per affrontare la situazione, a partire dal giovane Eli Wallace fino al giorno prima genio della matematica disoccupato e videogiocatore incallito che viveva a casa della madre. A complicare le cose l’impossibilità di tornare sulla Terra e di controllare l’astronave, guidata da una sorta di pilota automatico molto avanzato. Fin dai primi episodi le necessità del team sono molto concrete: filtri per l’anidride carbonica, energia, acqua. La nave sembra identificare di volta in volta le necessità e agire di conseguenza e ciò talvolta richiede un certo spirito di adattamento ed intraprendenza ai componenti del team. Una caratteristica peculiare della Destiny è di fermarsi vicino a pianeti a portata di Stargate per un tempo ben preciso, scandito da un conto alla rovescia, trascorso il quale riparte indipendentemente dal fatto che tutti i componenti del team siano riusciti a tornare a bordo. L’astronave si sposta più velocemente della luce ma non tramite l’iperspazio come invece fanno le altre navi degli Antichi, di milioni di anni più recenti.

Finalmente arriva l’attesa nuova serie di Stargate, molti fan sembrano non contenti di questa nuova scelta sia di trama che di casting. Personalmente ho visto le prime puntate in inglese, non e` assolutamente all’altezza di Stargate SG1 ne` di stargate Atlantis, l’inizio e` stato alquanto scontato e prevedibile…

Non resta che attendere le future puntate e vedere come si evolve!

MIT 6.00 Introduction to Computer Science and Programming

The following Youtube video is the first lesson of th 6.00 MIT course. It is a fantastic introduction to computer science.
This comment come from a friend’s blog, I’d really like to have the same kind of lessons here in our Italian university, but I’m afraid not…

However, I’m going to include the video from Youtube.

[youtube]http://www.youtube.com/watch?v=k6U-i4gXkLM[/youtube]
Awesome!

Listkick Plugin for X-Chat

I wrote a little plugin for X-Chat that on special keywords like !list or whatever you want (you can change it), it kick/ban or kill the user whom hit the trigger specified.
Writing /actionk on you client you’ll switch from kick/ban or kill as default action.
In order to compile the sources you need xchat-plugin.h xchat-plugin-win.h from x-chat source files.

Here there are the source code. (Read the full post).

To compile the plugin:

gcc -Wl,--export-dynamic -Wall -O1 -shared -fPIC listkick.c -o listkick.so

Plugin source:

#ifdef WIN32

#include "xchat-plugin-win.h"
#include "mingw32.h"

#else

#include "xchat-plugin.h"

#endif

#include 
#include 
#include 
#include 
#include 

#define VER_MAJOR 0
#define VER_MINOR 0
#define VER_PATCH 2

static int action = 0;
//static int enable = 1;
static xchat_plugin *ph;
static int chanmsg();
static int actionk(char *word[], char *word_eol[], void *userdata);

struct channel {
        char** names;
        int size;
};

int xchat_plugin_init(xchat_plugin *plugin_handle, char **plugin_name, char **plugin_desc, char **plugin_version, char *arg) {
	ph = plugin_handle;
	*plugin_name = "Kick/gline script by blackms";
  	*plugin_desc = "Choose Action kick/ban or gline on !list";
	*plugin_version = "0.0.2";

	xchat_hook_print(ph, "Channel Message", XCHAT_PRI_NORM, chanmsg, NULL);
	xchat_hook_command(ph, "actionk", XCHAT_PRI_NORM, actionk, "Usage: actionk, Choose Kick/ban or kill", NULL);
	xchat_printf( ph, "Kick/gline script by blackms %d.%d.%d loaded", VER_MAJOR, VER_MINOR, VER_PATCH );

	return 1;
}

static int actionk(char *word[], char *word_eol[], void *userdata) {
	if (action == 0 ) {
		action = 1;
		xchat_printf(ph, "Kill mode enabled.");
	} else if (action == 1) {
		action = 0;
		xchat_printf(ph, "kick/ban mode enabled.");
	}

	return 1;
}

int xchat_plugin_deinit(xchat_plugin *plugin_handle)
{
	xchat_printf( ph, "Kick/gline script by blackms unloaded\n" );

	return 1;
}

void add_chan(char *name, struct channel* obj) {
	obj->size++;
	obj->names=realloc(obj->names,(obj->size+1) * sizeof(char *));
	obj->names[obj->size] = strdup(name);

	return;
}

static int chanmsg(char *word[], void *userdata) {
	struct channel chan;
    chan.size = 0;
    chan.names=malloc(sizeof(char*));

	add_chan("#fusion",&chan);
	add_chan("#irchelp",&chan);

	if (!strncasecmp(word[2], "!list",5)) {
		int cnt=0;
		for (cnt = 1; cnt <= chan.size; cnt++) {
  			if ((strcasecmp(xchat_get_info(ph, "channel"),chan.names[cnt]) == 0))
				return XCHAT_EAT_NONE;
		}

		xchat_context *prevctx;
		prevctx = xchat_get_context(ph);
		xchat_set_context(ph, xchat_find_context(ph, NULL, xchat_get_info(ph, "channel")));

		const char* host;
		xchat_list *list = xchat_list_get(ph, "users");
		while(xchat_list_next(ph, list)) {
			if (strncasecmp(xchat_list_str(ph, list, "nick"), word[1], (size_t )strlen(word[1])) == 0 )
				host = xchat_list_str(ph, list, "host");
		}

		if (action == 0) {
			xchat_commandf(ph, "ban %s",host);
			xchat_commandf(ph, "kick %s Accendere il cervelloprima di accendere il PC?", word[1]);
		} else if(action == 1) {
			xchat_commandf(ph, "kill %s Accendi il cervello prima di accendere il PC.", word[1]);
			/*xchat_printf(ph,"Triggered list on channel %s by user %s, prefixed by %s", xchat_get_info(ph, "channel"), word[1], word[3]);*/
			xchat_set_context(ph, prevctx);
			return XCHAT_EAT_PLUGIN;
		}
	} else {
		return XCHAT_EAT_NONE;
	}

	return XCHAT_EAT_NONE;
}

I hope this will useful to someone, for me yes :) was been very useful! *evil*.

Please leave any comment if you want.