![]() |
# stampa la lunghezza, in caratteri, dei file di tipo testo specificati sulla linea comando |
while ($#argv>0)
if ({( file $argv[1] | grep -s text)}) thenwc -c $argv[1]
endif
shift
end
![]() |
# stampa la lunghezza, in caratteri, dei file di tipo testo presenti nella directory corrente |
set lista=`ls`
foreach F ($lista)
if ( { ( file $F | grep -s text) } ) thenwc -c $F
endif
end
![]() |
# manda un messaggio agli utenti collegati diversi dal mittente |
set userlist=`who | awk {print $1}`
foreach person ($userlist)if ($person != $user) then
write $person < msgfile.txt
endif
end
![]() |
# permette di selezionare diverse operazioni |
while (1)
echo "Menù"
echo "1- stampa directory corrente"
echo "2- elenca i file della working directory"
echo "3- stampa informazioni su un file"
echo "4- exit"
echo -n "\n\nScegli: "
set ans=`head -1`
switch ($ans)
case 1:pwd
breakswcase 2:
ls
breakswcase 3:
echo -n "Nome del file : "
set fname=$<
ls -l $fname
breakswcase 4:
exit 0
default:
echo "Scelta errata"
endsw
end
![]() |
# Crea una mailing list |
if (-e /var/adm/sendmail/alpnet) rm /var/adm/sendmail/alpnet
foreach I ( ` grep alpnet /etc/passwd |awk -F: '{print $1}'`)
set NOME=${I}
echo $NOME >> /var/adm/sendmail/alpnet
endif
end
echo root >> /var/adm/sendmail/alpnet
![]() |
# Conta quante persone sono memorizzate nei file elenco* |
@ tot = 0
foreach F (`ls elenco*`)@ linee =` wc l $F| awk {print $1}`
@ tot += $tot + $lineeend
echo $tot
![]() |
# Preleva da un file sottostringhe a lunghezza fissa e le memorizza in un file. Ad esempio, se la linea del file di input contiene la stringa 15Mar1982, nel file di output sarà memorizzato 15 Mar 1982 |
if ($#argv != 2) then
echo "Uso: preleva inputfile outputfile"
else
if (-e $argv[2]) rm $argv[2]
if (! -e $argv[1]) thenecho "$argv[1] non esiste!"
else
cat $argv[1] | awk '{print substr($1,1,2), substr($1,3,3), substr($1,6,4)}'>> argv[2]
endif
endif
![]() |
#Ricerca sequenziale |
set classi=(3AI 4AI 5AI 3BI 4BI 5BI)
set num=(26 20 18 27 22 17)
@ I = 0
set classe=`head -1`
set trovato = "false"
while ( $I < 6 && $trovato == "false")
if ( $classi[$I] == $classe) thenset trovato = "true"
set pos = $Ielse
@ I++
endif
end
if( $trovato == "true") echo "La classe $classe ha $num[$pos] studenti"
![]() |
# Dato un tempo espresso in secondi lo converte in hh:mm:ss |
echo n "Inserisci il tempo: "
set TOT=`head -1`
if ($TOT > 0) then@ MM = $TOT / 60
@ SEC = $TOT % 60
@ ORE = $MM / 60
@ MIN= $MM % 60
echo "$ORE:$MIN:$SEC"
endif
![]() |
# Copia i file di /usr/skel nella home directory dellutente specificato |
set UTENTE=$1
set PAT=`grep -w ${UTENTE} /etc/passwd | awk -F: '{print $6}'`
set GROUP=`grep -w ${UTENTE} /etc/passwd | awk -F: '{print $4}'`
echo $UTENTE $PAT $GROUP
foreach I ( `find /usr/skel -type f -print`)set FILE=`basename ${I}`
if ( -e $PAT/$FILE ) thenecho "${PAT}/${FILE} esiste."
else
echo "${PAT}/${FILE} copiato."
cp ${I} "${PAT}/${FILE}"
chmod 0751 "${PAT}/${FILE}"
chown "${UTENTE}" "${PAT}/${FILE}"
chgrp "${GROUP}" "${PAT}/${FILE}"endif
end
![]() |
# Configura lutente specificato per secure ftp |
if ($#argv == 0) then
echo "Specificare username"
else
set USER=`grep "^$argv[1]:" /etc/passwd | awk -F: '{print $1}'`
set UID=`grep "^$argv[1]:" /etc/passwd | awk -F: '{print $3}'`
set GID=`grep "^$argv[1]:" /etc/passwd | awk -F: '{print $4}'`
set HOME=`grep "^$argv[1]:" /etc/passwd | awk -F: '{print $6}'`
set GNAME=`grep $GID /etc/group | awk -F: '{print $1}'`
echo $USER $UID $GID $HOME $GNAME
chmod 755 $HOME
cd $HOME
if (! -e bin) mkdir bin
if (! -e etc ) mkdir etc
chown root.daemon bin etc
chmod 111 bin etc
cp /sbin/ls bin
chown root.bin bin/ls
chmod 111 bin/ls
echo "root:*:0:0::/:/bin/false" > etc/passwd
echo $USER":*:"$UID":"$GID":"$HOME"/./:/bin/false" >> etc/passwd
echo root::0:root > etc/group
echo $GNAME"::"$GID":"$USER >> etc/group
chown root.daemon etc/passwd etc/group
chmod 444 etc/passwd etc/group
touch .rhosts .forward
chown root.system .rhosts .forward
chmod 400 .rhosts .forward
endif
![]() |
#Comprime e rinomina i file *.log la cui dimensione è > di 7000000 bite |
cd /usr/var/spool/mqueue
foreach F(`ls *.log`)set DIMENSIONE=`ls -l $F| awk '{print $5}'`
if($DIMENSIONE > 7000000) thencp $F /rz73/logs ; cp /dev/null $F
cd /rz73/logs
/usr/local/bin/gzip $F
set FILE=$F_`/bin/date +"%y%m%d"`.gz
mv $F.gz $FILE
echo "Compresso il file $FILE"endif
end
![]() |
# Implementa la ricerca e lordinamento su un archivio memorizzato in un file di testo. i record contengono: nome indirizzo comune telefono |
while (1)
echo "Menù"
echo "1- ricerca dato un nome"
echo "2- ricerca tutti quelli che risiedono in un dato comune"
echo "3- ordina per nome"
echo "4- ordina per comune"
echo "5- visualizza lelenco dei comuni senza ripetizioni"
echo "6- exit"
echo -n "\n\nScegli: "
set ans=`head -1`
switch ($ans)
case 1:echo -n "Inserisci il nome: "
set nome=`head -1`
grep "\<$nome\>" $argv[1]
breakswcase 2:
echo -n "Inserisci il nome del comune: "
set comune=`head -1`
grep "\<$comune\>" $argv[1]
breaksw
case 3:
sort +0 1 $argv[1] | more
breaksw
case 4:
sort +2 3 $argv[1] | more
breaksw
case 5:
cat $argv[1]| awk {print $3} | sort u | more
breaksw
case 6:
exit 0
default:
echo "Scelta errata"
endsw
end