Codice: Seleziona tutto
STRING='SSLProtocol - ALL +TLSv1'
FILE=TUO_FILE
grep -w "$STRING" $FILE || echo "$STRING" >> $FILE
Codice: Seleziona tutto
STRING='SSLProtocol - ALL +TLSv1'
FILE=TUO_FILE
grep -w "$STRING" $FILE || echo "$STRING" >> $FILECodice: Seleziona tutto
FILE="conf/context.xml"
NODE=$(xmlstarlet el -a $FILE | grep -w "Context/Manager")
if [ "$NODE" = "" ];then
xmlstarlet ed -L --subnode "/Context" --type elem -n Manager -v "" $FILE
fi
ATTRIBUTE=$( xmlstarlet el -a $FILE | grep -w "Context/Manager/@randomClass")
if [ "$ATTRIBUTE" = "" ];then
# aggiungi attributo
xmlstarlet ed -L -i '/Context/Manager' -t attr -n randomClass -v java.security.SecureRandom $FILE
else
# aggiorna attributo già esistente
xmlstarlet ed -L -u '/Context/Manager/@randomClass' -v java.security.SecureRandom $FILE
fi
Codice: Seleziona tutto
#! /bin/bash
function add_or_update_attribute(){
# input
ATTR_NAME=$1
ATTR_VALUE=$2
ATTRIBUTE=$( xmlstarlet el -a $FILE | grep -w "Context/Manager/@${ATTR_NAME}")
if [ "$ATTRIBUTE" = "" ];then
# aggiungi attributo
xmlstarlet ed -L -i '/Context/Manager' -t attr -n $ATTR_NAME -v "$ATTR_VALUE" $FILE
else
# aggiorna attributo già esistente
xmlstarlet ed -L -u "/Context/Manager/@$ATTR_NAME" -v "$ATTR_VALUE" $FILE
fi
}
FILE="context.xml"
NODE=$(xmlstarlet el -a $FILE | grep -w "Context/Manager")
if [ "$NODE" = "" ];then
xmlstarlet ed -L --subnode "/Context" --type elem -n Manager -v "" $FILE
fi
add_or_update_attribute "randomClass" "java.security.SecureRandom"
add_or_update_attribute "randomClass2" "xxxxxx"
Codice: Seleziona tutto
#!/bin/bash
#
FILE="conf/server.xml"
NODE=$(xmlstarlet el -a $FILE | grep -w "Connector")
if [ "$NODE" = "" ];then
xmlstarlet ed -L --type elem -n Connector -v "" $FILE
fi
ATTRIBUTE1=$( xmlstarlet el -a $FILE | grep -w "Connector/@maxThreads")
if [ "$ATTRIBUTE1" = "" ];then
# aggiungi attributo
xmlstarlet ed -L -i '/Connector' -t attr -n maxThread -v 250 $FILE
else
# aggiorna attributo già esistente
xmlstarlet ed -L -u '/Connector/@maxThread' -v 250 $FILE
fi
Codice: Seleziona tutto
FILE="conf/context.xml"
NODE=$(xmlstarlet el -a $FILE | grep -w "Server/Service/Connector")
if [ "$NODE" = "" ];then
xmlstarlet ed -L --subnode "/Service" --type elem -n Connector -v "" $FILE
fi
ATTRIBUTE=$( xmlstarlet el -a $FILE | grep -w "Server/Service/Connector/@maxThread")
if [ "$ATTRIBUTE" = "" ];then
# aggiungi attributo
xmlstarlet ed -L -i '/Server/Service/Connector' -t attr -n maxThread -v 250 $FILE
else
# aggiorna attributo già esistente
xmlstarlet ed -L -u '/Server/Service/Connector/@maxThread' -v 250 $FILE
fi
Codice: Seleziona tutto
FILE="conf/server.xml"Codice: Seleziona tutto
xmlstarlet ed -L --subnode "/Service" --type elem -n Connector -v "" $FILE
Purtroppo se il nodo non è presente non viene creato. (Sarebbe comodo, ma xmlstarlet è un programma spartanopiccolotauro2 [url=http://forum.ubuntu-it.org/viewtopic.php?p=4589963#p4589963][img]http://forum.ubuntu-it.org/images/icons/icona-cita.gif[/img][/url] ha scritto:lo sai che non sono convinto che questa istruzione è giusta?a me non lo crea mai un sotto nodo con quell'attirbutoCodice: Seleziona tutto
xmlstarlet ed -L --subnode "/Service" --type elem -n Connector -v "" $FILE
Codice: Seleziona tutto
FILE="webapps/manager/WEB-INF/web.xml"
NODE=$(xmlstarlet el -a $FILE | grep -w "web-app/security-constraint")
if [ "$NODE" = "" ];then
xmlstarlet ed -L --subnode "/web-app" --type elem -n security-constraint -v "" $FILE
fi
NODE2=$(xmlstarlet el -a $FILE | grep -w "web-app/security-constraint/user-data-constraint")
if [ "$NODE2" = "" ];then
xmlstarlet ed -L --subnode "/web-app/security-constraint" --type elem -n user-data-constraint -v "" $FILE
fi
NODE3=$(xmlstarlet el -a $FILE | grep -w "web-app/security-constraint/user-data-constraint/transport-guarantee")
if [ "$NODE3" = "" ];then
xmlstarlet ed -L --subnode "/web-app/security-constraint/user-data-constraint" --type elem -n transport-guarantee -v "CONFIDENTIAL" $FILE
fiCodice: Seleziona tutto
xmlstarlet ed -L --subnode "/web-app/security-constraint" --type elem -n ciao -v "" web.xmlCodice: Seleziona tutto
xmlstarlet el -a web.xml | grep -w "web-app/security-constraint"

Codice: Seleziona tutto
xmlstarlet ed -L --subnode "/_:web-app/_:security-constraint" --type elem -n ciao -v "" web.xmlCodice: Seleziona tutto
ATTRIBUTE=$( xmlstarlet el -v $FILE | grep -w "Server/Service/Engine/Realm/@className='org.apache.catalina.realm.UserDatabaseRealm'")
Codice: Seleziona tutto
[root@localhost WEB-INF]# xmlstarlet ed -L --subnode "/_:web-app/_:security-constraint" --type elem -n ciao -v "" web.xml
Undefined namespace prefix: /_:web-app/_:security-constraint
Invalid expression: /_:web-app/_:security-constraint

forse hai una version vecchia di xmlstarlet? posta il risultato dipiccolotauro2 [url=http://forum.ubuntu-it.org/viewtopic.php?p=4590370#p4590370][img]http://forum.ubuntu-it.org/images/icons/icona-cita.gif[/img][/url] ha scritto:non gli è piaciutoCodice: Seleziona tutto
[root@localhost WEB-INF]# xmlstarlet ed -L --subnode "/_:web-app/_:security-constraint" --type elem -n ciao -v "" web.xml Undefined namespace prefix: /_:web-app/_:security-constraint Invalid expression: /_:web-app/_:security-constraint
Codice: Seleziona tutto
xmlstarlet --versionCodice: Seleziona tutto
[root@localhost apache-tomcat-6.0.39]# xmlstarlet --version
1.3.1
compiled against libxml2 2.7.6, linked with 20706
compiled against libxslt 1.1.26, linked with 10126
[root@localhost apache-tomcat-6.0.39]#
Visualizzano questa sezione: 0 utenti iscritti e 3 ospiti