Introdução ao Shell Script
O artigo traz uma introdução a Shell Script. Criaremos alguns exemplos práticos para que você consiga criar seus próprios scripts de automatização. Shell Script é um tipo de linguagem de programação que é utilizado por administradores Linux/Unix. Também é possível criar scripts para outros sistemas operacionais, mas o meu foco aqui será mesmo os sistemas Linux e suas distribuições.
[ Hits: 22.156 ]
Por: Renato Diniz Marigo em 15/02/2016 | Blog: http://www.renatomarigo.com.br
#!/bin/bash for line in $(cat lista.txt) do echo "$line" done
#!/bin/bash while read LINE do echo $LINE done < lista.txt
#!/bin/bash
echo "Script criado para o uso Case"
echo "Opção 1: Listar o conteúdo de /etc/init.d"
echo "Opção 2: Listar o conteúdo de /etc/kernel"
read OPCAO
case $OPCAO in
1)
echo "Você escolheu a opção $OPCAO "
ls /etc/init.d;;
2)
echo "Você escolheu a opção $OPCAO "
ls /etc/kernel;;
*)echo "Você não digitou uma opção válida";;
esac
#!/bin/bash while true do clear; #Scripts e comandos done
#!/bin/bash
while true
do
clear;
echo "Script criado para o uso Case"
echo "Opção 1: Listar o conteúdo de /etc/init.d"
echo "Opção 2: Listar o conteúdo de /etc/kernel"
echo "Opção 3: Sair"
read OPCAO
case $OPCAO in
1)
echo "Você escolheu a opção $OPCAO "
ls /etc/init.d
sleep 3;;
2)
echo "Você escolheu a opção $OPCAO "
ls /etc/kernel
sleep 3;;
3)
echo "Você escolheu a opção $OPCAO "
sleep 3
exit;;
*)echo "Você não digitou uma opção válida"
sleep 3;;
esac
done
#!/bin/bash if [ -e "/etc/teste" ] then echo "O diretório existe" else echo "O diretório não existe" fi
-eq Igual -ne Diferente -gt Maior -lt Menor -o Ou -d Se for um diretório -e Se existir -z Se estiver vazio -f Se conter texto -o Se o usuário for o dono -r Se o arquivo pode ser lido -w Se o arquivo pode ser alterado -x Se o arquivo pode ser executadoA seguir mostro a execução dele na tela:
#!/bin/bash printf "Deseja exibir estas informações /etc/init.d ?" read OPCAO if [[ $OPCAO == "S" || $OPCAO == "s" ]] then echo 'O conteúdo será exibido' ls /etc/init.d else echo 'O conteúdo não será exibido' echo "" fi
File operators:
-a FILE True if file exists.
-b FILE True if file is block special.
-c FILE True if file is character special.
-d FILE True if file is a directory.
-e FILE True if file exists.
-f FILE True if file exists and is a regular file.
-g FILE True if file is set-group-id.
-h FILE True if file is a symbolic link.
-L FILE True if file is a symbolic link.
-k FILE True if file has its `sticky' bit set.
-p FILE True if file is a named pipe.
-r FILE True if file is readable by you.
-s FILE True if file exists and is not empty.
-S FILE True if file is a socket.
-t FD True if FD is opened on a terminal.
-u FILE True if the file is set-user-id.
-w FILE True if the file is writable by you.
-x FILE True if the file is executable by you.
-O FILE True if the file is effectively owned by you.
-G FILE True if the file is effectively owned by your group.
-N FILE True if the file has been modified since it was last read.
FILE1 -nt FILE2 True if file1 is newer than file2 (according to
modification date).
FILE1 -ot FILE2 True if file1 is older than file2.
FILE1 -ef FILE2 True if file1 is a hard link to file2.
All file operators except -h and -L are acting on the target of a symbolic
link, not on the symlink itself, if FILE is a symbolic link.
String operators:
-z STRING True if string is empty.
-n STRING
STRING True if string is not empty.
STRING1 = STRING2
True if the strings are equal.
STRING1 != STRING2
True if the strings are not equal.
STRING1 < STRING2
True if STRING1 sorts before STRING2 lexicographically.
STRING1 > STRING2
True if STRING1 sorts after STRING2 lexicographically.
Nagios 3 + NagiosQL no Ubuntu Server 12.04
Tutorial de instalação do Squid no CentOS
Comando: journalctl - Monitoramento de LOGs
VLAN Tagging nos sistemas GNU/Linux derivados do Red Hat
Zabbix Server 2.0 no Ubuntu Server 12.04 - Instalação e configuração
Discar BrasilTelecom com PPPOE no Ubuntu 6.10
Montando, monitorando e gerando logs dos compartilhamento NFS automaticamente
AWK - Manipulação de arquivos de texto
Cirurgia para acelerar o openSUSE em HD externo via USB
Void Server como Domain Control
Modo Simples de Baixar e Usar o bash-completion
Monitorando o Preço do Bitcoin ou sua Cripto Favorita em Tempo Real com um Widget Flutuante
[Resolvido] VirtualBox can't enable the AMD-V extension
Como verificar a saúde dos discos no Linux
Como instalar , particionar, formatar e montar um HD adicional no Linux?
Como automatizar sua instalação do Ubuntu para desenvolvimento de software.
Fiz uma pergunta no fórum mas não consigo localizar (20)
Quais os códigos mais dificeis que vcs sabem fazer? (8)
Pfsense inacessivel após um periodo de tempo (1)
Não consigo instalar distro antiga no virtualbox nem direto no hd (9)









