Sponsored Content
Full Discussion: Copy and append
Top Forums UNIX for Dummies Questions & Answers Copy and append Post 302603998 by Dougj75 on Friday 2nd of March 2012 02:07:07 PM
Old 03-02-2012
Copy and append

Ok, Here it goes. I have several file in a directory that I want to copy to another directory and append the date to the end of the file. I do not want to zip the I just need a copy. I would like the script to ask the user before copying each file in the directory to keep from making unneeded copies.This is what I have:
Code:
cd ${PACKAGE_HOME}/km/cfg/
 echo " Do you wish to back-up file.cfg ?"
        echo -n "Enter Y or N: "
        read YN
if [[ $YN == y || $YN == Y ]];
        then
                cp file.cfg ${PACKAGE_HOME}/km/cfg/OLD/file.cfg.`date '+%Y%m%d'`;
        echo " Copy Complete "
fi
 echo " Do you wish to back-up file2 ?"
        echo -n "Enter Y or N: "
        read YN
if [[ $YN == y || $YN == Y ]];
        then
                cp file2 ${PACKAGE_HOME}/km/cfg/OLD/file2.`date '+%Y%m%d'`;
        echo " Copy Complete "
fi
 echo " Do you wish to back-up file3 ?"
        echo -n "Enter Y or N: "
        read YN
if [[ $YN == y || $YN == Y ]];
        then
                cp file ${PACKAGE_HOME}/km/cfg/OLD/file3.`date '+%Y%m%d'`;
        echo " Copy Complete "
fi

I would like to do this with one command instead of listing each file like this:
Code:
cd ${PACKAGE_HOME}/km/cfg/
 echo " Do you wish to back-up files.cfg ?"
        echo -n "Enter Y or N: "
        read YN
if [[ $YN == y || $YN == Y ]];
        then
                cp files.cfg ${PACKAGE_HOME}/km/cfg/OLD/files.cfg.`date '+%Y%m%d'`;
        echo " Copy Complete "
fi

I would also like to be able to use this on other databases with minor changes. Is this possible?

Moderator's Comments:
Mod Comment (in case you missed it....) How to use code tags
 

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

append a ' to the $1 $2

Hi all , Iam trying to append a ' to the end of the $1 and $2 in the bellow example : awk '{print "exec upload" ,$1,$2,$3 "\ngo"}' so the output would be something like this : exec upload '444042 ','444042 ','919841037265' i am getting : exec upload 444042 ,444042 ,919841037265 ... (2 Replies)
Discussion started by: ppass
2 Replies

2. UNIX for Dummies Questions & Answers

What is in-core copy and disk-copy of i-node table?

I have found a question from the exercises of my study mat. The question is "Why are there a in-core copy and a disk-copy of i-node block and super block?" If any one know the proper answer then please send me..... (1 Reply)
Discussion started by: dearanik
1 Replies

3. UNIX for Dummies Questions & Answers

Find, copy, and append into one file

Hi, I am trying to do something relatively easy, but am having some trouble getting it to work. I have multiple files called "distances.log" in numerous subdirectories and sub-subdirectories within a directory. I would like the contents of each of these "distances.log" files to be appended to a... (2 Replies)
Discussion started by: euspilapteryx
2 Replies

4. Shell Programming and Scripting

Append stderr

Hi everybody. I was used to redirect stderr to a file in this way, calling a generic script:./myScript &> output.logBut now I need something more sophisticated...Inside a bash script I launch an executable in this way:${command} >> "${globalLogFile}"So I redirect the stdout into globalLogFile.... (14 Replies)
Discussion started by: canduc17
14 Replies

5. Shell Programming and Scripting

Copy & Append text

Hi, I have a huge text file that contains contents like below. echo 2VPMUM1CMP01_2011-05-10_18_CPU_Stats_1.txt awk -F, '{sub ("%","",$8);sum+=100-$8;if (100-$8>max){max=100-$8}}END{printf "max=%.1f%\navg=%.1f%\n",max,sum/NR}' echo 2VPMUM1CMP01_2011-05-11_10_CPU_Stats_1.txt awk -F,... (2 Replies)
Discussion started by: SunilB2011
2 Replies

6. UNIX for Dummies Questions & Answers

Copy value and append value to a list

Hi, sorry if this has been asked before but I couldnt find it. Essentially I am trying to find a value next to an xml tag say abcd 12345678 the number 1-8 is the number i need to copy to a file of order numbers in my home directory ~/tn/ordernumbers.txt say for example there are 3 or... (3 Replies)
Discussion started by: rg01
3 Replies

7. Shell Programming and Scripting

how to copy the directory but not copy certain file

Hi experts cp bin root src /mnt but not copy bin/bigfile any help? ( I post this thread in the "redhat" forum wrongly, I don't know how to withdraw that question in that wrong forum) Thanks (6 Replies)
Discussion started by: yanglei_fage
6 Replies

8. UNIX for Dummies Questions & Answers

Copy(append ) the contents of file1 and file2 to file3

Platform : Oracle linux 6.5 I have two log files with the following contents # ls -l total 8 -rw-r--r--. 1 root root 75 Dec 10 20:55 myLogfile1.log -rw-r--r--. 1 root root 51 Dec 10 20:57 myLogfile2.log # # cat myLogfile1.log hello world jaded zombies acted quaintly but kept driving... (9 Replies)
Discussion started by: kraljic
9 Replies
STICKY(7)					       BSD Miscellaneous Information Manual						 STICKY(7)

NAME
sticky -- sticky text and append-only directories DESCRIPTION
A special file mode, called the sticky bit (mode S_ISTXT), is used to indicate special treatment for directories. It is ignored for regular files. See chmod(2) or the file <sys/stat.h> for an explanation of file modes. STICKY DIRECTORIES
A directory whose `sticky bit' is set becomes an append-only directory, or, more accurately, a directory in which the deletion of files is restricted. A file in a sticky directory may only be removed or renamed by a user if the user has write permission for the directory and the user is the owner of the file, the owner of the directory, or the super-user. This feature is usefully applied to directories such as /tmp which must be publicly writable but should deny users the license to arbitrarily delete or rename each others' files. Any user may create a sticky directory. See chmod(1) for details about modifying file modes. HISTORY
A sticky command appeared in Version 32V AT&T UNIX. BUGS
Neither open(2) nor mkdir(2) will create a file with the sticky bit set. BSD
June 5, 1993 BSD
All times are GMT -4. The time now is 09:50 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy