Prezados,<br><br> esta é minha primeira mensagem para esta lista.<br><br> Começo com uma questão interessante. Fiz o script abaixo para obter em formato CSV valores de alguns fundos de investimento. Gostaria de anexar este comportamento à funcionalidade de busca automática de cotações, mas não sei por onde começar. Alguém palpita?<br>

<br><font size="1"><span style="font-family: courier new,monospace;">#!/bin/bash</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"># Copyright (C) Leonardo F. Cardoso (não experiente com shell script)</span><br style="font-family: courier new,monospace;">

<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">#####################################################</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">CAMINHO=/home/leonardo/Leo</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">DATA_FINAL=$(date +%d/%m/%Y)</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">DATA_FINAL_TXT=$(date +%d-%m-%Y)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">DATA_INICIAL=$(date --date=&quot;5 days ago&quot; +%d/%m/%Y)</span><br style="font-family: courier new,monospace;">

<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">wget -o $CAMINHO/wgetFundos.log -O $CAMINHO/fundos-$DATA_FINAL_TXT.html --post-data=&quot;data_inicio=$DATA_INICIAL&amp;data_fim=$DATA_FINAL&amp;fundos_ok=&#39;123242&#39;&quot; <a href="http://www.anbid.com.br/prodserv/recuperar_fim.asp">http://www.anbid.com.br/prodserv/recuperar_fim.asp</a></span><br style="font-family: courier new,monospace;">

<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"># Até agora, obtivemos os dados ainda em formato HTML, vamos obter as cotas mais recentes</span><br style="font-family: courier new,monospace;">

<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">html2text $CAMINHO/fundos-$DATA_FINAL_TXT.html | while read LINHA_LIDA</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">do</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    if [[ $LINHA_LIDA == &quot;Fundo: &quot;* ]]</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">    then</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">        NOME_FUNDO=$(echo $LINHA_LIDA | gawk &#39;{ match ($0, /Fundo: .* Tipo: /, arr);  print arr[0]}&#39; | gawk &#39;{sub (/Fundo: /, &quot;&quot;); sub (/ Tipo:/,&quot;&quot;); print }&#39;)</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">        # Guardamos o nome do fundo atualmente em processamento em NOME_FUNDO</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">        # echo &quot;DEBUG&quot; $NOME_FUNDO</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">    fi</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    # Prossegue lendo linhas até encontrar uma linha com o separador</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">    # Separador = &quot;================================&quot;*</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    </span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">    if [[ $LINHA_LIDA == &quot;================================&quot;* ]]</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    then</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">        DATA_FUNDO=$(echo $LINHA_ANTERIOR | gawk &#39;BEGIN {FS=&quot;|&quot;} { print $2 }&#39; | gawk &#39;{sub (/_/, &quot;&quot;); print}&#39;)  </span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">        # echo &quot;DEBUG&quot; $DATA_FUNDO</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">        VALOR_FUNDO=$(echo $LINHA_ANTERIOR | gawk &#39;BEGIN {FS=&quot;|&quot;} { print $4 }&#39; | gawk &#39;{sub (/_/, &quot;&quot;); print}&#39;)  </span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">        # echo &quot;DEBUG&quot; $VALOR_FUNDO</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">        </span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">        echo $DATA_FUNDO&quot;;&quot;$VALOR_FUNDO&quot;;&quot;$NOME_FUNDO </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    fi</span><br style="font-family: courier new,monospace;">

<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    # Guarda a linha anterior pois no momento em que houver o separador, a cota estará nela</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">    LINHA_ANTERIOR=$LINHA_LIDA</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">done</span><br style="font-family: courier new,monospace;">

</font><br><br> Sds<br> Leonardo<br><br clear="all">-----------------------------------------<br>Leonardo F. Cardoso<br>leonardo.f.cardoso &quot;at&quot; <a href="http://gmail.com" target="_blank">gmail.com</a><br>leofcar &quot;at&quot; <a href="http://ig.com.br" target="_blank">ig.com.br</a> (Alternativo)<br>


MSN: <a href="mailto:lfcardoso@hotmail.com" target="_blank">lfcardoso@hotmail.com</a><br>-----------------------------------------<br>