Este é um script elaborado no Linux (CentOS) em bash, foi desenvolvido para criar pasta de usuário e para compartilhar com grupos diversos, com a utilização do Samba, assim como limitar o armazenamento por extensão de arquivos. Antes de executar o script certifique-se que esta a usar a distribuição correta do bash e não do shell, utilize o comando:

root@servidor:~# echo $SHELL

 

Segue abaixo a imagem da execução do script:

bashsamba


Segue o script:

root@servidor:~# user_pasta_samba.sh

#####################################
#!/bin/bash
# By Leandro Cestaro
Este endereço de email está protegido contra piratas. Necessita ativar o JavaScript para o visualizar.
#####################################
 
 # PASTA DO DEPARTAMENTO OU GRUPO:
                dirgroups='/home/destino/grupos_dominio'
 
 # PASTA DO USUARIO:
                dirusers='/home/destino/usuarios_dominio'
 
 #PASTA DOS ARQUIVOS DELETADOS SEM REMOVER A PASTA, SERÁ MOVIDO PARA A PASTA ABAIXO:
                dirdel='/home/destino/grupos_dominio/deletados'
 
 # ARQIVOS DE TRANSFERENCIA PARA A CRIACAO DE SCRIPTS:
                bat='/etc/samba/bat'
 
 # SERVIDOR LOCAL DE ARQUIVOS:
                servidorarquivos='IP_SERVIDOR_LOCAL'
 
 # SERVIDOR DE DOMINIO ONDE SERA ARMAZENADO O SCRIPT PARA O MAPEAMENTO DAS PASTAS:
                dominio='IP_SERVIDOR_DOMINIO_LDAP'
 
 # LOCAL DE ARMAZENAMENTO DOS ARQUIVOS DE COMPARTILHAMENTO DO SAMBA:
                sambashare='/etc/samba/share'
 
 # LOCAL ONDE SERA ARMAZENADO O SCRIPT PARA O MAPEAMENTO DAS PASTAS:
                localscriptremoto='/var/lib/samba/netlogon/scripts'
# USUARIO DE ACESSO AO SERVIDOR DE DOMINIO:
                user='root'
 
 ##### NAO ALTERAR ABAIXO #####
                black='\E[30;40m'
              red='\E[31;40m'
              green='\E[32;40m'
              yellow='\E[33;40m'
              blue='\E[34;40m'
              magenta='\E[35;40m'
              cyan='\E[36;40m'
              white='\E[37;40m'
              redback='\E[37;41m'
              black2='\E[30;47m'
             
Principal() {
clear
dir="Diretório: `pwd` "
kernel="Kernel: `uname -r` "
arquitetura="Arquitetura: `uname -m` "
data="Data: $(date +%d-%m-%y-%a)"
echo
echo -e $white"3[1m| ADICIONAR E REMOVER USUÁRIOS NO SERVIDOR DE ARQUIVOS |3[0m"; tput sgr0
echo
echo -e $magenta
echo $dir            
echo $kernel      
echo $arquitetura           
echo $data           
echo ; tput sgr0
echo -e $yellow"3[1mOPÇÕES" ; tput sgr0
echo -e $green
echo -e "3[1m#### ADICIONAR / CRIAR / ALTERAR ####3[0m"
echo -e $green"1 Adicionar PASTA do Usuário"
echo "2 Adicionar PASTA de Compartilhamento"
echo ; tput sgr0
echo -e $red"3[1m#### DELETAR / EXCLUIR ####3[0m"
echo -e $red"3 Remover PASTA do Usuário"
echo "4 Deletar a PASTA de Compartilhamento"
echo ; tput sgr0
echo -e $yellow"3[1m#### PESQUISAR / SAIR ####"; tput sgr0
echo -e $yellow"5 Pesquisar"
echo "6 Sair"; tput sgr0
echo
echo -e -n $cyan "Entre com a opção desejada => "; tput sgr0
read opcao
echo
case $opcao in
1) Adicionar;;
2) Compartilhamento;;
3) Deletar;;
4) DelGroup;;
5) Pesquisar;;
6) exit;;
*)"Opção Desonhecida, tente novamente..." ; echo ; Principal;;
esac
}
Adicionar() {
echo -n "Entre com o login do usuário: "
read login
mkdir $dirusers/$login
chown -R $login: $dirusers/$login
chmod -R 0700 $dirusers/$login
echo -e $cyan"#########################################################"
echo
echo "Mensagem do Sistema:"
echo
PesquisarComandos
echo
echo "#########################################################"
echo ; tput sgr0
echo -e $redback"3[1mPressione ENTER para continuar...3[0m "; tput sgr0
read msg
Principal
}
PesquisarComandos(){
echo
ls -lh $dirusers | grep $login
echo
ls -lh $dirusers/$login
echo
du -hs $dirusers/$login
}
Pesquisar(){
echo -n "Entre com o login: "
read login
echo
echo -e $green"#########################################################"
echo
PesquisarComandos
echo
echo "#########################################################"; tput sgr0
echo
echo -e $redback"3[1mPressione ENTER para voltar ao menu Principal...3[0m "; tput sgr0
read msg
echo "#########################################################"; tput sgr0
Principal
}
Compartilhamento (){
echo
echo -n "Nome da PASTA (visualizada pelo WINDOWS): "
read compartilha
echo
echo -n "Qual o Supervisor do Departamento? "
read comentario
echo
echo "Qual o GRUPO a PASTA pertence? "
echo
cat /etc/samba/netgroup.conf
echo
echo " Ex: (Buran:*:1024:) = Departamento: Buran, ID:1024"
echo
echo -n "Coloque o DEPARTAMENTO: "
read group
echo
echo -e $cyan"#########################################################"
echo
echo "Mensagem do Sistema:"
echo; tput sgr0
mkdir $dirgroups/$group
chmod -R 0770 $dirgroups/$group
chgrp -hR $group $dirgroups/$group
cat << EOF > $sambashare/smb.conf.$group
[$compartilha]
         comment = Departamento $compartilha
         path = $dirgroups/$group
         admin users = @admins,@$group
         public = yes
        writeable = yes
        read only = No
        create mask = 0770
        directory mask = 0770
        browseable = yes
# BLOQUEIOS
        veto files =
/*.aif/*.avi/*.cpl/*.mid/*.mov/*.mpa/*.mpe/*.mp3/*.mpeg/*.mpg/*.rar/*.scr/*.vbe/*.vbs/*.wav/*.wma/*.wmv/*.pif/*.bat/*.exe/*.eml/*.rmvb/
        delete veto files = yes
# LIXEIRA
        vfs objects = recycle
        recycle:repository = .recycle
        recycle:keeptree = True
        recycle:maxsize = 1024000
        recycle:versions = True
        recycle:noversions = .doc|.xls|.ppt|.pdf
        recycle:touch = False
        recycle:exclude = *.tmp *.temp *.obj *.~??
 # AUDITORIA
        vfs objects = full_audit
        full_audit:success = open, opendir, write, read, rename, mkdir, rmdir, chmod, chown
        full_audit:prefix = %u|%I|%S
        full_audit:failure = none
        full_audit:facility = local5
        full_audit:priority = notice
EOF
cat << EOF >> /etc/samba/smb.conf
include = $sambashare/smb.conf.$group
EOF
cat << EOF > $bat/$group.bat
net use P: \\\\$servidorarquivos\\$compartilha /persistent:yes
EOF
rm -rf $bat/$group.bat
/etc/init.d/smb restart
echo
echo -e $cyan"#########################################################"; tput sgr0
echo
echo -e "3[1mCompartilhamento criado com sucesso!!!3[0m"
echo
echo -e $cyan"#########################################################"
echo ; tput sgr0
echo -e $yellow"Caso queira fazer alguma alteracao de Script entre na pasta $sambashare/smb.conf.$group e altere o que for necessário."
echo ; tput sgr0
echo
echo -e $redback"3[1mPressione ENTER para finalizar esta operação e voltar ao M E N U principal...3[0m " ; tput sgr0
read msg
clear
Principal
}
Deletar() {
echo -n "Login do Usuário para deletar a PASTA: "
read login
echo
echo -e $red "Arquivos que estão na pasta do Usuário:"
echo
PesquisarComandos
echo
echo ; tput sgr0
echo -n "Deletar pasta (y ou n): "
read decisao
echo
if [ "$decisao" == "n" ];
then
decisao=n
echo -e $cyan"#########################################################"
echo
echo "Mensagem do Sistema: "
echo ; tput sgr0
mv $dirusers/$login $dirdel
echo
echo -e $magenta"Pasta do usuário - $login - está na pasta " $dirdel ", para facilitar a sua localização."; tput sgr0
echo
echo -e $cyan"#########################################################"; tput sgr0
else
decisao=y
echo -e $cyan"#########################################################"
rm -rf $dirusers/$login
echo
echo "Confirmando exclusão de PASTA: "
du -hs $login
echo
echo "PASTA removida com sucesso!!!"
echo
echo "#########################################################"; tput sgr0
fi
echo
echo -e $redback"3[1mPressione ENTER para continuar...3[0m "; tput sgr0
read msg
echo
Principal
}
PesquisarComandosGroups(){
echo
ls -lh $dirgroups | grep $group
echo
ls -lh $dirgroups/$group
echo
du -hs $dirgroups/$group
}
RemoverDadosGroups() {
rm -rf $sambashare/smb.conf.$group
sed -i '/smb.conf.$group$/d' /etc/samba/smb.conf
cat << EOF >> $bat/removerpasta.sh
rm $localscriptremoto/$group.bat
EOF
sftp -b $bat/removerpasta.sh $user@$dominio:$localscriptremoto
rm -rf $bat/removerpasta.sh
}
DelGroup() {
echo -n "Nome do grupo para deletar a PASTA: "
read group
echo -e $red "Arquivos que estão na pasta do grupo:"
echo
PesquisarComandosGroups
echo
echo ; tput sgr0
echo -n "Deletar pasta (y ou n): "
read decisao
echo
if [ "$decisao" == "n" ];
then
decisao=n
echo -e $cyan"#########################################################"
echo
echo "Mensagem do Sistema: "
echo ; tput sgr0
mv $dirgroups/$group $dirdel
RemoverDadosGroups
echo
echo -e $magenta"Pasta do usuário - $login - está na pasta " $dirdel ", para facilitar a sua localização."; tput sgr0
echo
echo -e $cyan"#########################################################"; tput sgr0
else
decisao=y
echo -e $cyan"#########################################################"
rm -rf $dirgroups/$group
RemoverDadosGroups
echo
echo "PASTA removida com sucesso!!!"
echo
echo "#########################################################"; tput sgr0
fi
echo
echo -e $redback"3[1mPressione ENTER para continuar...3[0m "; tput sgr0
read msg
echo
Principal
}
Principal
 
 

Comentar


Código de segurança
Atualizar