3
I have a project that whenever I go up to production or change the development machine I copy and paste the whole folder, only whenever I do this I have to give permissions in this folder and in some sub-folders.
I would like to create a script
to do this automatically, someone can help me.
Scenario: I copy the folder projeto
into my /var/www
give permissions for this project.
sudo chmod 755 /var/www/projeto -R
# dai me pede a senha de root, eu digito e ok
# dai eu tenho que alterar outras permissões de outras pastas para escrita
sudo chmod 777 /var/www/projeto/uploads -R
sudo chmod 777 /var/www/projeto/logs -R
I imagine it to be simple, but I don’t have much idea, because I’m thinking of calling this shell pass the path of the project where will give these permissions and I don’t know if it is correct to pass in the root password.
I think it would be something so correct:
#!/bin/sh
#dar permissoes necessarias
PASTAPROJETO=$1
sudo chmod 755 '$PASTAPROJETO' -R
sudo chmod 777 '$PASTAPROJETO'/uploads -R
sudo chmod 777 '$PASTAPROJETO'/logs -R
What’s the matter, it’s not working?
– Ricardo
@alacerda not yet... nor knew all these parameters... I will take a look
– Marcelo Diniz
@winged unfortunately not... apparently when I gave the command he even rode without mistakes but did not work.
– Marcelo Diniz
@Ricardo the script was giving an error that could not find the folder. Then I removed the quotes and it worked. But when I call the script I have to pass the root password. That’s why I put sudo in the script. Is there anything simpler than having to do it like this? Valew
– Marcelo Diniz
@Marcelodiniz dude, you should give permissions to the user you’re using.
– Ricardo
The problem you should investigate is how to give a user permission to run certain commands with
sudo
without having to enter password. This is perfectly possible, but it is another question. :)– Daniel C. Sobral
Daniel is correct... give permission, you already know because you have already put the answer in the question itself. The question, as I understand then is the need to run this with root, no password through
sudo
. Write the script with the chmod/chown commands and then run the script with sudo :sudo sh meuscript.sh
and it will do everything at once. If you need to avoid typing password, search for the configurationsudoers
or ask another more specific question of how to use it.– ceinmart