Linux Help
guides forums blogs
Home Desktops Distributions ISO Images Logos Newbies Reviews Software Support & Resources Linuxhelp Wiki

Welcome Guest ( Log In | Register )



Advanced DNS Management
New ZoneEdit. New Managment.

FREE DNS Is Back

Sign Up Now
 
Reply to this topicStart new topic
> Copy Or Rename Script, copy or rename script
ishba
post Nov 21 2003, 04:56 AM
Post #1


Whats this Lie-nix Thing?
*

Group: Members
Posts: 1
Joined: 21-November 03
Member No.: 1,838



Hello I am rather new to Linux and I need a script or utility to copy or rename a file that changes frequently to succesive file names.. that maybe i can call from cron to be done at certain times
As an example I have file list.xxx and want it copied or renamed to list-1.xxx
and next time it is copied to check to see what last name is and name it next higher number in succession.. ie list-2.xxx and list-3.xxx

Am I asking for too much? sounds pretty simple just not familiar enough with linux script files.

Maybe it doesnt have to be a script can i add options to end of a command like cp that will handle this for me?
Go to the top of the page
 
+Quote Post
hughesjr
post Nov 21 2003, 09:02 AM
Post #2


Its GNU/Linuxhelp.net
*******

Group: Admin
Posts: 3,433
Joined: 25-July 03
From: Corpus Chrsiti, TX, USA
Member No.: 1,151



A script is the way to go ... it can be done several ways. First, would a date-time e better than a number? If you are going to run the script once per day or less, you could use the date like so list-11-21-2003.xxx list-11-22-2003.xxx (or maybe list-11-22-2003-1143.xxx) Either is doable ... what's best for you?

Here is a simple script i named test.sh

CODE
#!/bin/bash
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin

# This does the math for the filename and stores the result
# for future use in a file called test.num.  This file is
# designed to be in the directory the other files reside in
#
if [ -f test.num ]; then
 a=`cat test.num`
else
 a=0
fi

let "a = $a + 1"
echo $a > test.num

# This copies the file list.xxx to list-#.xxx when you run
# the script.  If you also want to remove the old list.xxx
# and start with a new file, remove the # from the last line

cp list.xxx list-"$a".xxx
#echo > list.xxx


If you save this script to a text file and make it executable (chmod 755 test.sh), it will copy a file named list.xxx to list-1.xxx (the next time it is run it will copy list.xxx to list-2.xxx, etc.) and if you remove the # from the last line it will blankout list.xxx to start it over from a blank file.


--------------------
Johnny Hughes
hughesjr@linuxhelp.net
Enterprise Alternatives: CentOS, WhiteBoxEL
Favorite Workstation Distros (in order): CentOS, Gentoo, Debian Sarge, Ubuntu, Mandrake, FedoraCore, Slackware, SUSE
Favorite Server Distros (in order): CentOS, WhiteBoxEL, Debian Sarge, Slackware, Mandrake, FedoraCore, Gentoo, SUSE
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 21st October 2017 - 11:18 PM