- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Looking for a modified copy command [ Prefrably a ...
Operating System - HP-UX
1753767
Members
5797
Online
108799
Solutions
Forums
Categories
Company
Local Language
юдл
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
юдл
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-20-2009 11:45 AM
тАО02-20-2009 11:45 AM
Looking for a modified copy command [ Prefrably a C shell Script]
As a sysadmin I often find myself backingup files before changing them with something like
% cp -p filename filename.backup
I am looking for something which copies a individual file in a directory (probably called "Archive") in the same place. It should create a directory if one does not exist.
example:
% mycp /etc/resolv.conf
should make a copy of the file "/etc/resolv.conf" as
/etc/Archive/resolv.conf.backup
% cp -p filename filename.backup
I am looking for something which copies a individual file in a directory (probably called "Archive") in the same place. It should create a directory if one does not exist.
example:
% mycp /etc/resolv.conf
should make a copy of the file "/etc/resolv.conf" as
/etc/Archive/resolv.conf.backup
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-20-2009 12:35 PM
тАО02-20-2009 12:35 PM
Re: Looking for a modified copy command [ Prefrably a C shell Script]
Hi:
You really (already) have your solution -- write a wrapper script for 'cp'. Do NOT use the C-shell. It is dysfunctional. See:
http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/
That said:
# cat ./mycp
#!/usr/bin/sh
FILE="$@"
ARCHIVE=/var/tmp
[ -z "${FILE}" ] && { echo "Usage: $0 file"; exit 1; }
[ -f "${FILE}" ] || { echo "File expected" ; exit 1; }
[ -d "${ARCHIVE}" ] || { echo "Missing '${ARCHIVE}' directory"; exit 1; }
SUBDIR=${ARCHIVE}/$(dirname ${FILE})
mkdir -p ${SUBDIR}
cp -p ${FILE} ${SUBDIR}/$(basename ${FILE}).backup
exit
...run as :
# ./mycp full_path_to_file
For example:
# ./mycp /etc/hosts
# ./mycp /etc/rc.config.d/netconf
Modify the ARCHIVE=/var/tmp to your tastes.
Regards!
...JRF...
You really (already) have your solution -- write a wrapper script for 'cp'. Do NOT use the C-shell. It is dysfunctional. See:
http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/
That said:
# cat ./mycp
#!/usr/bin/sh
FILE="$@"
ARCHIVE=/var/tmp
[ -z "${FILE}" ] && { echo "Usage: $0 file"; exit 1; }
[ -f "${FILE}" ] || { echo "File expected" ; exit 1; }
[ -d "${ARCHIVE}" ] || { echo "Missing '${ARCHIVE}' directory"; exit 1; }
SUBDIR=${ARCHIVE}/$(dirname ${FILE})
mkdir -p ${SUBDIR}
cp -p ${FILE} ${SUBDIR}/$(basename ${FILE}).backup
exit
...run as :
# ./mycp full_path_to_file
For example:
# ./mycp /etc/hosts
# ./mycp /etc/rc.config.d/netconf
Modify the ARCHIVE=/var/tmp to your tastes.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-20-2009 01:51 PM
тАО02-20-2009 01:51 PM
Re: Looking for a modified copy command [ Prefrably a C shell Script]
James
Thanks for your prompt reply. My objective is to have an "Archive" directory wherever the file is being backed up which I understand maybe a little complicated.
Howevery I am getting a syntax error as below.
surya{root}50% ./mycp /etc/resolv.conf
./mycp: syntax error at line 7: `SUBDIR=${ARCHIVE}/$' unexpected
surya{root}51%
Thanks for your prompt reply. My objective is to have an "Archive" directory wherever the file is being backed up which I understand maybe a little complicated.
Howevery I am getting a syntax error as below.
surya{root}50% ./mycp /etc/resolv.conf
./mycp: syntax error at line 7: `SUBDIR=${ARCHIVE}/$' unexpected
surya{root}51%
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-20-2009 01:57 PM
тАО02-20-2009 01:57 PM
Re: Looking for a modified copy command [ Prefrably a C shell Script]
Hi (again):
Hmmm. I copied-and-pasted from my posting here and can't seem to repeat your error.
Regards!
...JRF...
Hmmm. I copied-and-pasted from my posting here and can't seem to repeat your error.
Regards!
...JRF...
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP