![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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? |
|
||||
|
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. |
|
||||
|
Quote:
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. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|