The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
combination of two commands nehaquick UNIX for Dummies Questions & Answers 3 02-01-2008 04:09 AM
Detecting a key combination mobile01 High Level Programming 11 12-22-2006 09:46 AM
awk and file combination sickboy UNIX for Dummies Questions & Answers 1 06-13-2005 10:02 PM
Combination Of commands rahulrathod UNIX for Dummies Questions & Answers 2 12-14-2004 07:32 AM
Partition combination gardarm Filesystems, Disks and Memory 3 03-14-2002 07:35 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-21-2009
cbo0485 cbo0485 is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 87
Combination backup/VI script

I was needing a script that basically covers my butt, lol. I have the nasty habit of making many changes without backing up files, and then after a ton of changes, if I have to go back to the original version, it makes it harder to go back.

Now, I have a script that takes a file, renames it to filename.bak.datestamp, but I was wondering how I would go about making a combination script.

I use vi to edit most files, so I'd like to use an alias 'vib'. I'd like to be able to use it in this way:

vib filename.txt

I'd like it to call a script that first runs the backup script, then runs the vi command.

Anyone done this before?
  #2 (permalink)  
Old 01-21-2009
Rhije Rhije is offline
Registered User
  
 

Join Date: Dec 2008
Posts: 103
Well.. I am not able to test it right now, but something like this should suffice.


Code:
function vib() {
    if [ -z $1 ]; then
        echo "You must supply a filename to modify.";
        echo "Syntax is: vib filename";
        exit;
    fi
    if [ ! -z $1 ]; then
        cp -v $1 /home/username/pathtobackupdir/$1.bak.`date +%Y%m%d`
        vi $1
    fi
}

Let me know how it works out! Of course, change the path to the backup directory.
  #3 (permalink)  
Old 01-21-2009
pludi's Avatar
pludi pludi is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2008
Location: .at
Posts: 1,972
You mean something like
Code:
for file in "$*"
do
    cp ${file} ${file}.`date +%Y-%m-%dT%H:%M:%S`
done
vi "$*"

Personally, I rather prefer svn (or any other RCS) over the copy-backup method for such things.
  #4 (permalink)  
Old 01-22-2009
cbo0485 cbo0485 is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 87
Quote:
Originally Posted by pludi View Post
You mean something like
Code:
for file in "$*"
do
    cp ${file} ${file}.`date +%Y-%m-%dT%H:%M:%S`
done
vi "$*"

Personally, I rather prefer svn (or any other RCS) over the copy-backup method for such things.
Works perfectly.

I might have used the first posters, but the server is pretty consolidated, with different backup directories for different applications, so it would have gotten much more complicated to work all that into it.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:17 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0