31

кстати, если вы желаете использовать лексикографическое сравнение строк в текущей локали, то вы можете воспользоваться средствами самого bash'а, а именно [[двойной квадратной скобкой]] :

+ открыть спойлер

[[ expression ]]
              Return  a  status  of  0 or 1 depending on the evaluation of the conditional expression expression.
              Expressions are composed of the primaries described  below  under  CONDITIONAL  EXPRESSIONS.   Word
              splitting and pathname expansion are not performed on the words between the [[ and ]]; tilde expan‐
              sion, parameter and variable expansion, arithmetic expansion, command substitution, process substi‐
              tution,  and  quote removal are performed.  Conditional operators such as -f must be unquoted to be
              recognized as primaries.

              When used with [[, The < and > operators sort lexicographically using the current locale.

              When the == and != operators are used, the string to the right of the operator is considered a pat‐
              tern  and  matched  according  to  the  rules described below under Pattern Matching.  If the shell
              option nocasematch is enabled, the match is performed without regard  to  the  case  of  alphabetic
              characters.   The  return value is 0 if the string matches (==) or does not match (!=) the pattern,
              and 1 otherwise.  Any part of the pattern may be quoted to force it to be matched as a string.

              An additional binary operator, =~, is available, with the same precedence as == and !=.  When it is
              used,  the  string  to  the  right of the operator is considered an extended regular expression and
              matched accordingly (as in regex(3)).  The return value is 0 if the string matches the pattern, and
              1  otherwise.   If  the regular expression is syntactically incorrect, the conditional expression's
              return value is 2.  If the shell option nocasematch is enabled,  the  match  is  performed  without
              regard  to the case of alphabetic characters.  Any part of the pattern may be quoted to force it to
              be matched as a string.  Substrings matched by  parenthesized  subexpressions  within  the  regular
              expression  are saved in the array variable BASH_REMATCH.  The element of BASH_REMATCH with index 0
              is the portion of the string matching the entire regular expression.  The element  of  BASH_REMATCH
              with index n is the portion of the string matching the nth parenthesized subexpression.

              Expressions  may  be  combined  using the following operators, listed in decreasing order of prece‐
              dence:

              ( expression )
                     Returns the value of expression.  This may be used to  override  the  normal  precedence  of
                     operators.
              ! expression
                     True if expression is false.
              expression1 && expression2
                     True if both expression1 and expression2 are true.
              expression1 || expression2
                     True if either expression1 or expression2 is true.

              The  &&  and  || operators do not evaluate expression2 if the value of expression1 is sufficient to
              determine the return value of the entire conditional expression.

Карусель разнесло по цепочке за час
Всех известий — конец
Да, весна началась!
(всё к лицу подлецу, как родному отцу, не рассказывай, батя, и так всё пройдёт)

32 (10.03.2011 16:58:20 отредактировано Kettler)

Пока чего ток смог добиться рабочего  smile

#!/bin/bash

SOURCE_BACKUP_DIR="/share/video/"
BACKUP_DIR_VIDEO="/share/backup/video/"
LOG_FILE="/var/log/backup_video.log"
SIZE_MAX_BACKUP="10000"
SIZE_MAX_VIDEO="1000"

rm $SOURCE_BACKUP_DIR*.jpg

size_backup=`du -shm $BACKUP_DIR_VIDEO`
size_video=`du -shm $SOURCE_BACKUP_DIR`

date=`date "+%Y-%m-%d"`

ls -t $SOURCE_BACKUP_DIR | sed '1d;$d' | tee file_list
ls -t $BACKUP_DIR_VIDEO | sed '1d;$d' | tee file_tar

size_b=${size_backup%%/*/}
size_v=${size_video%%/*/}

echo $size_b
echo $size_v

while read file_name
        do echo $SOURCE_BACKUP_DIR"$file_name" >> file_name_dir
done < file_list

if [ $size_v -ge $SIZE_MAX_VIDEO ]
then
        while read file_name;
        do rm "$file_name";
        done < file_name_dir
fi

if [ $size_b -ge $SIZE_MAX_BACKUP ]
        then
        while read file_name;
        do rm $BACKUP_DIR_VIDEO"$file_name";
        done < file_tar
        tar -cvvf $BACKUP_DIR_VIDEO"$date".tar -T file_name_dir
        echo "`$date` Архив создан..." >> $LOG_FILE;
        else
        tar -cvvf $BACKUP_DIR_VIDEO"$date".tar -T file_name_dir
        echo "`$date` Архив создан..." >> $LOG_FILE;
        fi
rm file_list file_name_dir file_tar

Вроде ни чё так) Спасибо DrBatty за правильное направление это мой первый опыт с bash

Ищу дополнительный заработок (удалёнка).
Пьянка без секса – признак алкоголизма.

33

Осталось ток перед удалением архивов всё паковать и переносить в сеть ток после удалять всё (ну это мелочь).

Ищу дополнительный заработок (удалёнка).
Пьянка без секса – признак алкоголизма.

34 (23.04.2011 15:03:33 отредактировано XliN)

По рекомендации доктора мой скрипт стал еще меньше )) Но еще не до конца доделан. Надо разобраться с шифрованием и кодами ошибок

Как то так:

#!/bin/bash
SOURCE_DATABASE="/home/parus/Data/"
BACKUP_DATABASE="/home/parus/backup/"
COPY_DIR="/home/parus/mirror/"
log_file="/var/log/parus_new_script.log"

function backup_parus()
{
    tar -czf "${BACKUP_DATABASE}parus-"$date".tar.gz" $SOURCE_DATABASE || return $?
    cp ${BACKUP_DATABASE}parus-"$date".tar.gz $COPY_DIR
    echo "`date -d"$date" +%Y-%m-%d` Backup Parus database in $COPY_DIR successfully" >> $log_file
}

date=`date "+%Y-%m-%d"`
date_day=`date "+%w"`

[ -d $BACKUP_DATABASE ] || mkdir -pv $BACKUP_DATABASE
[ -d $COPY_DIR ] || mkdir -pv $COPY_DIR

if [[ ! `date -d"$date_day" +%w` = 6 && ! `date -d"$date_day" +%w` = 7 ]]; then
    backup_parus
else
    echo "`date -d"$date" +%Y-%m-%d` Резервное копирование базы Паруса не выполнено, т.к. сегодня $(date +%A)" >> $log_file
fi
MX 23.6 Libretto x86_64
Чем больше я работаю админом, тем больше понимаю, насколько волшебна фраза - "Нет технической возможности!"