Here is a very easy way to compare dates under the BASH shell under linux.
Use the date function.
Here is a simple example.
Let's say i want to know if this happened more than 30 days ago.
I have two dates
Today: 2009/07/15
Then: 2009/03/21
It would be much trouble trying to compare the year then the month and finally the day and
finding if 30 days have passed or not.
Here comes the date function.
Simply do this
date -d 2009/03/21 +%s
this will give you your date in second since epoch
(lookup wikipedia if you dont know what epoch is)
so then do
date +%s
to get today's date in second since epoch.
All you have to do then is find the amount of second you want to have between the dates.
In our case 30 days is: 30*24h*60m*60s = 2 592 000s
sooo i think you can guess the rest.
Have fun :D
== French version ==
Voici une maniere tres simple de comparer deux dates dans le BASH shell de Linux.
Utiliser la fonction date.
Voici un exemple.
Disont que vous voulez savoir si plus de 30 jours se sont ecouler depuis une certaine date.
Aujourd'hui: 2009/07/15
A ce moment: 2009/03/21
Il serait complique de comparer les annees ensuite les mois et finalement les jours pour
determiner si plus de 30 jours se sont ecouler.
Voila que viens en jeux la fonction date.
Faite simplement ceci:
date -d 2009/03/21 +%s
Ceci va vous donner la date en seconde depuis epoch.
(allez voir wikipedia si vous ne savez pas ce qu'est l'epoch)
donc faite ensuite
date +%s
pour avoir la date d'aujourd'hui en seconde depuis l'epoch
Il ne vous reste plus qua savoir combien de seconde devrait avoir passer entre vos deux dates.
Dans notre cas 30 jours: 30*24h*60m*60s = 2 592 000s
Bon... je crois que vous pouvez devinez le reste.
Amusez vous bien! Et ne courez pas avec des ciseaux.
mercredi 15 juillet 2009
vendredi 20 juin 2008
Quelques trucs pour vi // Some tips for using vi
Voici quelques petit truc a utiliser sous vi en mode commande:
/[MODELE] Recherche [MODELE] dans le fichier.
n Prochaine occurrence de la dernière recherche.
[x]yy Met [x] caractere dans le tampon
p Insert le tampon apres le curseur
P Insert le tampon avant le curseur
[x]b Recule de [x] mots
[x]e Avance a la fin du [x]eme mot
=== English ===
/[PATERN] Search [PATERN] in the current file
n Redo last search (go to next occurence)
[x]yy Put [x] line in buffer
p Insert buffer after the cursor
P Insert buffer before the cursor
[x]b Go back [x] words
[x]e Go to the end on the [x]th word.
/[MODELE] Recherche [MODELE] dans le fichier.
n Prochaine occurrence de la dernière recherche.
[x]yy Met [x] caractere dans le tampon
p Insert le tampon apres le curseur
P Insert le tampon avant le curseur
[x]b Recule de [x] mots
[x]e Avance a la fin du [x]eme mot
=== English ===
/[PATERN] Search [PATERN] in the current file
n Redo last search (go to next occurence)
[x]yy Put [x] line in buffer
p Insert buffer after the cursor
P Insert buffer before the cursor
[x]b Go back [x] words
[x]e Go to the end on the [x]th word.
mardi 27 mai 2008
Slow SSH Connection / Lenteur SSH
J'ai enfin trouvé mon problème. Lors d'une connection SSH, le serveur prenais un bon 8 sec. avant de demandé le password de l'usager. Partout ou je regardais les suggestions était vérifier la config DNS. Oui c'était bien ca mais c'était causé par autre chose. Quand je roulais la commande route, je recevais un message a propos d'une commande non valide dans host.conf
mdns off
Le problème était dans la version de glibc, un bug, qui brisait le multicast DNS. Une fois glibc mis a jour a la version 1.3.3-98.31 tout est redevenu normal. Donc si vous avez ce problème et que vous savez vos DNS correcte, vérifier votre glibc.
== English ==
I just found my problem. I had this nagging problem where SSH would hang for like 8 seconds before asking the password for a connection. Everywhere I looked everyone was talking about it being a DNS problem. Yes it was, but it was actually caused by something else. When I ran the route command it was giving off an error about a bad command in host.conf.
mdns off
The problem was actually a bug in glibc
For it to get fixed I had to upgrade glibc to version 1.3.3-98.31
So if you get this error on SuSe and you know your DNS are working fine. Check your glibc
mdns off
Le problème était dans la version de glibc, un bug, qui brisait le multicast DNS. Une fois glibc mis a jour a la version 1.3.3-98.31 tout est redevenu normal. Donc si vous avez ce problème et que vous savez vos DNS correcte, vérifier votre glibc.
== English ==
I just found my problem. I had this nagging problem where SSH would hang for like 8 seconds before asking the password for a connection. Everywhere I looked everyone was talking about it being a DNS problem. Yes it was, but it was actually caused by something else. When I ran the route command it was giving off an error about a bad command in host.conf.
mdns off
The problem was actually a bug in glibc
For it to get fixed I had to upgrade glibc to version 1.3.3-98.31
So if you get this error on SuSe and you know your DNS are working fine. Check your glibc
Inscription à :
Articles (Atom)