Du bist hier: Snippet-Verzeichnis » UNIX Admin (199)
Sprache:

{copy/move}{date,note,time}

Sprache: English
Programmiersprache: Unix Shell
Veröffentlicht von: devphil [nicht registriert]
Letzte Änderung: 15.05.2006
Aufrufe: 1086


Beschreibung

This ksh script hardlinks itself as six other scripts: cpdate, cpnote, mvdate, mvnote, cptime, and mvtime. They are simple timesavers for making backup copies of files. The first iteration was written by a system administrator at a university, then others were added by me. Finally I pulled them all together into a single file and added some more "names" and the result is used quite a bit on my Unix systems.Here are some examples of combinations of commands. They should be self-explanatory.$ cpdateUsage: cpdate file [path]$ cpnoteUsage: cpnote file [path] note$ touch foo$ cpdate foo$ cpnote foo bar$ mkdir dir$ mvtime Usage: mvtime file [path]$ mvtime foo dir$ ls -lFtotal 16drwxr-xr-x 2 user group 197 Jan 15 19:28 dir/-rw-r--r-- 1 user group 0 Jan 15 19:27 foo.2000-01-15-rw-r--r-- 1 user group 0 Jan 15 19:27 foo.bar$ ls -lF dirtotal 0-rw-r--r-- 1 user group 0 Jan 15 19:27 foo.2000-01-15T19:28:18

Code

1 #! /bin/ksh 2 3 4 # {LNCPMV,"{cp,mv}{date,note,time} {args}"} 5 # If called as LNCPMV, creates the files listed in LIST below as hardlinks. 6 # 7 # + Original cpdate: "jsloan@wright, 10Dec1986" 8 # + {cp,mv}note: pedwards@cs.wright.edu 11Nov1994 9 # + mvdate: pedwards@cs.wright.edu 19Nov95 10 # + Copied to AAMR on W-P AFB, pedwards 22Oct97 11 # + Merged into one script, date changed from 'ddmmmyy' to 12 # extended ISO8601 format, added LNCPMV. pedwards 6Dec1999 13 # + *time: added especially for rotlog. Yes, that 'T' is supposed 14 # to be there as per 8601. pedwards 8Dec1999 15 ##################################################################### 16 17 DATE=/usr/xpg4/bin/date 18 LIST='cpdate cpnote mvdate mvnote cptime mvtime' 19 20 ## No more changes should be needed, unless new names are being added. 21 ##################################################################### 22 23 key=$(basename $0) 24 case $key in 25 cp*) cmd='cp -p';; 26 mv*) cmd='mv' ;; 27 LNCPMV) for i in $LIST; do 28 [[ -f $i ]] && rm $i 29 ln "$0" $i 30 done; exit 0 ;; 31 *) echo "$0 unmatched -- what command is that"; exit 1 ;; 32 esac 33 34 case $key in 35 *date) case $# in 36 1) source="$1"; target="$1" ;; 37 2) source="$1"; target="${2}/${1}" ;; 38 *) echo "Usage: $key file [path]"; exit 1 ;; 39 esac 40 target="${target}.$($DATE '+%Y-%m-%d')" 41 ;; 42 *time) case $# in 43 1) source="$1"; target="$1" ;; 44 2) source="$1"; target="${2}/${1}" ;; 45 *) echo "Usage: $key file [path]"; exit 1 ;; 46 esac 47 # I guess "datetime" might have been better than just "time" 48 target="${target}.$($DATE '+%Y-%m-%dT%T')" 49 ;; 50 *note) case $# in 51 2) source="$1"; target="${1}.${2}" ;; 52 3) source="$1"; target="${2}/${1}.${3}" ;; 53 *) echo "Usage: $key file [path] note"; exit 1 ;; 54 esac 55 ;; 56 esac 57 58 $cmd "$source" "$target" 59 60

Noch kein Kommentar vorhanden

Dieses Snippet kommentieren

Name *  

E-Mail (wird nicht angezeigt) *    

Website  

Kommentar *  

Sicherheitscode Sicherheitscode *    

RSS