![]() |
| Le forum de référence en programmation et développement. Articles, cours et tutoriels du débutant au chef de projet et DBA confirmé. | |||||||
|
|||||||
| Shell Vos questions sur l'utilisation des commandes shell |
![]() |
|
|
Outils de la discussion |
|
|
#1 (permalink) |
|
Nouveau membre du Club
![]() Date d'inscription: janvier 2007
Messages: 54
|
Bonjour j'ai téléchargé un script .bat fonctionnat sur windows et j'aimerais le modifié pour qu'il puisse fonctionné avec Linux
je suis un peu confuse dans mon script au niveau des tests(if). Comment est ce que je peux les modifiés pour qu'ils puissent etre utilisables sous linux? Code :
if "%OP_CERT_COUNTRY%" == "" goto edit_script if "%OP_CERT_STATE%" == "" goto edit_script if "%OP_CERT_LOCALITY%" == "" goto edit_script if "%OP_CERT_ORG%" == "" goto edit_script if "%OP_CERT_CA_DAYS%" == "" goto edit_script if "%OP_CERT_CERT_DAYS%" == "" goto edit_script shift if "%0" == "" goto help if "%0" == "help" goto help if "%0" == "dsaparam" goto dsaparam if "%0" == "gencakey" goto gencakey if "%0" == "genmanager" goto genmanager Aussi je ne comprends pas ce bout de code Code :
goto end :help echo usage: op_cert command echo. echo commands: echo dsaparam: generates DSA parameters echo gencakey: generates the certificate authority's private and public keys echo genmanager: generates the certificates used by the capture manager echo help: displays this text echo. echo Certificate generation requires generating the DSA parameters first. echo If the DSA parameter file (dsaparam.pem) already exists, there is no echo need to generate a new DSA parameter file. goto end :dsaparam openssl dsaparam -outform PEM -out dsaparam.pem 1024 goto end :gencakey ECHO. ECHO =========================================== ECHO Generating the private and public keys for the certificate authority. This operation only needs to be done once. ECHO Enter the same passphrase three times.This passphrase should be kept secure. ECHO ============================================== ECHO. echo [ req ] > openssl.cnf echo default_bits = 1024 >> openssl.cnf echo default_keyfile = privkey.pem >> openssl.cnf echo distinguished_name = req_distinguished_name >> openssl.cnf echo prompt = no >> openssl.cnf echo [ req_distinguished_name ] >> openssl.cnf echo C = %OP_CERT_COUNTRY% >> openssl.cnf echo ST = %OP_CERT_STATE% >> openssl.cnf echo L :end set OP_CERT_COUNTRY= set OP_CERT_STATE= set OP_CERT_LOCALITY= set OP_CERT_ORG= Merci d'avance Dernière modification par ggnore ; 27/08/2008 à 16h15 |
|
|
|
|
|
#2 (permalink) |
|
Membre éprouvé
![]() Date d'inscription: février 2007
Messages: 451
|
tu devrais regarder un tuto script shell parce que y a presque tout à refaire.
En shell tu récupères la valeur d'une variable avec $NOM_VARIABLE et pas avec %NOM_VAR%. Pour tester l'égalité de deux chaines c'est Code :
if [ $CHAINE1 = $CHAINE2 ]; then [...] fi Et vire moi ces goto. Fais des if, else if, [...], else
__________________
La science est ce que nous comprenons suffisamment bien pour l'expliquer à un ordinateur. L'art, c'est tout ce que nous faisons d'autre. Donald E. Knuth |
|
|
|
|
|
#3 (permalink) |
|
Membre Expert
![]() Date d'inscription: juillet 2006
Localisation: toulouse
Messages: 1 474
|
goto est interdit en programmation quelque soit le langage (à part en basic 8bits mais qui programme encore sur mo5 ?)
il faut faire des fonctions (ici en syntaxe shell) Code :
toto()
{
....
}
Code :
... toto ... |
|
|
|
|
|
#4 (permalink) | |||
|
Membre éclairé
![]() Date d'inscription: avril 2008
Localisation: Chambéry - Nancy
Âge: 21
Messages: 342
|
Citation:
![]() Citation:
__________________
Citation:
|
|||
|
|
|
|
|
#5 (permalink) |
|
Nouveau membre du Club
![]() Date d'inscription: janvier 2007
Messages: 54
|
oui c ca .. j'utilise openssl ... mais pour que ca puisse fonctionner avec le logiciel de simulation OPNET, je dois utiliser ce script ... mais il faut que je le modifie pour qu'il puisse passser avec linux ... et je n'y comprends vraiment rien car je n'ai jamais écris de script....
|
|
|
|
|
|
#6 (permalink) |
![]() Date d'inscription: juillet 2004
Localisation: Made in normandy
Âge: 29
Messages: 2 120
|
ça vaudrait le coût de tout réécrire. Les goto c'est très laid. Et très incompréhensible, comme tu en fais l'expérience actuellement.
Il faut savoir que la génération de certificats ssl auto certifiés, ne sont, par défaut, plus acceptés par firefox. Tu peux te documenter ici : http://www.keliglia.com/categorie/divers/1993/
__________________
Donne un poisson à un homme et tu le nourris pour un jour, Apprends-lui à pêcher et tu le nourris pour toujours. |
|
|
|
|
|
#7 (permalink) |
|
Nouveau membre du Club
![]() Date d'inscription: janvier 2007
Messages: 54
|
Bonjour,
J'ai toujours un problème avec mon script. Voici mon script : Code :
#!/bin/bash
# The information assigned to the environment variables below will be included
# in the certificates generated by this script.
#
# The following environment variables should be assigned to valid values. This
# script will not work with quotes in any of the following environment
# variables.
############################################################################
# EDIT THE FOLLOWING LINES, WHICH CURRENTLY HAVE SAMPLE DEFAULTS.
# CHANGE THE VALUES AFTER THE '=' SYMBOL TO REFLECT YOUR SPECIFIC ENVIRONMENT.
#
#############################################################################
# Specify your country Specify your country [two letters only]
set OP_CERT_COUNTRY=CA
# Specify your state or province
set OP_CERT_STATE=QC
# Specify your city
set OP_CERT_LOCALITY=Trois-Rivieres
# Specify your company's name
set OP_CERT_ORG=UQTR
# This is the expiration for the CA and public certificates created by the CA;
# often will be 10 years or more.
set OP_CERT_CA_DAYS=3650
# This is the expiration for the Capture Manager certificates; might be 1 day,
# 30 days, etc., depending on policy.
set OP_CERT_CERT_DAYS=200
##########################################################
#
# END OF LINES THAT YOU SHOULD EDIT.
#
###########################################################
#Test de l'alimentation des variables
if [[ " $OP_CERT_COUNTRY" ]] || [[ " $OP_CERT_STATE" ]] || [[ " $OP_CERT_LOCALITY " ]] || [[ " $OP_CERT_ORG" ]] || [[ " $OP_CERT_CA_DAYS" ]] || [[ " $OP_CERT_CERT_DAYS" ]] ; then
echo "op_cert: please edit the environment variables at the start of this script file"
exit
#Test de l'option du script
function help()
{
echo "usage: op_cert command"
echo "commands:"
echo "dsaparam: generates DSA parameters"
echo "gencakey: generates the certificate authority's private and public keys"
echo "genmanager: generates the certificates used by the capture manager"
echo "help: displays this text"
echo "Certificate generation requires generating the DSA parameters first"
echo "If the DSA parameter file (dsaparam.pem) already exists, there is no"
echo "need to generate a new DSA parameter file"
exit 1
}
function dsaparam()
{
/usr/local/ssl/bin/openssl dsaparam -outform PEM -out dsaparam.pem 1024
}
function gencakey()
{
echo "===================================================================================================================="
echo "Generating the private and public keys for the certificate authority. This operation only needs to be done once."
echo "Enter the same passphrase three times. This passphrase should be kept secure."
echo "===================================================================================================================="
echo "[ req ]" > openssl.cnf
echo "default_bits = 1024" >> openssl.cnf
echo "default_keyfile = privkey.pem" >> openssl.cnf
echo "distinguished_name = req_distinguished_name" >> openssl.cnf
echo "prompt = no" >> openssl.cnf
echo "[ req_distinguished_name ]" >> openssl.cnf
echo "C = $OP_CERT_COUNTRY" >> openssl.cnf
echo "ST = $OP_CERT_STATE" >> openssl.cnf
echo "L = $OP_CERT_LOCALITY" >> openssl.cnf
echo "O = $OP_CERT_ORG" >> openssl.cnf
echo "CN = CA" >> openssl.cnf
/usr/local/ssl/bin/openssl req -config openssl.cnf -newkey dsa:dsaparam.pem -sha1 -keyout cakey.pem -outform PEM -out careq.pem
/usr/local/ssl/bin/openssl x509 -req -inform PEM -in careq.pem -sha1 -signkey cakey.pem -outform PEM -out ca.pem -days $OP_CERT_CA_DAYS
cp ca.pem cakey.pem casign.pem
rm -f cakey.pem careq.pem
echo "========================================================"
echo "This certificate will expire in $OP_CERT_CA_DAYS days."
echo "========================================================"
function genmanager()
{
echo "==================================================================================================="
echo "Generating the capture manager certificate."
echo "Enter the user's passphrase twice, followed by the certificate authority's passphrase."
echo "The user's passphrase is what he will type into ITGuru when opening the capture manager."
echo "==================================================================================================="
echo "[ req ]" > openssl.cnf
echo "default_bits = 1024" >> openssl.cnf
echo "default_keyfile = privkey.pem" >> openssl.cnf
echo "distinguished_name = req_distinguished_name" >> openssl.cnf
echo "prompt = no" >> openssl.cnf
echo "[ req_distinguished_name ]" >> openssl.cnf
echo "C = $OP_CERT_COUNTRY" >> openssl.cnf
echo "ST = $OP_CERT_STATE" >> openssl.cnf
echo "L = $OP_CERT_LOCALITY" >> openssl.cnf
echo "O = $OP_CERT_ORG" >> openssl.cnf
# Note that CN ("Commmon Name") is chosed to be different to make sure the output cert.pem does not appear to be self-signed.
echo "CN = manager certificate" >> openssl.cnf
/usr/local/ssl/bin/openssl req -config openssl.cnf -newkey dsa:dsaparam.pem -sha1 -keyout managerkey.pem -outform PEM -out managerreq.pem
/usr/local/ssl/bin/openssl x509 -req -inform PEM -in managerreq.pem -sha1 -CA casign.pem -CAkey casign.pem -CAcreateserial -outform PEM -out managercert.pem -days $OP_CERT_CERT_DAYS
cp managercert.pem+managerkey.pem+ca.pem cert.pem
rm managerkey.pem managerreq.pem managercert.pem casign.srl openssl.cnf
echo " ==========================================================="
echo " This certificate will expire in $OP_CERT_CERT_DAYS days."
echo " ============================================================"
}
Code :
[root@li372 ssl]# ./op_cert.cnf op_cert: please edit the environment variables at the start of this script file [root@li372 ssl]# Merci d'avance |
|
|
|
|
|
#8 (permalink) | |
|
Membre éclairé
![]() Date d'inscription: avril 2008
Localisation: Chambéry - Nancy
Âge: 21
Messages: 342
|
Utilise la commande export au lieu de set pour définir tes variables d'environnement
__________________
Citation:
|
|
|
|
|
![]() |
![]() |
||
pb de lecture de script
|
||
| Outils de la discussion | |
|
|