proxy
Avec nagios, tu auras ce genre d'infos
pmarion
Ce n'est pas linux qui peut te permettre d'extraire des parties de chaines mais les commandes shell incluses dans Linux mais qui existent aussi sous window$ .
Si l'on essaie :
echo "1217333533 12:12:13 2008/07/29" | cut -d' ' -f1
on obtient
1217333533
Si tu as un fichier :
while read ligne
do
echo $ligne | cut -d' ' -f1
done <nom_fichier
affichera la première partie de chaque ligne
rémidoubi
la première marche mais la seconde non 🙁.
il manque quelque chose ????!!!!! :s:s:s:s
pmarion
La deuxième n'est qu'une boucle de lecture dans un fichier .
Essaie une boucle plus simple:
while read ligne
do
echo $ligne
done <nom_du_fichier_dont_tu_veux_lire_le_contenu
Avec n'importe quel nom de fichier la boucle doit t'afficher le contenu du fichier.
Si ça ne marche pas, peux-tu poster le ou les messages d'erreur.
rémidoubi
je recois ca :
[root@Serveur ~]# while read ligne do echo $ligne done <ff
>
et ça reste comme ça.
fichier ff
[root@Serveur ~]# cat ff
1217323495 09:24:55 2008/07/29
1217333533 12:12:13 2008/07/29
1217333539 12:12:19 2008/07/29
pmarion
Je pense que tu ne respecte pas les règles d'une boucle dans un SHELL.
1 ) soit tu fais des retours à la ligne comme dans les exemples précédents
2 ) soit tu utilises un ';' (point-virgule) comme séparateur
while read ligne
do
echo $ligne
done <nom_du_fichier_dont_tu_veux_lire_le_contenu
ou
while read ligne; do echo $ligne; done <nom_fichier_dont_tu_veux_lire_le_contenu
La seconde méthode est beaucoup moins lisible et ce n'est pas qu'une question de gout. Il faut acquérir de bonnes habitudes dès le départ et Il faut penser à la maintenance, aux boucles imbriquées, ...
rémidoubi
En fait c tout bête, il faut mettre des ';' 😃
while read ligne;
do
echo $ligne |cut -d' ' -f1;
done <ff >f
Un peu tard
- fichier f
1217323495
1217333533
1217333539
mais pour avoir que la premiere ligne on fait comment ??
merci Bcp
pmarion
Si tu respectes les retours à la ligne tu n'es pas obligé de mettre des ';' mais si tu en mets cela fonctionne mais alourdit la saisie et la lisibilité.
Pour avoir la première ligne d'un fichier il suffit de faire
head -n1 nom_fichier
Pour avoir les deux premières :
head -n2 nom_fichier
Pour avoir les deux dernières
tail -n2 nom_fichier
et ainsi de suite ! !
rémidoubi
C'est bon
tail -1 <ff |while read ligne; do tail -1 ff |cut -d ' ' -f1; done
rémidoubi
Thank u thank u!!
Merci les amis pour votre aide maintenant je crois avoir tout bagage nécessaire pour commencer mon pti script,
je le posterai aprés, faut juste qu'il contienne pas d'erreurs,
mais on y arrivera,
merci beaucoup jeunes gens
rémidoubi
Encore moi les Amis,
voici mon script
/etc/init.d/mon_script
#!/bin/bash
#
# description: Logs start and stop
#
RETVAL=0
case $1 in
start)
echo "Demarrage = $(date +'%s'' ''%H:%M:%S'' ''%Y/%m/%d')" >>root/Tracing_F
;;
stop)
echo "Arret = $(date +'%s'' ''%H:%M:%S'' ''%Y/%m/%d')" >>root/Tracing_F
;;
*)
printf "Service Start | Stop \n"
exit 1;
esac
exit 0;
Aprés :
chmod +x mon_script
chkconfig --add mon_script
chkconfig --level 12345 mon_script on
est se qu'il faut ajouter quelque chose pour que le service démarre avec la démarrage de la machine et s'arrête avec l'arrêt de la machine ??? car un fois demarré (manuellement ) il ne s'arrete pas :s
y a t'il une étape que j'ai oublié ??
pmarion
A mon avis tu n'as pas mis les commentaires nécessaires à chkconfig en début de script. Mais je suis surpris que chkconfig ne hurle pas sur cette lacune.
En début de script (après le #!xxxxxx) il doit y avoir une ligne du genre :
# chkconfig: xx yy zz
Pour plus de précision sur les xx, yy et zz voir 'man chkconfig'
Pour voir comment chkconfig a activé un script.
chkconfig --list mon_script
rémidoubi
oui c'est ce que je recois mnt
le service mon_script ne prend pas en charge chkconfig
je crois que c'est du à ce manque,je vais tout de suite régler la chose
merci d'avoir répondu si rapidement
rémidoubi
La j'ai vraiment besoin de vous les gars,mon service démarre automatiquement au démarrage mais ne quand la machine s'arrête, le service lui ne s'arrête pas ....
Et après un nouveau redémarrage: je tape service mon_script stop,... il s'arrete :s Comprends rien
Voici le fichier :
============================================
#!/bin/bash
#
# chkconfig: 345 20 20
# description: service start and stop
#
case $1 in
start)
echo "Demarrage = $(date +'%s'' ''%H:%M:%S'' ''%Y/%m/%d')" >>root/Tracing_F
;;
stop)
echo "Arret = $(date +'%s'' ''%H:%M:%S'' ''%Y/%m/%d')" >>root/Tracing_F
;;
*)
printf "Service start | stop \n"
exit 1;
esac
exit 0;
=========================================
y a t il quelque chose d'incorrect ??
proxy
As tu fait chkconfig --add ton service ?
As tu un lien K20tonservice dans /etc/rc6.d ?
nouvo09
Tu peux poster le résultat de
ls -l /etc/rc.d/rc6.d
je pressens un problème d'ordre
rémidoubi
le chkconfig --add oui car je le vois grace a chkconfig --list | grep mon
[root@Serveur ~]# chkconfig --list | grep mon
avahi-daemon 0:arrêt 1:arrêt 2:arrêt 3:marche 4:marche 5:marche 6:arrêt
haldaemon 0:arrêt 1:arrêt 2:arrêt 3:marche 4:marche 5:marche 6:arrêt
mdmonitor 0:arrêt 1:arrêt 2:marche 3:marche 4:marche 5:marche 6:arrêt
mon_script 0:arrêt 1:arrêt 2:arrêt 3:marche 4:marche 5:marche 6:arrêt <=
le lien existe dans /etc/rc.d/rc6.d/K20mon_script donc il porte le même numéro qui figure dans le script.
le K montre que le service doit être arrêté dans un niveau d'arrêt 0,6.pourquoi c'est pas le cas alors ??
rémidoubi
[root@Serveur ~]# ls -l /etc/rc.d/rc6.d
total 312
lrwxrwxrwx 1 root root 16 jui 10 14:03 K01smartd -> ../init.d/smartd
lrwxrwxrwx 1 root root 22 jui 10 14:02 K02avahi-daemon -> ../init.d/avahi-daemon
lrwxrwxrwx 1 root root 24 jui 10 14:02 K02avahi-dnsconfd -> ../init.d/avahi-dnsconfd
lrwxrwxrwx 1 root root 16 jui 10 14:02 K02dhcdbd -> ../init.d/dhcdbd
lrwxrwxrwx 1 root root 19 jui 10 14:02 K02haldaemon -> ../init.d/haldaemon
lrwxrwxrwx 1 root root 24 jui 10 14:02 K02NetworkManager -> ../init.d/NetworkManager
lrwxrwxrwx 1 root root 34 jui 10 14:02 K02NetworkManagerDispatcher -> ../init.d/NetworkManagerDispatcher
lrwxrwxrwx 1 root root 15 jui 10 14:02 K03rhnsd -> ../init.d/rhnsd
lrwxrwxrwx 1 root root 22 jui 10 14:03 K03yum-updatesd -> ../init.d/yum-updatesd
lrwxrwxrwx 1 root root 17 jui 10 14:00 K05anacron -> ../init.d/anacron
lrwxrwxrwx 1 root root 13 jui 10 14:02 K05atd -> ../init.d/atd
lrwxrwxrwx 1 root root 16 jui 10 14:03 K05conman -> ../init.d/conman
lrwxrwxrwx 1 root root 19 jui 10 14:02 K05saslauthd -> ../init.d/saslauthd
lrwxrwxrwx 1 root root 14 jui 10 14:02 K10cups -> ../init.d/cups
lrwxrwxrwx 1 root root 19 jui 10 14:06 K10dc_server -> ../init.d/dc_server
lrwxrwxrwx 1 root root 15 jui 10 14:03 K10hplip -> ../init.d/hplip
lrwxrwxrwx 1 root root 16 jui 10 14:03 K10psacct -> ../init.d/psacct
lrwxrwxrwx 1 root root 22 jui 18 10:55 K10sqlsyslog-ng -> ../init.d/sqlsyslog-ng
lrwxrwxrwx 1 root root 18 jui 25 12:45 K10webmin -> /etc/init.d/webmin
lrwxrwxrwx 1 root root 13 jui 10 14:08 K10xfs -> ../init.d/xfs
lrwxrwxrwx 1 root root 19 jui 10 14:06 K12dc_client -> ../init.d/dc_client
lrwxrwxrwx 1 root root 13 jui 10 14:00 K15gpm -> ../init.d/gpm
lrwxrwxrwx 1 root root 15 jui 10 14:06 K15httpd -> ../init.d/httpd
lrwxrwxrwx 1 root root 20 jui 29 15:55 K20mon_script -> ../init.d/mon_script
lrwxrwxrwx 1 root root 13 jui 10 14:03 K20nfs -> ../init.d/nfs
lrwxrwxrwx 1 root root 14 jui 10 14:03 K24irda -> ../init.d/irda
lrwxrwxrwx 1 root root 15 jui 10 14:07 K25squid -> ../init.d/squid
lrwxrwxrwx 1 root root 14 jui 10 14:03 K25sshd -> ../init.d/sshd
lrwxrwxrwx 1 root root 18 jui 10 14:02 K30sendmail -> ../init.d/sendmail
lrwxrwxrwx 1 root root 13 jui 10 14:06 K35smb -> ../init.d/smb
lrwxrwxrwx 1 root root 19 jui 10 14:10 K35vncserver -> ../init.d/vncserver
lrwxrwxrwx 1 root root 17 jui 10 14:02 K35winbind -> ../init.d/winbind
lrwxrwxrwx 1 root root 14 jui 10 14:10 K36lisa -> ../init.d/lisa
lrwxrwxrwx 1 root root 16 jui 10 14:06 K36mysqld -> ../init.d/mysqld
lrwxrwxrwx 1 root root 13 jui 10 14:07 K50tux -> ../init.d/tux
lrwxrwxrwx 1 root root 15 jui 10 14:03 K56acpid -> ../init.d/acpid
lrwxrwxrwx 1 root root 15 jui 10 14:02 K60crond -> ../init.d/crond
lrwxrwxrwx 1 root root 16 jui 24 12:00 K60snortd -> ../init.d/snortd
lrwxrwxrwx 1 root root 19 jui 10 14:03 K68rpcidmapd -> ../init.d/rpcidmapd
lrwxrwxrwx 1 root root 17 jui 10 14:03 K69rpcgssd -> ../init.d/rpcgssd
lrwxrwxrwx 1 root root 20 jui 10 14:03 K69rpcsvcgssd -> ../init.d/rpcsvcgssd
lrwxrwxrwx 1 root root 16 jui 10 14:03 K72autofs -> ../init.d/autofs
lrwxrwxrwx 1 root root 16 jui 10 14:02 K73ypbind -> ../init.d/ypbind
lrwxrwxrwx 1 root root 14 jui 10 14:03 K74apmd -> ../init.d/apmd
lrwxrwxrwx 1 root root 14 jui 10 14:03 K74ipmi -> ../init.d/ipmi
lrwxrwxrwx 1 root root 20 jui 10 14:06 K74lm_sensors -> ../init.d/lm_sensors
lrwxrwxrwx 1 root root 14 jui 10 14:02 K74nscd -> ../init.d/nscd
lrwxrwxrwx 1 root root 14 jui 10 14:03 K74ntpd -> ../init.d/ntpd
lrwxrwxrwx 1 root root 15 jui 10 14:02 K75netfs -> ../init.d/netfs
lrwxrwxrwx 1 root root 15 jui 10 14:06 K80kdump -> ../init.d/kdump
lrwxrwxrwx 1 root root 15 jui 23 16:07 K82snort -> ../init.d/snort
lrwxrwxrwx 1 root root 19 jui 10 14:03 K85mdmonitor -> ../init.d/mdmonitor
lrwxrwxrwx 1 root root 15 jui 10 14:03 K85mdmpd -> ../init.d/mdmpd
lrwxrwxrwx 1 root root 20 jui 10 14:01 K85messagebus -> ../init.d/messagebus
lrwxrwxrwx 1 root root 17 jui 10 14:03 K86nfslock -> ../init.d/nfslock
lrwxrwxrwx 1 root root 20 jui 10 14:03 K87irqbalance -> ../init.d/irqbalance
lrwxrwxrwx 1 root root 18 jui 10 14:02 K87mcstrans -> ../init.d/mcstrans
lrwxrwxrwx 1 root root 17 jui 10 14:02 K87portmap -> ../init.d/portmap
lrwxrwxrwx 1 root root 24 jui 10 14:09 K87setroubleshoot -> ../init.d/setroubleshoot
lrwxrwxrwx 1 root root 16 jui 10 14:02 K88auditd -> ../init.d/auditd
lrwxrwxrwx 1 root root 15 jui 10 14:04 K88pcscd -> ../init.d/pcscd
lrwxrwxrwx 1 root root 16 jui 10 14:02 K88syslog -> ../init.d/syslog
lrwxrwxrwx 1 root root 19 jui 11 10:51 K88syslog-ng -> ../init.d/syslog-ng
lrwxrwxrwx 1 root root 24 jui 10 14:02 K88wpa_supplicant -> ../init.d/wpa_supplicant
lrwxrwxrwx 1 root root 14 jui 10 14:03 K89dund -> ../init.d/dund
lrwxrwxrwx 1 root root 14 jui 10 14:03 K89hidd -> ../init.d/hidd
lrwxrwxrwx 1 root root 18 jui 10 14:01 K89netplugd -> ../init.d/netplugd
lrwxrwxrwx 1 root root 14 jui 10 14:03 K89pand -> ../init.d/pand
lrwxrwxrwx 1 root root 15 jui 10 14:00 K89rdisc -> ../init.d/rdisc
lrwxrwxrwx 1 root root 19 jui 10 14:03 K90bluetooth -> ../init.d/bluetooth
lrwxrwxrwx 1 root root 17 jui 10 14:02 K90network -> ../init.d/network
lrwxrwxrwx 1 root root 21 jui 10 14:02 K90restorecond -> ../init.d/restorecond
lrwxrwxrwx 1 root root 14 jui 10 14:11 K91capi -> ../init.d/capi
lrwxrwxrwx 1 root root 14 jui 10 14:11 K91isdn -> ../init.d/isdn
lrwxrwxrwx 1 root root 19 jui 10 14:00 K92ip6tables -> ../init.d/ip6tables
lrwxrwxrwx 1 root root 18 jui 10 14:00 K92iptables -> ../init.d/iptables
lrwxrwxrwx 1 root root 19 jui 10 14:03 K95firstboot -> ../init.d/firstboot
lrwxrwxrwx 1 root root 15 jui 10 14:02 K95kudzu -> ../init.d/kudzu
lrwxrwxrwx 1 root root 18 jui 10 14:00 K99cpuspeed -> ../init.d/cpuspeed
lrwxrwxrwx 1 root root 23 jui 10 14:03 K99microcode_ctl -> ../init.d/microcode_ctl
lrwxrwxrwx 1 root root 25 jui 10 14:03 K99readahead_early -> ../init.d/readahead_early
lrwxrwxrwx 1 root root 25 jui 10 14:03 K99readahead_later -> ../init.d/readahead_later
lrwxrwxrwx 1 root root 17 jui 10 14:02 S00killall -> ../init.d/killall
lrwxrwxrwx 1 root root 14 jui 10 14:02 S01reboot -> ../init.d/halt
voila
rémidoubi
Aucune Idée ?
nouvo09
hum, essaie de lui donner le numéro d'ordre 99 en level 6 ?