my code stock.com

Snippet options

Download: Download snippet as wdatefieldsh.txt.
Copy snippet: For this you need a free my code stock.com account.
Embed code : You will find the embed code for this snippet at the end of the page, if you want to embed it into a website or a blog!

#!/bin/bash
# Noilson Caio
# 22 / abril / 2010
#
# Notifica tickets vencidos do datefiel, plugin do TRAC.
# Busca Tickets que se vencem na data atual de execucao do script
#
# data - equivale ao formato utilizado no trac.ini, vaiavel due_date.value em [ticket-custom]
# url - url do TRAC
# 
#
#
data="$(date +%d-%m-%Y)"
url="trac.dominio.com"
#
# chaveaut - qualquer numero diferente de zero habilita a autenticacao
# Se chaveaut = 1 
# usuario - usuario com permissoes de realizarconsultas no TRAC
# senha - senha do usuario
# 
chaveaut="1"
usuario="usuario"
senha="senha"
#
# saida - arquivo de retorno da consuta
#
saida="$(mktemp)"
#
# mail - endereco de email onde sera enviado o aviso
#
mail="[email protected]"
#
# Localiza e testa os principais programas envolvidos no processo
#
sedbin="$(which sed)"
mailbin="$(which mail)"
wgetbin="$(which wget)"
#
# Testa binarios
#
for i in "$sedbin" "$mailbin" "$wgetbin"
do
	if [ ! -e "$i" ]
	then
		echo "binario nao encontrado"
		exit 127
	fi
done
#
#
# Consulta autenticada
#
consultaaut()
{
wget -q "http://"$url"/query?status=accepted&status=assigned&status=new&status=reopened&due_date=%7E"$data"&format=csv&order=priority&col=id&col=summary&col=due_date&col=status&col=owner&col=milestone&col=component" --user="$usuario" --password="$senha" -O "$saida"
}
#
# Consulta sem autenticacao
#
consulta()
{
wget -q "http://"$url"/query?status=accepted&status=assigned&status=new&status=reopened&due_date=%7E"$data"&format=csv&order=priority&col=id&col=summary&col=due_date&col=status&col=owner&col=milestone&col=component" -O "$saida"
}
#
# Testa chave de autenticacao
#
if [ "$chave" != "0" ]
then
	consultaaut
else
	consulta
fi
#
# Testa resultado da consulta
#
conteudo=$(cat $saida | sed -e 1d)
if [ -z "$conteudo" ];
then
	exit
else
	sed -i 1d "$saida"
	while read ticket
	do
		id=$(echo $ticket | cut -d',' -f 1)
		sumario=$(echo $ticket | cut -d',' -f 2)
		dono=$(echo $ticket | cut -d',' -f 5)
#
# MSG
#
msg()
{
echo "
ticket de id: $id - http://"$url"/ticket/"$id" [ $sumario ] responsavel : $dono. Vence hoje, "$data"
"
}
#
# Notifica por email
#
		msg | mail -s "ticket de id: [ $id ] - Data limite" "$mail"
#
# Limpa fila
#
		sed -i 1d "$saida"
	done < "$saida"
#
# Limpa tempfile
#
	rm -rf "$saida"
#
fi
exit 0

Create a free my code stock.com account now.

my code stok.com is a free service, which allows you to save and manage code snippes of any kind and programming language. We provide many advantages for your daily work with code-snippets, also for your teamwork. Give it a try!

Find out more and register now

You can customize the height of iFrame-Codes as needed! You can find more infos in our API Reference for iframe Embeds.