<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi.<div class=""><br class=""></div><div class="">Можно реализовать через файл блокировки (в примере ниже переменная LOCK). Т. е. при запуске скрипта создается файл, который не удаляется если задание не завершено (например первый бакап длится больше заданного интервала вркмкни).</div><div class=""><br class=""></div><div class="">Пример бакапа домашних папок пользователей по времени (типа «Машина времени»):</div><div class=""><br class=""></div><div class=""><div class=""># cat rbackup.sh </div><div class="">=============================================================</div><div class="">#!/bin/sh</div><div class="">date=`date "+%Y-%m-%d-%H%M%S"`</div><div class="">rsync=/usr/local/bin/rsync</div><div class="">LOCK=/var/spool/lock/rbackup.lock</div><div class="">LOG=/var/log/rbackup.log</div><div class=""><br class=""></div><div class="">SRC=/home/</div><div class="">TARGET=/var/data/backups/homes/$date</div><div class="">P_TARGET=/var/data/backups/homes/Latest</div><div class=""><br class=""></div><div class="">if [ -f $LOCK ]; then</div><div class="">    exit 0</div><div class="">fi</div><div class=""><br class=""></div><div class="">touch $LOCK</div><div class="">date >> $LOG</div><div class="">mkdir -p $TARGET</div><div class=""><br class=""></div><div class="">$rsync -auvAHX --link-dest=$P_TARGET $SRC $TARGET >>$LOG 2>&1</div><div class=""><br class=""></div><div class="">rm -f $P_TARGET</div><div class="">ln -s $TARGET $P_TARGET</div><div class="">rm $LOCK</div><div class=""><br class=""></div><div class="">exit 0</div></div><div class=""><div class="">=============================================================</div></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><div class="">
<div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><span class="Apple-style-span" style="border-collapse: separate; font-variant-ligatures: normal; font-variant-position: normal; font-variant-numeric: normal; font-variant-alternates: normal; font-variant-east-asian: normal; line-height: normal; border-spacing: 0px;"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; border-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">__</div><div class="">With best regards,<br class="">Andrey Marshalenko.<br class=""><span style="orphans: auto; widows: auto;" class="">System & Network Administrator</span><br class="">AM1000-UANIC<br class="">mailto: <a href="mailto:marshall@marshall.kiev.ua" class="">marshall@marshall.kiev.ua</a><br class="">tel (mob) +380676574197<br class="">Skype: marshalenko</div><div class="">JabberID: <a href="mailto:marshall@marshall.kiev.ua" class="">marshall@marshall.kiev.ua</a></div></div></span></div></span></div></div></div></div>
</div>
<br class=""><div><blockquote type="cite" class=""><div class="">25 янв. 2017 г., в 14:52, Valentin Nechayev <<a href="mailto:netch@netch.kiev.ua" class="">netch@netch.kiev.ua</a>> написал(а):</div><br class="Apple-interchange-newline"><div class=""><div class="">hi,<br class=""><br class=""> Wed, Jan 25, 2017 at 14:49:46, krylov wrote about "[freebsd] Повторный запуск скрипта в cron": <br class=""><br class=""><blockquote type="cite" class="">Есть задача в cron'e rsync'ом делать зеркало раз в минуту<br class="">Как правильно обезопаситься от повторного запуска скрипта?<br class=""><br class="">нашел <a href="https://habrahabr.ru/post/114622/" class="">https://habrahabr.ru/post/114622/</a><br class="">но в портах нет lockrun<br class=""><br class="">flock кошерно использовать?<br class=""></blockquote><br class="">Фрёвая тулза зовётся lockf, и таки да, кошерно и прельстиво.<br class=""><br class=""><br class="">-netch-<br class="">_______________________________________________<br class="">freebsd mailing list<br class=""><a href="mailto:freebsd@uafug.org.ua" class="">freebsd@uafug.org.ua</a><br class="">http://mailman.uafug.org.ua/mailman/listinfo/freebsd<br class=""></div></div></blockquote></div><br class=""></div></body></html>