#!/bin/bash
echo "Скрипт необходимо запускать из папки, где расположены папки client_request upstream_request upstream_response client_response или их tmp_ версии"
echo "Enter код log файла"
read logname
echo "Введите название папок с логами. Если просто папки, то нажмите enter. Если папки начинаются с tmp_ - введите tmp_ и нажмите enter"
read foldername
sudo id
#sudo touch $logname.export
#sudo chmod 777 $logname.export

echo "client_request:"  >> ~/$logname.export
echo ""  >> ~/$logname.export

if sudo [ -f "$foldername"client_request/$logname.log ]; then
  sudo cat "$foldername"client_request/$logname.log >> ~/$logname.export
else
  echo ""$foldername"client_request/$logname.log: No such file or directory" >> ~/$logname.export
fi

echo ""  >> ~/$logname.export
echo "upstream_request:"  >> ~/$logname.export
echo ""  >> ~/$logname.export

if sudo [ -f "$foldername"upstream_request/$logname.log ]; then
  sudo cat "$foldername"upstream_request/$logname.log >> ~/$logname.export
else
  echo ""$foldername"upstream_request/$logname.log: No such file or directory" >> ~/$logname.export
fi

echo ""  >> ~/$logname.export
echo "upstream_response:"  >> ~/$logname.export
echo ""  >> ~/$logname.export


if sudo [ -f "$foldername"upstream_response/$logname.log ]; then
  sudo cat "$foldername"upstream_response/$logname.log >> ~/$logname.export
else
  echo ""$foldername"upstream_response/$logname.log: No such file or directory" >> ~/$logname.export
fi

echo ""  >> ~/$logname.export
echo "client_response:"  >> ~/$logname.export
echo ""  >> ~/$logname.export

if sudo [ -f "$foldername"client_response/$logname.log ]; then
  sudo cat "$foldername"client_response/$logname.log >> ~/$logname.export
else
  echo ""$foldername"client_response/$logname.log: No such file or directory" >> ~/$logname.export
fi

