diff --git a/README b/README index 56b3302..d09c997 100644 --- a/README +++ b/README @@ -1,4 +1,4 @@ -Here is some more detailed information about the scripts I have written. I do not consider myself a programmer, I create these little programs as experiments to have a play with the language, or to solve a problem for myself. I would gladly accept pointers from others to improve the code and make it more efficient, or simplify the code. If you would like to make any comments then please feel free to email me at craig@geekcomputers.co.uk. +Here is a detailed information about the scripts I have written. I do not consider myself a programmer, I create these little programs as experiments to have a play with the language, or to solve a problem for myself. I would gladly accept pointers from others to improve the code and make it more efficient, or simplify the code. If you would like to make any comments then please feel free to email me at craig@geekcomputers.co.uk. In the scripts the comments etc are lined up correctly when they are viewed in Notepad++ or vi. This is what I use to code Shell scripts. @@ -58,4 +58,4 @@ unix_users_to_sql.ksh - Export UNIX users to sql, you can change the last line i vosstat.sh - Gather OS statistics to place in to the database -world_writable.ksh - Gather OS statistics to place in to the database \ No newline at end of file +world_writable.ksh - Gather OS statistics to place in to the database diff --git a/batch_file_rename.sh b/batch_file_rename.sh index 0e14cd0..6b13a11 100644 --- a/batch_file_rename.sh +++ b/batch_file_rename.sh @@ -31,12 +31,12 @@ funct_check_params() # Start of the procedure funct_batch_rename() # Start of the procedure { - old_ext_cut=`echo ${old_ext} | cut -f2 -d .` # Cut just the extension passed, lose the . - new_ext_cut=`echo ${new_ext} | cut -f2 -d .` # Cut just the extension passed, lose the . + old_ext_cut=$(echo "${old_ext}" | cut -f2 -d .) # Cut just the extension passed, lose the . + new_ext_cut=$(echo "${new_ext}" | cut -f2 -d .) # Cut just the extension passed, lose the . # This will carry out the rename - for file in $(ls $work_dir/*$old_ext); do mv $file `echo $file | sed 's/\(.*\.\)'$old_ext_cut'/\1'$new_ext_cut/` ; done + for file in "$work_dir"/*"$old_ext"; do mv "$file" "$(echo "$file" | sed 's/\(.*\.\)'"$old_ext_cut"'/\1'"$new_ext_cut"/)" ; done } ################ @@ -56,4 +56,4 @@ NARG=$# funct_batch_rename # Call the procedure } # End of the main program -## End of Script +## End of Script \ No newline at end of file diff --git a/bk_daily.sh b/bk_daily.sh new file mode 100644 index 0000000..df3b38f --- /dev/null +++ b/bk_daily.sh @@ -0,0 +1,39 @@ +#!/bin/bash +## +##### NOME: rotina_backup_diario.sh +##### VERSÃO: 0.1 +##### DESCRIÇÃO: Implementação rotina de backup diario com arquivos modificados##### DATA DA CRIAÇÃO: 14/06/2023 +##### ATUALIZADO EM: 18/08/2023 +##### ESCRITO POR: Natan Ogliari +##### E-MAIL: natanogliari@gmail.com +##### DISTRO: Ubuntu GNU/Linux 22.04 +##### LICENÇA: MIT license +##### PROJETO: https://github.com/OgliariNatan/servidor-file-samba4 +#########################Torne o script executável ########## +## chmod +x novo_script +############################## +## Script idealizado para manter uma política de backup dos arquivos +## compartilhados no Servidor de Arquivos. +## +## A linha mais abaixo é uma maneira otimizada de backup, pois realiza +## a compactação dos arquivos compartilhados e já os coloca na pasta +## montada referente ao servidor de backup. +## +## Opção: [v] exibe o progresso, [p] mantem as permissões +echo -e "Inicializado o backup diario" $(date +%d%m%y) >> /home/servidor/samba/conf/log/log.bk_diario + +# Data de ontem +DATA=$(date -d "yesterday" '+%Y-%m-%d') + +# Criar o backup apenas dos arquivos modificados no dia anterior + +find /home/servidor/samba/data/compartilhados -type f -newermt "$DATA" -print0 | tar --null -czvf /home/servidor/samba/bk_diario/$(date -d "yesterday" +%d%m%y)_backup_diario.tar.gz --files-from=- +#Remove arquivos antigos + +echo -e "Removendo o arquivo\t" $(find /home/servidor/samba/bk_diario/ -mtime +7) >> /home/servidor/samba/conf/log/log.bk_diario + +rm $(find /home/servidor/samba/bk_diario/ -mtime +7) + + +echo -e "Finalizado o backup diario\n" >> /home/servidor/samba/conf/log/log.bk_diario +echo -e "################################" diff --git a/nddchecker.ksh b/nddchecker.ksh index 84804ec..f3b983e 100644 --- a/nddchecker.ksh +++ b/nddchecker.ksh @@ -1,3 +1,4 @@ +## #!/bin/sh # Print column header information diff --git a/network.ksh b/network.ksh index ebb3e0c..a8bb436 100644 --- a/network.ksh +++ b/network.ksh @@ -266,7 +266,7 @@ do num=$(echo $LINK | sed 's/[a-z,A-Z]//g') # Here we reference the functions above to set the variables for each port which -# will be outputed below. +# will be outputted below. # case $type in bge) Check_BGE_NIC $type $num ;; diff --git a/show_eri.sh b/show_eri.sh index 31ff0ff..8662df0 100644 --- a/show_eri.sh +++ b/show_eri.sh @@ -1,7 +1,7 @@ #!/bin/sh echo "show_hme, v1.5. Stacey Marshall, 16 April 1998" # Display HME/network parameters. -# Based on get_hme_paramters, Version 2 by Mark F 26/2/97 +# Based on get_hme_parameters, Version 2 by Mark F 26/2/97 # # # ****************************************************** @@ -44,7 +44,7 @@ get_ndd_info(){ substr(tab,length(ans),50),$1,$4)}' } -# 16/Feb/98 : 1.5: INSTANCES should be space seperated.... +# 16/Feb/98 : 1.5: INSTANCES should be space separated.... # 11/Feb/98 : 1.4: Ultra platform reports onboard hme as 'network'! # get_instances: find the instance numbers of hme cards installed. get_instances(){ @@ -182,7 +182,7 @@ for instance in $INSTANCES $ECHO "or if the interface is unused ( IE: Not plumbed in )." $ECHO "Try snooping the device to inititalise it." - $ECHO "\nLink Paremeters.\n\n" + $ECHO "\nLink Parameters.\n\n" set_instance $instance get_ndd_info link_status "The link is DOWN" "The link is UP" get_ndd_info link_speed "Speed = 10Mb/S" "Speed = 100Mb/S" diff --git a/show_hme b/show_hme index 050d995..b737b9b 100644 --- a/show_hme +++ b/show_hme @@ -1,7 +1,7 @@ #!/bin/sh echo "show_hme, v1.5. Stacey Marshall, 16 April 1998" # Display HME/network parameters. -# Based on get_hme_paramters, Version 2 by Mark F 26/2/97 +# Based on get_hme_parameters, Version 2 by Mark F 26/2/97 # # # ****************************************************** @@ -44,7 +44,7 @@ get_ndd_info(){ substr(tab,length(ans),50),$1,$4)}' } -# 16/Feb/98 : 1.5: INSTANCES should be space seperated.... +# 16/Feb/98 : 1.5: INSTANCES should be space separated.... # 11/Feb/98 : 1.4: Ultra platform reports onboard hme as 'network'! # get_instances: find the instance numbers of hme cards installed. get_instances(){ @@ -182,7 +182,7 @@ for instance in $INSTANCES $ECHO "or if the interface is unused ( IE: Not plumbed in )." $ECHO "Try snooping the device to inititalise it." - $ECHO "\nLink Paremeters.\n\n" + $ECHO "\nLink Parameters.\n\n" set_instance $instance get_ndd_info link_status "The link is DOWN" "The link is UP" get_ndd_info link_speed "Speed = 10Mb/S" "Speed = 100Mb/S" diff --git a/users_no_password.sh b/users_no_password.sh index 0134824..e8110a6 100644 --- a/users_no_password.sh +++ b/users_no_password.sh @@ -10,16 +10,26 @@ # Description : This will show all OS accounts that don't have a password set. -if [[ `uname -s` == 'Linux' ]]; then - nopass=`passwd -Sa | grep NP | awk '{print $1}'` -elif [[ `uname -s` == 'SunOS' ]]; then - nopass=`passwd -sa | grep NP | awk '{print $1}'` -fi +get_user_names(){ + nopass=`passwd -${1}a | grep -o "^.* NP"` + + for i in ${nopass/ /_} + { + nopassnames="${nopassnames:- } $i" + } +} - if [ -z "$nopass" ] - then - echo "Good - All user accounts have a password" - else - echo "Not Good - $nopass has no password set" - fi +if [[ "$OSTYPE" == *linux-gnu* ]]; then + get_user_names S +elif [[ "$OSTYPE" == *sunos* ]]; then + get_user_names s +fi +if [ -z "$nopassnames" ] + then + echo "Good - All user accounts have a password." + else + echo "ERROR: The users listed below have no password set:"\ + " ${nopassnames//_NP/}" 1>&2 + exit 1 +fi diff --git a/world_writable.ksh b/world_writable.ksh index a1059d1..9797dd0 100644 --- a/world_writable.ksh +++ b/world_writable.ksh @@ -3,7 +3,7 @@ # Script Name : world_writable.ksh # Author : Craig Richards # Created : 28-November-2007 -# Last Modified : 28 Janurary 2008 +# Last Modified : 28 January 2008 # Version : 1.1 # Modifications : 28th-Jan-2008 - CR - Added the function to check the user ROOT is running the program