Pular para o conteúdo

Converte permissões de octal para textual e vice-versa

Shell Script que faz a conversão de permissões no formato OCTAL para TEXTUAL e vice-versa.
Rafael Ancinelo Adolpho radolpho
Hits: 6.561 Categoria: Shell Script Subcategoria: Introdução
  • Download
  • Nova versão
  • Indicar
  • Denunciar

Descrição

Shell Script que faz a conversão de permissões no formato OCTAL para TEXTUAL e vice-versa.
Download converte_permissoes.sh Enviar nova versão

Versões atualizadas deste script

Esconder código-fonte

#!/bin/bash
#Autor radolpho 2012
echo " Escolha com opcao voce deseja (a ou b)
a) Octal para texto
b) Texto para octal "
read resp

if [ $resp == a ] ;then #Conversao de OCTAL para TEXTUAL
   echo "Digite a permissao em  OCTAL Ex. 776"
   read poct

   #Permissao de user
   if [ ${poct:0:1} == 0 ] ;then
      u="---"   
   elif [ ${poct:0:1} == 1 ] ;then
      u="--x"
   elif [ ${poct:0:1} == 2 ] ;then
      u="-w-"
   elif [ ${poct:0:1} == 3 ] ;then
      u="-wx"
   elif [ ${poct:0:1} == 4 ] ;then
      u="r--"
   elif [ ${poct:0:1} == 5 ] ;then
      u="r-x"
   elif [ ${poct:0:1} == 6 ] ;then
      u="rw-"
   elif [ ${poct:0:1} == 7 ] ;then
      u="rwx"
   fi

   #Permissao de group
        if [ ${poct:1:1} == 0 ] ;then
                g="---"   
        elif [ ${poct:1:1} == 1 ] ;then
                g="--x"
        elif [ ${poct:1:1} == 2 ] ;then
                g="-w-"
        elif [ ${poct:1:1} == 3 ] ;then
                g="-wx"
        elif [ ${poct:1:1} == 4 ] ;then
                g="r--"
        elif [ ${poct:1:1} == 5 ] ;then
                g="r-x"
        elif [ ${poct:1:1} == 6 ] ;then
                g="rw-"
        elif [ ${poct:1:1} == 7 ] ;then
                g="rwx"
        fi


   #Permissao de other
        if [ ${poct:2:1} == 0 ] ;then
                o="---"
        elif [ ${poct:2:1} == 1 ] ;then
                o="--x"
        elif [ ${poct:2:1} == 2 ] ;then
                o="-w-"
        elif [ ${poct:2:1} == 3 ] ;then
                o="-wx"
        elif [ ${poct:2:1} == 4 ] ;then
                o="r--"
        elif [ ${poct:2:1} == 5 ] ;then
                o="r-x"
        elif [ ${poct:2:1} == 6 ] ;then
                o="rw-"
        elif [ ${poct:2:1} == 7 ] ;then
                o="rwx"
        fi

   echo "Conversao de OCTAL para TEXTUAL\n"
   echo $poct" >>>> "$u$g$o

elif [ $resp == b ] ;then #Conversao de TEXTUAL para OCTAL

   echo "Digite a permissao em TEXTUAL Ex. rwxrw--w-"
   read ptxt
   
   #Permissao de user
        if [ ${ptxt:0:3} == "---" ] ;then
                u="0"   
        elif [ ${ptxt:0:3} == "--x" ] ;then
                u="1"
        elif [ ${ptxt:0:3} == "-w-" ] ;then
                u="2"
        elif [ ${ptxt:0:3} == "-wx" ] ;then
                u="3"
        elif [ ${ptxt:0:3} == "r--" ] ;then
                u="4"
        elif [ ${ptxt:0:3} == "r-x" ] ;then
                u="5"
        elif [ ${ptxt:0:3} == "rw-" ] ;then
                u="6"
        elif [ ${ptxt:0:3} == "rwx" ] ;then
                u="7"
        fi

    #Permissao de group
        if [ ${ptxt:3:3} == "---" ] ;then
                g="0"
        elif [ ${ptxt:3:3} == "--x" ] ;then
                g="1"
        elif [ ${ptxt:3:3} == "-w-" ] ;then
                g="2"
        elif [ ${ptxt:3:3} == "-wx" ] ;then
                g="3"
        elif [ ${ptxt:3:3} == "r--" ] ;then
                g="4"
        elif [ ${ptxt:3:3} == "r-x" ] ;then
                g="5"
        elif [ ${ptxt:3:3} == "rw-" ] ;then
                g="6"
        elif [ ${ptxt:3:3} == "rwx" ] ;then
                g="7"
        fi


   #Permissao de other
        if [ ${ptxt:6:3} == "---" ] ;then
                o="0"   
        elif [ ${ptxt:6:3} == "--x" ] ;then
                o="1"
        elif [ ${ptxt:6:3} == "-w-" ] ;then
                o="2"
        elif [ ${ptxt:6:3} == "-wx" ] ;then
                o="3"
        elif [ ${ptxt:6:3} == "r--" ] ;then
                o="4"
        elif [ ${ptxt:6:3} == "r-x" ] ;then
                o="5"
        elif [ ${ptxt:6:3} == "rw-" ] ;then
                o="6"
        elif [ ${ptxt:6:3} == "rwx" ] ;then
                o="7"
        fi

        echo "Conversao de TEXTUAL para OCTAL\n"
        echo $ptxt" >>>> "$u$g$o

fi

Pós-instalação do openSUSE Tumbleweed

Script para Backup Banco Firebird

Sabendo quem acessou um site

Busca string em arquivos

Agenda de contatos em DIALOG

#1 Comentário enviado por vitinho217 em 25/06/2014 - 11:13h
O script ficou muito grande, existe uma lógica que pode incurta-lo.

Contribuir com comentário

Entre na sua conta para comentar.