nonethefewer: (Default)
Chris ([personal profile] nonethefewer) wrote2009-06-16 09:44 am

(no subject)

This is scripting stuff for work.  I don't script in Linux that often, sooo.

--

This directory has a series of folders with this naming convention:

update_[name][date]/

It's wicked simple.  Basically, I need to:

- get the most recent folder name for [name]
- make a new folder for today's date
- copy from most-recent to new-folder
- cd new-folder

Fucked if I know, though.

[identity profile] australian-joe.livejournal.com 2009-06-16 07:08 pm (UTC)(link)
I don't have a Linux handy to get this right in, alas.

Assuming bash, this may be useful to get you going in the right direction:

#!/bin/bash

BASEDIR=[path]
NAME="[...]"
DATE=$( date +[format stuff here] )

# this is a "minus 1, not a minus lower-case L"
MOSTRECENT=$( ls -1 -t ${BASEDIR}/update_${NAME}* | head -1 )

# if the date is regularly formatted, maybe use cut to strip out the date
DATELESS=$( echo ${MOSTRECENT} | cut [cut args here] )

NEWFOLDER="${DATELESS}${DATE}"

mkdir ${NEWFOLDER}
cp -rp ${MOSTRECENT}/* ${NEWFOLDER}
cd ${NEWFOLDER}



Something like that. Hope that helps.

[identity profile] novalis.livejournal.com 2009-06-16 07:44 pm (UTC)(link)
Use Python. os.listdir to get a list of file and directory names, re to split the name into the name, date, sort to sort them. Then use os.system to copy files.

[identity profile] hitchhiker.livejournal.com 2009-06-17 12:29 pm (UTC)(link)
is the date in ansi format? (i take it you want to sort by nominal date, rather than the folder timestamp, just in case)

[identity profile] hitchhiker.livejournal.com 2009-06-17 12:30 pm (UTC)(link)
(where by ansi format i mean yyyy-mm-dd)