Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Лаба_9_Операционные_Системы_ПДФ

.docx
Скачиваний:
0
Добавлен:
14.12.2022
Размер:
34.22 Кб
Скачать

Министерство цифрового развития, связи и массовых коммуникаций Российской Федерации

Ордена Трудового Красного Знамени федеральное государственное бюджетное образовательное учреждение высшего образования

«Московский технический университет связи и информатики»

(МТУСИ)

Кафедра «Математическая кибернетика и информационные технологии»

Лабораторная работа

на тему

«Создание и выполнение командных файлов в ОС UNIX»

Выполнил:

Студент 1 курса магистратуры

Группы М092201(75)

Францев Артем

Проверил:

Симонов Сергей Евгеньевич

Москва 2022

  1. Вариант №9

Вариант 9

1

3

7

16

18

  1. Задача 1

if [ $# -eq 0 ]; then

echo "Error: no arguments provided"

exit 1

fi

# Print the arguments, along with their corresponding argument number

for ((i = 1; i <= $#; i++)); do

echo "$i: $1"

shift

done

  1. Задача 3

ls -rt $HOME > home_files.txt

# Print the list of files

echo "List of files in home directory:"

cat home_files.txt

# Print the total number of files

num_files=$(wc -l < home_files.txt)

echo "Total number of files: $num_files"

  1. Задача 7

bash

#!/bin/bash

# Prompt the user for a directory name

read -p "Enter directory name: " dir_name

# Save the current directory so we can return to it later

orig_dir=$(pwd)

# Move to the specified directory

cd $dir_name

# Create a file with a listing of the directory

ls > directory_listing.txt

# Return to the original directory

cd $orig_dir

  1. Задача 16

bash

#!/bin/bash

# Define the time to create the directory (in 24-hour format)

target_time="12:00"

while true; do

# Get the current time

curr_time=$(date +"%T")

# Check if the current time matches the target time

if [ "$curr_time" = "$target_time" ]; then

# Create the directory

mkdir "directory_$curr_time"

# Print a message indicating that the directory was created

echo "Directory created at $curr_time"

fi

# Sleep for 1 second before checking the time again

sleep 1

done

  1. Задача 18

if [ $# -ne 2 ]; then

echo "Usage: $0 <key> <value>"

exit 1

fi

key=$1

value=$2

# Read the phone book file and split each line into its fields

while IFS=$'\t' read -r last_name address phone_number; do

# Search for a record that matches the given search key and value

case $key in

last_name)

if [ $last_name == $value ]; then

# Print the values of the other two fields

echo "address: $address"

echo "phone_number: $phone_number"

break

fi

;;

address)

if [ $address == $value ]; then

# Print the values of the other two fields

echo "last_name: $last_name"

echo "phone_number: $phone_number"

break

fi

;;

phone_number)

if [ $phone_number == $value ]; then

# Print the values of the other two fields

echo "last_name: $last_name"

echo "address: $address"

break

fi

;;

esac

done <phonebook.txt