🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.bash
Article #1

Re: pushing my bash luck

#1
From: bad sector
Date: Thu, 19 Sep 2024 20:04
77 lines
4438 bytes
moved over from alt.os.linux



On 9/19/24 11:35, Chris Elvidge wrote:
> On 19/09/2024 at 16:14, bad sector wrote:
>> On 9/19/24 11:01, Chris Elvidge wrote:
>>> On 19/09/2024 at 13:18, bad sector wrote:
>>>>
>>>> I want to devise a shutdown cron script that will make a dated rsync 
>>>> backup of any directory under a particular path that had been 
>>>> written to during the session and then shut down.
>>>>
>>>> The rsync command itself would look something like
>>>>
>>>> rsync -ahcEWXd /x/trees-planted/ /x/trees-$date (format 
>>>> 2024-09-24-hr-m)
>>>>
>>>> The part that's over my head is for the script to know what 
>>>> directory (under /x in this case) had been written to.
>>>>
>>>> Maybe there's a uti that already does this and I just have to invoke 
>>>> IT with args in the script?
>>>
>>> Try it with a local function to override the built-in command?
>>>
>>> shutdown() {
>>> printf -v today '%(%Y-%m-%d_%H-%M)T'
>>> # this will put the contents of /x/trees-planted into the directory
>>> # /x/trees-2024-09-19_16-00
>>> rsync -ahcEWXd /x/trees-planted/ /x/trees-$today && /sbin/shutdown
>>> }
>>
>> thanks, that gives me the date to append which I don't need if doing 
>> it manually but gotta have as part of any script.
>>
>>
> OK change second line to:
> if tty -s; then read -p "Give a value: " today; else printf -v today 
> '%(%Y-%m-%d_%H-%M)T'; fi

Thanks, my highness is at scripting level 10,
meaning that for every line I need 10 comment
lines explaining that one line to myself.

I thought I had it made but screwed it up. This
script gives me the youngest file date but only
in the first directory, the loop isn't viable.


cd /x
for d in [0-9][0-9][0-9]
do
##################################################
# the 1st ls in next line tells you where you are.
# the find command coughs up the youngest file mod date
##################################################
     ( cd "$d" && ls; find . -not -type d -printf "%TY.%Tm.%Td\n" | sort 
-n | tail -1
)
done

I would also like to break the steps up between the sub shell brackets 
but I don't know if that needs to remain on a single line.

The plan would be, in that sub shell, to enter every 1st depth directory 
under /x  such as say /x/1 to x99 and find if that directory has a 
younger file than the youngest one in its backup under /y such as /y/1 
...recursively under /y because there may be several date-appended 
back-levelable versions of 1 there already.

/y is a copy of the last backup made, usually a couple of months old, I 
would know that it's time for a new one when some of its 1st depth 
directories have too many interim backlevel copies already such as 
/y/3-2024-08-19 etc.
Technical Details
Message-ID: <HaKdncRCCYQkHnH7nZ2dnZfqn_YAAAAA@giganews.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!archive!apf8.newsdeef.eu!nnrp.usenet.blueworldhosting.com!!spool1.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!feeder.usenetexpress.com!tr3.iad1.usenetexpress.com!69.80.99.27.MISMATCH!border-4.nntp.ord.giganews.com!nntp.giganews.com!Xl.tags.giganews.com!local-2.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mail
References: <fnGdnWF7Lsgzi3H7nZ2dnZfqnPqdnZ2d@giganews.com> <vchebh$k2k4$1@dont-email.me> <KyednUkpsbJ9onH7nZ2dnZfqnPgAAAAA@giganews.com> <vchgcr$kcfe$1@dont-email.me>

Show Full Headers
Complete Article Headers
Message-ID: <HaKdncRCCYQkHnH7nZ2dnZfqn_YAAAAA@giganews.com>
Subject: Re: pushing my bash luck
Date: Thu, 19 Sep 2024 16:04:08 -0400
From: bad sector <forgetski@_INVALID.net>
References: <fnGdnWF7Lsgzi3H7nZ2dnZfqnPqdnZ2d@giganews.com> <vchebh$k2k4$1@dont-email.me> <KyednUkpsbJ9onH7nZ2dnZfqnPgAAAAA@giganews.com> <vchgcr$kcfe$1@dont-email.me>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!archive!apf8.newsdeef.eu!nnrp.usenet.blueworldhosting.com!!spool1.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!feeder.usenetexpress.com!tr3.iad1.usenetexpress.com!69.80.99.27.MISMATCH!border-4.nntp.ord.giganews.com!nntp.giganews.com!Xl.tags.giganews.com!local-2.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Thu, 19 Sep 2024 20:04:08 +0000
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Newsgroups: gnu.bash
Content-Language: hu-HU
In-Reply-To: <vchgcr$kcfe$1@dont-email.me>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 78
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-hXzcFA9xv/ho1PaSJi2L8gBZ+5dPY0p1ZJoJNrHggFSUmWfGqvBxlG52p2mOpTQuhSg06vQRThVifs2!otUC1Edjn5hjcn22ZNRhTQhLq080Ngt+4L0Ft+o3V2Pz1esstm+Y4+5lbz/ToakCqqJ9n1lCfMH1
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40