The UNIX and Linux Forums  

Go Back   O UNIX e Linux Forum > Top Fóruns > Programação Shell Script e
.
google unix.com



Programação Shell Script e Post perguntas sobre ksh, CSH, SH, BASH, Perl, PHP, SED, Awk e outros scripts shell e shell scripts línguas aqui.

Mais UNIX e Linux Fórum Tópicos Você pode achar Helpfull
Fio Thread Starter Fórum Respostas Última postagem
Como ontem DATA osymad Programação Shell Script e 19 09-23-2009 03:39
Ajuda, Preciso de ir buscar a última data do mês anterior sirrtuan Programação Shell Script e 11 10-14-2008 06:59
no mês passado, data de término vanathi UNIX & avançada para usuários experientes 7 03-21-2008 04:17
Como mostrar ontem data wind_n_cloud Programação Shell Script e 1 02-16-2005 10:51
chegar ontem à data no formato aaaammdd hk_newbie UNIX para Dummies Perguntas & Respostas 2 12-14-2001 03:32

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
Linkback Thread Tools Pesquisar este Thread Avaliação: Thread Rating: 1 votes, 5.00 average. Display Modes
  #1 (permalink)  
Old 06-24-2008
skully skully is offline
Usuário
  
 

Join Date: Apr 2008
Lugares: 46
ontem à data mês / dia

Oi perito,

Eu quero recuperar ontem su log.
Como calcular e atribuir valor variável (06/23) em myVariable?


#! / bin / sh

\u003d ontem myVariable data no mês / dia

cat / var / adm / sulog | grep $ myVariable> file.txt



muito obrigado!
  #2 (permalink)  
Old 06-24-2008
ripat ripat is offline Forum Advisor  
Usuário
  
 

Join Date: Oct 2006
Localização: Bélgica
Lugares: 438
Se você tem GNU Data:

Código:
myVariable=$(date "+%m/%d" --date "now 1 day ago")
  #3 (permalink)  
Old 06-24-2008
skully skully is offline
Usuário
  
 

Join Date: Apr 2008
Lugares: 46
Eu não acho que tenho isso. Como verificar?

Eu posso extrair a data, vamos dizer 24. Mas como fazer -1

Como corrigir código abaixo da sintaxe em / bin / sh

myDate \u003d `date-u +% d`
myMonth \u003d `date-u +% m`
myYear \u003d `date-u +% Y`
myAnotherMonth \u003d `date-u +% b`

if [$ myDate \u003d\u003d 1 & & ($ myAnotherMonth \u003d\u003d Set | | $ myAnotherMonth \u003d\u003d abr | | $ myAnotherMonth \u003d\u003d junho | | $ myAnotherMonth \u003d\u003d novembro | | $ myAnotherMonth \u003d\u003d fevereiro)]
então
ontem \u003d 30

elseif [$ myDate \u003d\u003d 1 & & $ myAnotherMonth \u003d\u003d fev.]

ontem \u003d 28 # Eu não se preocupe em terminar com 29 meses

diferente

ontem \u003d $ myDate - 1

fi

cat / var / adm / sulog | grep "$ myMonth \ / $ ontem" | grep-v grep> $ myYear $ myMonth $ yesterday_sulog.txt

Última edição por skully; em 06/24/2008 04:28..
  #4 (permalink)  
Old 06-24-2008
ripat ripat is offline Forum Advisor  
Usuário
  
 

Join Date: Oct 2006
Localização: Bélgica
Lugares: 438
Para conhecer a sua versão do data, Basta executar o meu comando e ver o que sua caixa resposta.

Uma solução alternativa, mas novamente com GNU data:
Código:
#!/bin/bash 

STAMP_TODAY=$(date --utc --date "$1" +%s)
STAMP_YESTERDAY=$((STAMP_TODAY-86400))
DTE_YESTERDAY=$(date --utc --date "1970-01-01 $STAMP_YESTERDAY sec" "+%m/%d")

echo $DTE_YESTERDAY
  #5 (permalink)  
Old 06-24-2008
ripat ripat is offline Forum Advisor  
Usuário
  
 

Join Date: Oct 2006
Localização: Bélgica
Lugares: 438
Se você não tem GNU data, Experimente isto em bash:

Código:
TODAY_D=$(date -u +%d)
TODAY_M=$(date -u +%m)
LAST_DAY_OF_M=(-- 31 28 31 30 31 30 31 31 30 31 30 31)
if [[ $TODAY_D == "01" ]];then
        if [[ $TODAY_M == "01" ]];then
                PREVIOUS_M="12"
        else
                PREVIOUS_M=$((TODAY_M-1))
        fi
        printf "%02d/%s" $PREVIOUS_M ${LAST_DAY_OF_M[$PREVIOUS_M]}
else
        printf "%s/%s" $TODAY_M $((TODAY_D-1))
fi
exit 0

Última edição por ripat; em 06/24/2008 06:39.. Motivo: Esqueceu a cuidar de janeiro!
  #6 (permalink)  
Old 06-24-2008
skully skully is offline
Usuário
  
 

Join Date: Apr 2008
Lugares: 46
Funciona. Excelente
Eu apenas não têm uma idéia de como escrever algo parecido com você.
Muito obrigado!

Última edição por skully; em 06/24/2008 06:55.. Motivo: se esqueceu de incluir Excelente
Closed Thread

Marcadores

Thread Tools Pesquisar este Thread
Pesquisar este Thread:

Pesquisa Avançada
Display Modes Esta taxa Thread
Esta taxa Thread:

Destacamento Regimento
Você não pode postar novas threads
Você não pode postar respostas
Você não pode postar anexos
Você não pode editar suas postagens

BB code é Ligado
Smilies são Ligado
[IMG] código é Ligado
Código HTML é Desligado
Trackbacks são Ligado
Pingbacks são Ligado
Refbacks são Ligado




Todos os horários são GMT -4. A hora é agora 08:30.


Powered by: vBulletinCopyright © 2000 - 2006, Jelsoft Enterprises Limited. Língua Traduções Powered by .
vBCredits v1.4 Copyright © 2007 - 2008, PixelFX Studios
O UNIX e Linux Fóruns Content Copyright © 1993-2009. Todos os Direitos Reserved.Ad Gestão por RedTyger

Content Relevant URLs por vBSEO 3.2.0