Baixe o app para aproveitar ainda mais
Prévia do material em texto
Lista de Exercícios – Shell Script Avaliação de scripts OBS: Para os exercícios abaixo, não é permitido executar o script, mas o man pode ser usado para pesquisa de comandos novos. 1. Descreva a função do script abaixo. Ele é executado quinzenalmente na minha conta. #!/bin/bash # set -x lbl=$(date +%y%b%d-%H%M%S | tr '[A-Z]' '[a-z]') maildir=$HOME/Mail logfile=$maildir/log bakfile=$logfile$lbl if [ -s $logfile ] ; then mv -f $logfile $bakfile touch $logfile gzip -f -9 $bakfile fi 2. Descreva a função do script abaixo: #!/bin/bash for P in $( ps -U $USER -o "%p %n %a" | egrep $1 | \ egrep -v 'ps|egrep|re-nice' | cut -d ' ' -f 1' ) ; do renice +8 $P >/dev/null done 3. Descreva a função do script abaixo. Você não tem permissão para executá-lo. #!/bin/bash cd /home/$1 ; /bin/ls ; echo for UU in $(/bin/ls) ; do cd $UU if [ -f core ] ; then rm core echo $UU fi cd - done 4. Descreva a função das funções abaixo. function ff(){ local a="$1"; shift; find . -name $a -print "$@" ; } function ffd(){ local a="$1"; shift; find . -name $a -type d -print "$@" ; } function cr() { chmod a+r "$@" ; } function cw() { chmod u+w "$@" ; } function cx() { chmod a+x "$@" ; } function crr(){ if [ $# = "0" ] ; then DIR="." ; else DIR="$1" ; fi ;\ find $DIR -type f -exec chmod a+r {} \; ; } function cxr() { if [ $# = "0" ] ; then DIR="." ; else DIR="$1" ; fi ;\ find $DIR -type d -exec chmod a+x {} \; ; } function mc() { echo "comando mc nulo" ; } function m() { for file in "$@" ; do if [ ! $# = 1 ] ; then echo ------- $file ------- ; echo fi ; if [ -d $file ] ; then ls -F $file else if [ "${file%.Z}x" = "${file}x" -a "${file%.z}x" = "${file}x" \ -a "${file%.gz}x" = "${file}x" ] then more $file else if [ "${file%.bz2}x" = "${file}x" ] ; then bzcat $file else # [ "${file%.gz}x" = "${file}x" ] gzcat $file | more fi ; # bzip2 ou gzip fi ; fi ; if [ ! $# = 1 ] ; then echo fi ; done ; }
Compartilhar