Beruflich Dokumente
Kultur Dokumente
1
//////////////////////////////////////////////////
#!/bin/bash
a=$1
b=$2
if [[ "$a" = "$b" ]]
fi
//////////////////////////////////////////////////
LAB 1.2
//////////////////////////////////////////////////
#!/bin/bash
a=$1
b=$2
c=$3
then a=$b
fi
then a=$c
fi
echo "$a"
//////////////////////////////////////////////////
LAB 1.3
//////////////////////////////////////////////////
#!/bin/bash
b=""
read a
b="$b$a"
do
read a
b="$b$a"
if [[ "$a" == "q" ]]
then break
fi
done
echo "$b"
//////////////////////////////////////////////////
LAB 1.4
//////////////////////////////////////////////////
#!/bin/bash
count=1
read a
while [[ "$a"%2 != 0 ]]
do read a
let count=$count+1
let m=$a%2
if [[ "$m" == "0" ]]
then break
fi
done
echo "$count"
//////////////////////////////////////////////////
LAB 1.5
//////////////////////////////////////////////////
#!/bin/bash
read a
case $a in
1 )
/usr/bin/nano
;;
2 )
/usr/bin/vim
;;
3 )
/usr/bin/links
;;
4 )
echo "Goodbye"
exit 0
;;
esac
//////////////////////////////////////////////////
LAB 1.6
//////////////////////////////////////////////////
#!/bin/bash
if [[ "$HOME" == "$PWD" ]]
exit 0
fi
if [[ "$HOME" != "$PWD" ]]
exit 1
fi
//////////////////////////////////////////////////
LAB 2.1
//////////////////////////////////////////////////
#!/bin/bash
inf="\\(II\\)"
war="\\(WW\\)"
mail="[a-zA-Z0-9_.]+@[a-zA-Z0-9_]+(\\.[a-zA-Z]+)+"
p="*.bash"
cat /var/log/*.log | wc –l
//////////////////////////////////////////////////
LAB 2.7
//////////////////////////////////////////////////
#!/bin/bash
ps -Ao pid,stime | tail -n +2 | sort -r -k2 | head -9 | sort -k2 | head -1 | awk
'{print $1}'
//////////////////////////////////////////////////
LAB 3.3
//////////////////////////////////////////////////
#!/bin/bash
for i in $(ls /proc/ | grep "[0-9]\+")
do
done
//////////////////////////////////////////////////
LAB 3.4
//////////////////////////////////////////////////
#!/bin/bash
status=""
do
file="/proc/"$pid"/status"
file1="/proc/"$pid"/sched"
if [[ -z $sleepavg ]]
then sleepavg=0
fi
if [[ $ppid != "" ]]
fi
done
ppid=0
sleepavg=0
count=0
b=""
while read a
do
if [[ -n $a ]]
then
if [[ $ppid == $newppid ]]
else
if [[ -n $b ]]
then
b=$b"Average_Sleeping_Children_of_ParentID="$ppid" is "$sleepavg$'\n'
fi
sleepavg=$newsleepavg
ppid=$newppid
count=1
fi
b=$b$a$'\n'
fi
if [[ -n $b ]]
then
b=$b"Average_Sleeping_Children_of_ParentID="$ppid" is "$sleepavg$'\n'
fi
echo "$b" > ans6.tmp
//////////////////////////////////////////////////
LAB 4.1
//////////////////////////////////////////////////
#!/bin/bash
d=$(date '+%d.%m.%y_%H:%M:%S')
mkdir ~/test && echo "catalog test was created successfully" >> ~/report.tmp &&
touch ~/test/$d.tmp
at now+2minutes -f ./script1.bash
tail -n 0 -f ~/report.tmp
//////////////////////////////////////////////////
LAB 4.3
//////////////////////////////////////////////////
#!/bin/bash
nice -n 6 ./script4dop.bash&
nice -n 0 ./script4dop.bash&
#!/bin/bash
x=0
while true;
do
let x=$x+1
done
//////////////////////////////////////////////////
LAB 4.5
//////////////////////////////////////////////////
#!/bin/bash
while true
do
read line
if [[ $line == "QUIT" ]]
then
exit
fi
if [[ $line != '*' ]]
fi
done
Дополнительный файл:
#!/bin/bash
result=1
operate='+'
do
read line
case $line in
'+')
operate='+'
;;
M)
operate='*'
;;
[0-9]*)
if [[ $operate == '+' ]]
then
let result=$result+$line
else
let result=$result\*$line
fi
;;
*)
echo "Error!"
;;
esac
done
//////////////////////////////////////////////////
LAB 4.6
//////////////////////////////////////////////////
#!/bin/bash
./script6dop.bash&
while true
do
read line
case $line in
"term")
exit
;;
esac
done
Дополнительный файл:
#!/bin/bash
echo "RUNNING"
i=0
exiting='0'
sigterm()
exiting='1'
while true
do
case $exiting in
0)
echo $i
let i=$i+1
;;
1)
echo "STOP"
exit
;;
esac
sleep 1
done
//////////////////////////////////////////////////
LAB 4.7
//////////////////////////////////////////////////
#!/bin/bash
./script7dop.bash&
while true
do
read line
case $line in
"term")
kill -SIGTERM $(cat mypid)
exit
;;
"+")
;;
"*")
;;
esac
done
Дополнительный файл:
#!/bin/bash
i=1
mode="+"
sigterm()
echo "STOP"
exit
user1()
mode="+"
user2()
mode="*"
while true
do
case $mode in
"+")
let i=$i+2
;;
"*")
let i=$i*2
;;
esac
echo $i
sleep 1
done
//////////////////////////////////////////////////
LAB 5.1
//////////////////////////////////////////////////
#!/bin/bash
scriptName=$1
homeTrash=$HOME/.trash
homeLog=$HOME/trash.log
if [ $# -ne 1 ]; then
exit 1
fi
if [ -d $homeTrash ]; then :
else
mkdir $homeTrash
fi
currentTrashFile=$(date +%s)
ln $scriptName "$homeTrash/$currentTrashFile"
rm $scriptName
if [ -e $homeLog ];
then :
else
touch $homeLog
fi
restFile=/home/user/panyavin/lab5/$1
do
if [[ $restFile == $glPath ]]
then
rmFile=$HOME/.trash/$trFile
if [ $# -ne 1 ]; then
exit 1
fi
if [ -e $rmFile ];
then
read answer
if [[ $answer == "yes" ]]
then
if [ -d $(dirname $glPath) ]
then
if [[ -e $glPath ]]
then
read newName
else
ln $rmFile $glPath
fi
else
ln $rmFile $HOME/$1
fi
rm $rmFile
mv $HOME/trash0.log $HOME/trash.log
fi
fi
fi
done
//////////////////////////////////////////////////
LAB 5.3
//////////////////////////////////////////////////
#!/bin/bash
backupParentDir="$HOME/"
sourceDir="$HOME/source/"
todayDate=$(date "+%F")
dircreated=0
backupPrefix="Backup-"
backupReport="$HOME/backup-report"
let dateDiff=($todaySec\-$lastbackupSec)/60/60/24
if [ "$dateDiff" -le 7 ]
then
currentbackupDir=$backupParentDir$lastbackupDir"/"
else
mkdir $backupParentDir$backupPrefix$todayDate
currentbackupDir=$backupParentDir$backupPrefix$todayDate"/"
dircreated=1
fi
if [ "$dircreated" == "1" ]
then
echo "backup created on "$todayDate" in directory "$sourceDir" Files copied :" >>
$backupReport
do
cp $sourceDir$file $currentbackDir$file
done
else
do
currentfile=$currentbackupDir$file
if [ -f currentfile ];
then
mv $currentfile $currentfile"."$todayDate
cp $sourceDir$file $currentfile
echo "New version of file "$file" found. Old version moved to "$file.$todayDate""
>> $backupReport
fi
else
cp $sourceDir$file $currentfile
fi
done
fi
exit 1
//////////////////////////////////////////////////
LAB 5.4
//////////////////////////////////////////////////
#!/bin/bash
backupParentDir="$HOME/"
restoreDir="$HOME/restore/"
backupPrefix="Backup-"
if [[ ! -d "$restoreDir" ]];
then
mkdir $restoreDir
fi
do
then
then
cp $latestBackup$file $restoreDir$file
fi
fi
done
exit 1