Acesso direto ao conteúdo
Logotipo Dicas-L, por Ricardo Burile

Busca

Visite também: Segurança Linux ·  UnderLinux ·  VivaOLinux ·  LinuxSecurity ·  NoticiasLinux ·  BR-Linux ·  SoftwareLivre.org ·  [mais]   
 

Você está aqui: Home  → Arquivo Dicas-L

 

Aprenda inglês de uma vez por todas

Assine a Lista Dicas-L

Receba diariamente por email as dicas
de informática publicadas neste site
Para se descadastrar, clique aqui.

Automatização de criação de páginas em servidores Web (2 de 2)

Colaboração: Rubens Queiroz de Almeida

Data de Publicação: 01 de Julho de 1997

A seguir encontra-se a shell script que faz a implementação da automatização do serviço mantido pela lista Dicas-L. A explicação encontra-se dentro dos comentários da shell.


  #!/bin/ksh
  #------------------------------------------------------------------------------
  
  #------------------------------------------------------------------------------
  # Definicao das variaveis
  # A variavel TIP_FILE e usada varias vezes no decorrer deste script
  # Todos os arquivos de dicas recebem o nome de acordo com a data
  # do dia em que sera veiculada, de modo a facilitar a automatizacao
  # do envio das mensagens. O comando 
  # date +%y+%m+%d gera como saida uma string como 970630, que ira
  # servir como prefixo de todos os arquivos gerados.
  #------------------------------------------------------------------------------
  PATH=/home/queiroz/bin:/bin:/usr/bin:/etc:/usr/sbin:/usr/ucb:/usr/local/bin
  TIP_FILE=""date +%y%m%d""
  #------------------------------------------------------------------------------
  # Todos os arquivos gerados encontram-se em /usr/local/www/docs/dicas-l
  # Dai o deslocamento para la.
  #------------------------------------------------------------------------------
  cd /usr/local/www/docs/dicas-l
  #------------------------------------------------------------------------------
  # Criacao dos arquivos .doc e temporarios
  # A criacao destes arquivos e feita atraves da edicao do arquivo original.
  # o arquivo de sufixo .src.
  # Sao substituidas as diretivas originais, descritas na dica anterior,
  # por diretivas html, para criacao do arquivo html.
  # Para a criacao do arquivo de extensao .doc, as diretivas sao eliminadas
  #
  # Os comandos ao editor foram espacejados para facilitar a compreensao
  # do que esta se passando. Observar que todas as diretivas para conversao
  # em diretivas html, contidas no arquivo .src, encontram-se na primeira
  # posicao.
  #
  # Apos a substituicao das diretivas, e gravado o arquivo html
  # w! $TIP_FILE.tmp
  # Em seguida, as diretivas sao eliminadas e e' gravado entao o arquivo
  # de extensao .doc:
  # w! $TIP_FILE.doc
  # Apos esta etapa e' encerrada a edicao. O arquivo de extensao .src
  # permanece inalterado.
  #------------------------------------------------------------------------------
  ed $TIP_FILE.src << EOF
  g:^\~:                                s:$:\~\~:=
  g:^\~:                                s::<H1><FONT COLOR="#B22222">:=
  g:\~\~$:                              s::</FONT></H1>:=
  2s:^:<HR><P>:
  g:^--:                                s::<HR>:
  g:^\.\.:                              s::<PRE><FONT COLOR="#0000FF">:
  g:^;;:                                s::</FONT></PRE>:
  g:^\.:                                s::<P>:
  w! $TIP_FILE.tmp
  g:<H1>:                               s::
  g:<PRE><FONT COLOR="#0000FF">:        s::
  g:<FONT COLOR="#B22222">:             s::
  g:</FONT></H1>:                       s::
  g:<P>:                                s::
  g:</P>:                               s::
  g:</FONT></PRE>:                      s::
  g:</H1>:                              s::
  g:<HR>:s::--------------------------------------------------------------------:
  w! $TIP_FILE.doc
  q
  EOF
  #------------------------------------------------------------------------------
  # Montagem do arquivo html e definicao da tag <TITLE>[Dicas-L] ...</TITLE>
  # O arquivo html final e criado a partir da concatenacao de tres outros:
  # 1. O arquivo de cabecalho (dica.head.html)
  # 2. O arquivo temporario, criado na edicao do arquivo de extensao .src
  #    ($TIP_FILE.tmp)
  # 3. O arquivo de rodape (dica.tail.html)
  #------------------------------------------------------------------------------
  cat dica.head.html $TIP_FILE.tmp dica.tail.html > $TIP_FILE.html
  #------------------------------------------------------------------------------
  # A seguir, o arquivo html gerado e editado para inclusao do
  # titulo e da data de criacao
  # O titulo esta sempre localizado na linha de numero 4
  #------------------------------------------------------------------------------
  ex $TIP_FILE.html << EOF
  4s/Dicas-L/[Dicas-L] ""head -n 1 $TIP_FILE.doc""
  g:Última Modificação\: DATA:s:DATA:""date +%d/%m/%y"":
  w
  q
  EOF
  #------------------------------------------------------------------------------
  # Remocao dos acentos do arquivo .doc
  # Todos os acentos do arquivo de extensao .doc sao removidos
  # para gerar o arquivo de extensao .txt, que e' o arquivo que
  # sera enviado aos assinantes da lista.
  # Para isto utilizamos o shell script chamado tiraacento, que
  # ja foi discutido nesta lista
  #------------------------------------------------------------------------------
  tiraacento $TIP_FILE.doc $TIP_FILE.txt
  #------------------------------------------------------------------------------
  # Inclusao mensagem da dicas-l no arquivo .txt
  # Neste ponto sao incluidas as instrucoes sobre como se descadastrar
  # da lista contidas no arquivo tail.txt
  #------------------------------------------------------------------------------
  cat tail.txt >> $TIP_FILE.txt
  #------------------------------------------------------------------------------
  # Inclusao da dica do dia na listagem geral
  # A listagem de todas as dicas e' tambem atualizada diariamente de maneira
  # a permitir que os usuarios tenham o acesso direto a toda a documentacao
  # ja criada.
  #------------------------------------------------------------------------------
  echo "<P><IMG SRC="/icons/b042.gif" HEIGHT=21 WIDTH=21><A HREF="$TIP_FILE.html">""head -n 1 $TIP_FILE.doc""</A></P>" >> listagem.$$.html
  #------------------------------------------------------------------------------
  # Atualizacao arquivo listagem.body.html
  # Criacao da listagem de dicas
  # A listagem de dicas e' criada a partir da concatenacao de outros arquivos
  # como exemplificado abaixo. Nesta listagem, a dica mais recente sempre
  # e a primeira a aparecer na listagem.
  #------------------------------------------------------------------------------
  cat listagem.$$.html listagem.body.html > listagem.body.tmp
  mv listagem.body.tmp listagem.body.html
  cat listagem.head.html listagem.body.html listagem.tail.html > listagem.html
  #------------------------------------------------------------------------------
  # Atualiza Indice
  # E gerado tambem um arquivo chamado 00index.txt, tambem atualizado
  # diariamente e colocado no servidor ftp anonimo da Unicamp
  # http://ftp.unicamp.br
  #------------------------------------------------------------------------------
  echo "$TIP_FILE.[doc|txt] --- ""head -n 1 $TIP_FILE.txt""" >> 00index.txt
  #------------------------------------------------------------------------------
  # Atualiza repositório DICAS-L
  # Transferencia dos arquivos gerados para o servidor ftp
  # anonimo da Unicamp
  #------------------------------------------------------------------------------
  ftp -ni ftp.unicamp.br << EOF
  user queiroz
  cd /pub/pub/dicas-l
  mput 00index.txt $TIP_FILE.txt $TIP_FILE.doc
  quit
  EOF
  #------------------------------------------------------------------------------
  # Envia a mensagem para os assinantes
  #------------------------------------------------------------------------------
  for user in ""awk '{print $1}' /usr/server/lists/DICAS-L/.subscribers""
  do
  mail -s "[DICAS-L] ""head -n 1 $TIP_FILE.txt""" $user < $TIP_FILE.txt
  echo $user
  done
  #------------------------------------------------------------------------------
  # Remocao arquivos de trabalho
  #------------------------------------------------------------------------------
  rm *.tmp listagem.$$.html

A seguir encontra-se a listagem dos arquivos de cabeçalho e de rodapé utilizados:


dica.head.html


  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
  <HTML>
  <HEAD>
     <TITLE>Dicas-L</TITLE>
     <META NAME="GENERATOR" CONTENT="Mozilla/3.0Gold (X11; I; AIX 1) [Netscape]">
  </HEAD>
  <BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#0000EE" VLINK="#551A8B" ALINK="#FF0000">
  <P><H1 ALIGN=RIGHT><A HREF="http://www.dicas-l.com.br"><IMG SRC="dicas-l.gif" BORDER=0 HEIGHT=80 WIDTH=150></A></H1></DIV>

dica.tail.html


  <HR WIDTH="100%">
  <FONT SIZE=-1>
  <BR><A HREF="http://www.unicamp.br">Universidade Estadual de Campinas</A>
  <BR><A HREF="http://www.unicamp.br/CCUEC">Centro de Computa&ccedil;&atilde;o</A>
  <BR>Autor:<A HREF="mailto:queiroz@ccuec.unicamp.br">Rubens Queiroz de Almeida</A>
  <BR>Última Modificação: DATA
  </FONT></P>
  
  </BODY>
  </HTML>

listagem.head.html


  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
  <HTML>
  <HEAD>
     <TITLE>Dicas-L - Sumario</TITLE>
     <META NAME="GENERATOR" CONTENT="Mozilla/3.0Gold (X11; I; AIX 1) [Netscape]">
  </HEAD>
  <BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#0000EE" VLINK="#551A8B" ALINK="#FF0000">
  <H1 ALIGN=RIGHT><A HREF="http://www.dicas-l.com.br"><IMG SRC="dicas-l.gif" BORDER=0 HEIGHT=80 WIDTH=150></A></H1></DIV>
  </BODY>
  </HTML>

listagem.body.html


  <P><IMG SRC=/icons/b042.gif HEIGHT=21 WIDTH=21><A HREF=970627.html>Caracteres invisíveis</A></P>
  <P><IMG SRC=/icons/b042.gif HEIGHT=21 WIDTH=21><A HREF=970626.html>O comando sort (4)</A></P>
  <P><IMG SRC=/icons/b042.gif HEIGHT=21 WIDTH=21><A HREF=970625.html>O comando sort (3)</A></P>
      .... e muito mais

00index.txt


  
                              =======
                              DICAS-L
                              =======
  
  Este diretorio contem a lista completa das dicas veiculadas na
  lista dicas-l. As dicas diarias podem ser encontradas em dois
  arquivos com extensao .[doc|txt] e extensao .txt. Os arquivos com 
  extensao .[doc|txt] sao acentuados ao passo que os arquivos com extensao
  txt nao sao.
  
  As dicas sao identificadas pelo dia em que foram veiculadas e por
  sua extensao ([doc|txt] ou txt). Desta forma o arquivo que contem a dica
  do dia 11 de abril de 1997 se chamara 110497.txt ou 110497.[doc|txt].
  
  As dicas encontram-se em ftp.unicamp.br:/pub/dicas-l. Em breve
  estas dicas estarao disponiveis tambem atraves do servidor Web
  do Centro de Computacao da Unicamp (http://www.unicamp.br/CCUEC).
  
  970303.[doc|txt] --- O comando find
  970304.[doc|txt] --- Dicas uso gzip
       etc, etc, etc

Tabela de conversão de diretivas

  =====================================================================
  SRC                                                 HTML
  =====================================================================
   ~                                       <H1><FONT COLOR="#B22222">=
   --                                      <HR>
   ..                                      <PRE><FONT COLOR="#0000FF">
   ;;                                      </FONT></PRE>
   .                                       <P>
  =====================================================================
  --------------------
  = Dica Humorística :-)=
  
  = Fit the Nineteenth: Bastard Operator from Hell #14=
  [Bastard Operator From Hell]
  Updated: Tuesday 14 November 1995
  BOFH © 1990-1995 by Simon Travaglia and Datamation. All rights reserved.
  
  Don't ask how I got back, I just did. Suffice to say that work frowns upon
  management material that uses electrodes to gain client information.
  Especially when you do it to the boss's in-laws. That's HIS entertainment.
  
  So I'm back in the saddle. Unfortunately, that means there's a surplus of
  operators in the computer room. One slam of the tape safe door later, the
  problem is solved. The knocking dies down in a couple of hours, so I guess
  the safes really *are* airtight.
  
  To welcome myself back, I send a message out saying there's a shutdown in 10
  minutes. 5 minutes later I shut the system down. I love doing that. I see
  the hard-disk activity lights flicker as the "disk recovery" phase of
  startup run through, globally deleting journal files. Funny how we always
  start up with lots of free disk..
  
  I just get Wolfenstein started and the phone rings. What the hell, I almost
  missed it while I was away, so I answer it.
  
  "Computer Room" I say
  
  "THAT WASN'T TEN MINUTES!!!!" the voice at the other end screams
  
  "What wasn't 10 minutes?" I ask in a pleasant manner. I can see that things
  have deteriorated in my absence. Spare the rod and spoil the rm -r, that's
  what I always say.
  
  "THAT! You said it was going to be te... >pause "This is the Operator; who
  did you expect it to be?"
  
  "Darren? Is that Darren?"
  
  "Uh, No. Darren.. Darren is... unavailable... at the moment."
  
  "Oh. Do you know when he'll be back in the control room?"
  
  "Probably around the time of our next backup - the year 2007 or sometime
  thereabouts I should imagine"
  
  He's toying with asking me if he can recover their files or not. I let him
  dangle for a few moments.
  
  "Was that all?", I say, nice as pie
  
  "Well.... NO, it doesn't matter"
  
  "Of course it doesn't. Would you like me to check if your files are ok?" I
  prompt
  
  "Would you? I'm a bit new to this system and I'm not too sure what to do"
  
  "Sure. What was your username?"
  
  Everything inside him is screaming at him not to say it - People beside him
  are screaming at him not to say it.
  
  He says it.
  
  You just can't tell some people.
  
  "Ok. Well, it looks ok to me, all your files are in perfect condition!" I
  say
  
  "THEY ARE!! GREAT!!"
  
  The relief in his voice is overwhelming
  
  clicketyclickety "Yep. Both your x-defaults and AND your newsrc file are ok"
  
  "But.. But what about my site monitoring data?"
  
  "Sorry?"
  
  "There were about 10 files in my research subdirectory, data I'd collected
  over the past year."
  
  "Oh. Well, I can't see anything. Perhaps you backed them up somewhere?"
  
  "I put a copy in my girlfriend's account.."
  
  "What was her username?"
  
  "Uh.... pause Is he going to do it? Is he?
  
  He does.
  
  Like running down a snail with a steamroller...
  
  clickety clickety "Nope, nothing there either. OH! Hang on, there looks like
  some form of journal file in your account, it's quite large... I think maybe
  you should login there and try to recover with it..."
  
  I cat about 100 man files together and slop them in his girlfriends account
  under then name "rsrch.j"
  
  "How do I do that?"
  
  "Ok; can you login yet?"
  
  "Yeah, I think so..... Ok, I'm logged in"
  
  "Ok, You need to run the file thru the mailer to clear the eigth bit, other-
  wise the journal recovery will probably choke with an instruction error"
  
  DUMMY MODE ON "Oh... How do I do that?"
  
  "Well, you have to type in `mail root "Ok!"
  
  "HANG ON! You have to type it with your nose."
  
  "WH..? WHY?"
  
  I flip the excuse card till something appropriate pops up. "HARDWARE STRESS
  FRACTURES"
  
  "Well, it's got to do with hardware stress fractures. You probably type too
  hard with your fingers which upsets the internals of the keyboard. It's got
  to do with dry joints and electromagnetic inductance"
  
  DUMMY MODE IRREVOCABLY ON "Oh. Ok"
  
  "Now, you've got to type it in 20 times"
  
  "Sure, ok"
  
  He hangs up.
  
  I ring campus security
  
  "Hey, we've got another crazy in the lab. Apparently he's typing with his
  nose. He might be armed..."
  
  3 minutes later I hear the shots. I close his account, he won't be needing
  it any more..
  
  The phone rings. It's my Mum.
  
  "Hi Ma, what can I do for you"
  
  "Simon, I've got a problem at work, the floppy disk with all my personal
  stuff on it is failing I think"
  
  "Oh. Ok. Well, have you got any nail polish remover and some cotton wool
  buds?"
  
  "Yes"
  
  "Ok, take your disk out, and clean that brown stuff off the inside of the
  disk. That's what gets the heads dirty. You should just have a nice clean
  plastic disk when you've cleaned it completely"
  
  "Oh, Ok Simon, Thanks"
  
  "You're welcome. Oh; remember that time you wouldn't let me go over to
  Graeme's place to watch videos when I was 11?"
  
  "Yeah, why?"
  
  "Oh, No reason.."

Veja a relação completa dos artigos de Rubens Queiroz de Almeida

Formato PDF
Newsfeed RSS
Formato para impressão
PDF RSS Imprimir

Referências Adicionais

Referências adicionais sobre os assuntos abordados neste site podem ser encontradas em nossa Bibliografia.

Avalie esta dica

  • Currently 2.90/5
  • 1
  • 2
  • 3
  • 4
  • 5

Avaliação: 2.9 /5 (1347 votos)

Opinião dos Leitores

Seja o primeiro a comentar este artigo
*Nome:
Email:
Me notifique sobre novos comentários nessa página
Oculte meu email
*Texto:
 
  Para publicar seu comentário, digite o código contido na imagem acima
 


Powered by Scriptsmill Comments Script
Treinamentos, Consultorias e Soluçoes em TI. Baseados em softwares livres e padrões abertos para ambientes de missão crítica

Submarino.com.br

As Palavras Mais Comuns da Língua Inglesa (2ª edição)