Script per Cygwin

Ecco alcuni semplici script per l’ambiente di Cygwin: conversione dei file di testo da Unix a DOS (e viceversa), menu per lancio comandi e infine una ricerca testi all’interno delle diverse directory.

 

Convertire un file testo, in formato DOS

#!/bin/sh
#
# convtodos.sh - converte un file testo, in formato DOS
# -------------------------
# When - Who - What
# 03.11.2017 - m.rossolato - creates

if [ "$1" == "" ] ;
then
echo -e "\nusage: convtodos.sh [source] [destination]"
exit
fi
sed 's/$'"/`echo \\\r`/" $1 > $2
echo -e "\nDone: $1 converted to DOS with name $2."
echo "have a nice day!"

 

Convertire un file testo, in formato UNIX

#!/bin/sh
#
# convtounix.sh - converte un file testo, in formato UNIX
# -------------------------
# When - Who - What
# 03.11.2017 - m.rossolato - creates

if [ "$1" == "" ] ;
then
 echo -e "\nusage: convtounix.sh [source] [destination]"
 exit
fi


sed -e 's/.$//g' $1 > $2
echo -e "\nDone: $1 converted to UNIX with name $2."
echo "have a nice day!"

 

Menu script per shell (BASH)

#!/bin/sh
#
# fire.sh - menu script per shell (bash)
# -------------------------
# When - Who - What
# 03.11.2017 - m.rossolato - creates

PS3='Please enter your choice: '
options=("MIODB1-SVIL" "MIODB1-TEST" "MIODB1-PROD" "MIODB2-SVIL" "MIOWPR1-TEST" "Quit")
select opt in "${options[@]}"
do
 case $opt in
 "MIODB1-SVIL")
 cd /home/utente/oper
 sqlplus dbuser/userpass@servizio
 ;;
 "MIODB1-TEST")
 cd /home/utente/oper
 sqlplus dbuser/userpass@servizio
 ;;

 "MIODB1-PROD")
 cd /home/utente/oper
 sqlplus dbuser/userpass@servizio
 ;;
 "MIODB2-SVIL")
 cd /home/utente/oper
 sqlplus dbuser/userpass@servizio
 ;;

 "MIOWPR1-TEST")
 cd /home/utente/wordpress
 sudo ./ctlscript.sh start
 ;;
 "Quit")
 break
 ;;
 *) echo invalid option;;
 esac
done

Ricerca stringhe nei file

#!/bin/sh
#
# cercastr.sh - cerca sottostringa nel percorso
# -------------------------
# WHEN - WHO - WHAT
# 03.11.2017 - m.rossolato - creates

if [ "$1" == "" ] ;
then
        echo "usage: cercastr.sh [filename] [string]"
        exit
fi

mfname=${1}
mstr=${2}
echo "${mstr} ${mfname}"
# find . -name "${mfname}" -exec grep -i "${mstr}" {} \; 2>/dev/nul
find . -name "${mfname}" -exec grep -il "${mstr}" {} \;  >miolist.txt

for mfile in `cat miolist.txt`; do
        echo "FOUND ON $mfile *******************************"
        grep -i ${mstr} "$mfile";

done