Bonjour à tous,
Je m'amuse à faire un petit script, mais je rencontre un petit problème. Voila ce que je veux :
- créer un script "prog" qui lorsqu'il est lancé avec un paramètre le nom d'un utilisateur celui renvoie ceci :
./prog nomlogin
uid : 1890
gid : 568
fullname : Nom Prénom
homedir : /home/nomlogin
shell : /bin/tcsh
voila ce que j'ai fait :
#!/bin/tcsh
grep $1 /etc/passwd
endif
il m'affiche seulement la ligne correspond au nom de login indiqué au prélable en paramètre du fichier /etc/passwd
Moi je veux qu'il affiche en colonne, vous savez avec la commande awk'{print $1 "" $3}', pour afficher les colonnes 1 et 3 du fichier, mais bon voila quoi il ne veut rien savoir même si je met des pipes (|).
Je voudrais après l'exécution de la commande :
./prog jean
ou
./prog "nom d'un utilisateur (ex: root, marcel, pascal ...)"
celle ci m'affiche :
uid : 1890
gid : 568
fullname : dupond jean
homedir : /home/jean
shell : /bin/tcsh
car dans le fichier :
/etc/passwod:
on a :
jean:x:1890:568:dupont jean:/home/jean:/bin/tcsh
marcel:x:1111:564:dupuit marcel:/home/marcel:/bin/bash
autres utilisateurs ...
....
....
si j'avais tapé la commande :
./prog marcel
Alors elle m'aurais affiché :
uid : 1111
gid : 564
fullname : dupuit marcel
homedir : /home/marcel
shell : /bin/bash
Voila ce que j'ai fais :
VERSIONS QUI MARCHE avec uid gid
#!/bin/tcsh
if ($1 == "-help") then
echo "Usage: infouser [-help] username"
echo "Display user information (uid,gid,full name, homedir and common shell)"
else
echo uid:$uid
set uid = "grep $1 /etc/passwd | awk -F : '{print $3}'"
echo gid:$gid
set gid = "grep $1 /etc/passwd | awk -F : '{print $4}'"
endif
VERSIONS QUI MARCHE PLUS :
#!/bin/tcsh
if ($1 == "-help") then
echo "Usage: infouser [-help] username"
echo "Display user information (uid,gid,full name, homedir and common shell)"
else
echo uid:$uid
set uid = "grep $1 /etc/passwd | awk -F : '{print $3}'"
echo gid:$gid
set gid = "grep $1 /etc/passwd | awk -F : '{print $4}'"
echo fullname:$fullname
set fullname = "grep $1 /etc/passwd | awk -F : '{print $5}'"
echo homedir:$homedir
set homedir = "grep $1 /etc/passwd | awk -F : '{print $6}'"
echo shell:$shell
set shell = "grep $1 /etc/passwd | awk -F : '{print $7}'"
endif
Pouvez vous m'aidez MERCI
Configuration: Windows XP pro sp3
Firefox 3.5.4