Answer the question
In order to leave comments, you need to log in
How to pull out the last 10 characters in a string?
There is a line like this
drwxr-xr-x 1 8000027 8000027 0 Nov 28 16:37 2017-11-28
Need to pull out the last 10 characters from it - 2017-11-28
Answer the question
In order to leave comments, you need to log in
STRING="drwxr-xr-x 1 8000027 8000027 0 Nov 28 16:37 2017-11-28"
LAST10="${STRING: -10:10}"
echo drwxr-xr-x 1 8000027 8000027 0 Nov 28 16:37 2017-11-28 | awk '{print $9}'
Thank you all for your help, I added that script. I used lftp (and it emulates some bash functions, but I can make a mistake in the terminology)
I had to emulate the ftp server into a folder and pull out everything I need with a normal bash
. And about the crookedness of writing. I can make a jump, after all, this is my first bash script)))))
echo -en "\n${GREEN}Начало импорта...${NORMAL}\n\n"
CURRENT_DIR=`pwd`
function importDumpFileToVagrant {
cd ${CURRENT_DIR}
pwd
echo ${DUMP_FILE_NAME}
if
then
pv ${CURRENT_DIR}/${DUMP_FILE_NAME} | mysql -h${MYSQL_HOST} -P${MYSQL_PORT} -D${MYSQL_DB_NAME} -u${MYSQL_USER} -p${MYSQL_PASS}
rm ${DUMP_FILE_NAME}
echo -en "${GREEN}Импортирование прошло успешно! =(${NORMAL}\n";
else
echo -en "${RED}Файл дампа БД не найден! =(${NORMAL}\n";
fi
}
echo -en "${YELLOW}Создаем дамп на сервере...${NORMAL}\n"
ssh ${SSH_LOGIN}@${SSH_HOST} 'bash /var/www/hlamada.ru/server/backup.sh -m db'
echo -en "${GREEN}Дамп успешно создан и отправлен на FTP сервер...${NORMAL}\n"
echo -en "${YELLOW}Мотируем FTP как диск в папку '${PATH_TO_MOUNT}' ${NORMAL}\n"
fusermount -u ${PATH_TO_MOUNT}
curlftpfs ${FTP_LOGIN}:${FTP_PASS}@${FTP_HOST} ${PATH_TO_MOUNT}
echo -en "${GREEN}Монтирование прошло успешно! '${CYAN}${PATH_TO_MOUNT}${NORMAL}' \n"
cd ${PATH_TO_MOUNT}/hlamada.ru/
DIR_NAME=`ls | tail -1`
cd ${DIR_NAME}
FILE_NAME=`ls | tail -1`
echo -en "${YELLOW}Распаковка дампа...${NORMAL}\n"
tar -xvzf ${PATH_TO_MOUNT}/hlamada.ru/${DIR_NAME}/${FILE_NAME} -C ${CURRENT_DIR}
echo -en "\n${GREEN}Распаковка дампа прошла успешно!\nНаходится в '${CYAN}${CURRENT_DIR}/${DUMP_FILE_NAME}${YELLOW}'${NORMAL}\n"
importDumpFileToVagrant
echo -en "\n${GREEN}Конец импорта!\n\n"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question