Jump to content

[BashScript] - Editar ficheiro


DarkHipno
 Share

Recommended Posts

Boas tardes, não sei se é bem aqui que tenho de postar a minha duvida, também procurei mas não encontrei nada no fórum que me podesse ajudar.

É o seguinte necessito de um script que procure num ficheiro por exemplo o ficheiro de configuração do apache: httpd.conf  e que localiza-se a linha DirectoryIndex e que a substitui-se por "DirectoryIndex index.html index.htm index.shtml index.cgi index.php index.php3 index.php4 index.pl".

Isto é para integrar num ficheiro de instalação/configuração automatica do apache que estou a fazer para um projecto de aptidão tecnica (PAT).

Cumprimentos...

Link to comment
Share on other sites

Boas. Não sei se é bem isto que pretendes, nem se é o melhor modo de o fazer. Mas tá aqui a minha ajuda.

#!/bin/bash
nfile1="/etc/httpd/httpd.conf"
nfile2="httpd.conf"
string="DirectoryIndex"
replace="    DirectoryIndex index.html index.htm index.shtml index.cgi index.php index.php3 index.php4 index.pl"

cline=`cat $nfile1 | grep -n $string | grep -v "#" | cut -f1 -d:`
let cline=$cline-1

head -n$cline $nfile1 > $nfile2
echo $replace >> $nfile2
let cline=$cline+1
let cline=`wc -l $nfile1 | tr ' ' '#' | cut -f1 -d'#'`-$cline
tail -n$cline $nfile1 >> $nfile2
mv $nfile2 $cfile1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.