GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Looking for a modified copy command [ Prefrably a ...
Operating System - HP-UX
1845515
Members
2505
Online
110244
Solutions
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
Forums
Categories
This widget could not be displayed.
Company
This widget could not be displayed.
Local Language
This widget could not be displayed.
back
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
back
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
Blogs
Information
This widget could not be displayed.
This widget could not be displayed.
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
- This widget could not be displayed.This widget could not be displayed.This widget could not be displayed.This widget could not be displayed.This widget could not be displayed.This widget could not be displayed.
- 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.
Company
Events and news
Customer resources
© Copyright 2026 Hewlett Packard Enterprise Development LP