Moje skrypty w Unix:



#!/bin/sh
echo "Hello World"

#!/bin/sh
tmp_dir=/tmp
echo "Variable tmp_dir contains: $tmp_dir"

#!/bin/sh
today=`date`
identity=`whoami`
machine=`hostname`
echo "Hello, today is $today. I am logged as $identity on machine $machine"

#!/bin/sh
echo "\t\tCURRENT USER INFORMATION\n"
echo "My UNIX username is: `whoami`"
echo "My UNIX machine name is: `hostname`"
echo "My current directory is: `pwd`"
echo "Pograms I am currently running: \n `ps -ef | grep $identity`"

#!/bin/sh
echo "please enter a username: \c"
read username
echo "\n\t\tCURRENT USER INFORMATION\n"
programs="`ps -ef | grep $username`"   
echo "User $username is running the following programs : \n\n$programs"

#!/bin/sh
echo "Please enter your name :"
read name
if [ "$name" = pawel ]
then
echo "czesc pawel"
else
echo "nie znam cie"
fi

#!/bin/sh
if ps -ef | grep "vi$" > /dev/null 2>&1
then
echo "Yep, someone is running vi"
else
echo "No one is running vi at this time"
fi

#!/bin/sh
echo "Of which file am I supposed to do a duplicate :"
read file
( cp ${file} ${file}.dup 2> /dev/null && cp /dev/null ${file} ) || echo "Could not copy ${file} to ${file}.dup"

#!/bin/sh
# przelicza kb na mb
diskspace_kb=1808071
diskspace_mb=`echo "scale=2; $discspace_kb / 1024" | bc`
echo $diskspace_mb

#!/bin/sh
echo jakie dwie liczby dodac :
read l1 l2
echo "suma tych liczb `expr $l1 + $l2`"

#!/bin/sh
if [ "$#" -ne 1 ]
then
echo "This script wants 1 argument"
exit
else
nl $1 > /tmp/nm$$
cat /tmp/nm$$
fi

#!/bin/sh
if [ "$#" -eq 0 ]
then
echo "This script takes at least one argument"
exit
fi
listing="`ls -l $* 2> /dev/null`"
echo "$listing"

#!/bin/sh
if [ "$#" -eq 0 ]
then
echo "Usage: $0 filename ..."
echo "Please enter filname(s) to be removed"
exit 1
fi
rm $*

#!/bin/sh
for arg in $*
do 
echo $arg
done

#!/bin/sh
if [ "$#" -eq 0 ]
then
echo "This command requires at least one argument"
echo "$0 filename-to-compress ..."
exit 1
fi
for file in $*
do
if [ -f "$file" ]
then
echo "Compressing file $file now"
compress $file
else
echo "Sorry, filename $file does not exist"
fi
done

#!/bin/sh
if [ "$#" -eq 0 ]
then
echo "This command requires at least one argument"
echo "$0 direcory_containing_files_to_compress ..."
exit 1
fi
for dir in $*
do
if [ ! -d "$dir" ]
then
echo "Sorrt, directory $dir does not exist"
exit 1
fi
for file in `ls $dir`
do
if [ -d "$file" ]
then
echo "This is direcory"
else
echo "compressing $file now"
compress $file
fi
done
done

#!/bin/sh
echo "What would you like to do:
1.        Compress a file
2.        Do a long listing of a file
3.        Delete a file
Please select one of above (1-3): \c"
read select
case "$select" in
1) echo "Enter filename to compress: \c"
   read file
   if [ -f "$file" ]
   then
   compress $file
   else "Bad filename"
   fi;;
2) echo "Enter filename to list: \c"
   read file
   if [ -f "$file" ]
   then
   ls -l $file
   else
   echo "Bad filename"
   fi;;
3) echo "Enter filename to delate: \c"
   read file
   if [ -f "$file" ]
   then
   rm $file
   else
   echo "Bad filename"
   fi;;
*) echo "Incorrect input data";;
esac

#!/bin/sh
#Give attributes of file
echo "Which file do you want to check"
read f
if ls -l $f | grep "^.r........" > /dev/null
then
ur=yes
else
ur=no
fi
if ls -l $f | grep "^..w......." > /dev/null
then
uw=yes
else
uw=no
fi
if ls -l $f | grep "^...x......" > /dev/null
then
ux=yes
else
ux=no
fi
if ls -l $f | grep "^....r....." > /dev/null
then
gr=yes
else
gr=no
fi
if ls -l $f | grep "^.....w...." > /dev/null
then
gw=yes
else
gw=no
fi
if ls -l $f | grep "^......x..." > /dev/null
then
gx=yes
else
gx=no
fi
if ls -l $f | grep "^.......r.." > /dev/null
then
or=yes
else
or=no
fi
if ls -l $f | grep "^........w." > /dev/null
then 
ow=yes
else
ow=no
fi
if ls -l $f | grep "^.........x" > /dev/null
then
ox=yes
else
ox=no
fi
echo "---------------------------------------"
echo "|             | USER | GROUP | OTHERS |"                 
echo "| Readable    |  $ur |  $gr  |  $or   |"     
echo "|             |      |       |        |"
echo "| Writeable   |  $uw |  $gw  |  $ow   |"    
echo "|             |      |       |        |"
echo "| Executeable |  $ux |  $gx  |  $ox   |"       
echo "|_____________|______|_______|________|" 


#!/bin/sh
#oblicza silnie z parametru
if [ "$#" -ne 1 ]
then
echo "Usage: $0 liczba_z_ktorej_ma_byc_wyliczona_silnia"
exit 1
fi
i=1
m=1
while [ "$i" -le "$1" ]
do
m=`expr $m \* $i`
i=`expr $i + 1`
done
echo "Silnia z parametru = $m"


#!/bin/sh
#ustawia parametry w odwrotnej kolejnosci
l=1
for i in $*
do
let w$l=$i
l=`expr $l + 1`
done
l=`expr $l - 1`
for i in $*
do
echo "$w$l" #nie wiem jak tu powinno byc naprawde
l=`expr $l - 1`
done