- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: shell script
Operating System - Linux
1753398
Members
7269
Online
108792
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
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
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
07-09-2006 03:47 PM
07-09-2006 03:47 PM
shell script
Hi,
My system create files everyday in specific file system.
so I want to make a script which find out specific files created in specific time
and delete it after backup to other directory.
For example, The script find out file which created from 07:00 from 21:00,
and copy that file to backup directory and delete the original.
#ls -al A
-rw-rw---- 1 ftp sys 20971520 Jul 13 09:41 a
-rw-rw---- 1 ftp sys 20971520 Jul 12 06:40 b
-rw-rw---- 1 ftp sys 20972544 Jul 11 06:20 c
-rw-rw---- 1 ftp sys 20971520 Jul 10 22:01 d
-rw-rw---- 1 ftp sys 20972544 Jul 10 21:44 e
-rw-rw---- 1 ftp sys 20972544 Jul 10 20:30 f
-rw-rw---- 1 ftp sys 20971520 Jul 10 19:20 g
-rw-rw---- 1 ftp sys 20972544 Jul 10 08:10 h
-rw-rw---- 1 ftp sys 20972544 Jul 8 21:05 i
-rw-rw---- 1 ftp sys 20971520 Jul 8 20:30 j
Can anyone help?
Thanks,
zungwon
My system create files everyday in specific file system.
so I want to make a script which find out specific files created in specific time
and delete it after backup to other directory.
For example, The script find out file which created from 07:00 from 21:00,
and copy that file to backup directory and delete the original.
#ls -al A
-rw-rw---- 1 ftp sys 20971520 Jul 13 09:41 a
-rw-rw---- 1 ftp sys 20971520 Jul 12 06:40 b
-rw-rw---- 1 ftp sys 20972544 Jul 11 06:20 c
-rw-rw---- 1 ftp sys 20971520 Jul 10 22:01 d
-rw-rw---- 1 ftp sys 20972544 Jul 10 21:44 e
-rw-rw---- 1 ftp sys 20972544 Jul 10 20:30 f
-rw-rw---- 1 ftp sys 20971520 Jul 10 19:20 g
-rw-rw---- 1 ftp sys 20972544 Jul 10 08:10 h
-rw-rw---- 1 ftp sys 20972544 Jul 8 21:05 i
-rw-rw---- 1 ftp sys 20971520 Jul 8 20:30 j
Can anyone help?
Thanks,
zungwon
1 REPLY 1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2006 04:29 PM
07-09-2006 04:29 PM
Re: shell script
The key is to use touch to create two reference files and then use the -newer option of find.
#!/usr/bin/sh
TDIR=${TMPDIR:-/var/tmp}
typeset T1=${TDIR}/Ref_1.${$}
typeset T2=${TDIR}/Ref_2.${$}
typeset BKDIR=/xxx/Backup
typeset SRCDIR=/xxx/yyy
typeset -i STAT=0
typeset FNAME=""
typeset DESTNAME=""
cd ${SRCDIR}
STAT=${?}
if [[ ${STAT} -ne 0 ]]
then
echo "Can't cd to ${SRCDIR}" >&2
exit ${STAT}
fi
touch -t 200607090659.59 ${T1}
touch -t 200607092100.01 ${T2}
find . -type f \( -newer ${T1} -a ! -newer ${T2} \) -print | while read FNAME
do
DESTNAME="${DESTDIR}/${FNAME}"
if [[ -f "{DESTNAME}" ]]
then
echo "${DESTNAME} exists; not copied" >72
else
cp -p "{FNAME}" "${DESTNAME}"
STAT=${?}
if [[ ${STAT} -eq 0 ]]
then
rm -f "${FNAME}"
else
echo "Cp of ${FNAME} failed; status ${STAT}" >&2
fi
fi
done
rm -f ${T1} ${T2}
exit ${STAT}
man find, touch for details.
#!/usr/bin/sh
TDIR=${TMPDIR:-/var/tmp}
typeset T1=${TDIR}/Ref_1.${$}
typeset T2=${TDIR}/Ref_2.${$}
typeset BKDIR=/xxx/Backup
typeset SRCDIR=/xxx/yyy
typeset -i STAT=0
typeset FNAME=""
typeset DESTNAME=""
cd ${SRCDIR}
STAT=${?}
if [[ ${STAT} -ne 0 ]]
then
echo "Can't cd to ${SRCDIR}" >&2
exit ${STAT}
fi
touch -t 200607090659.59 ${T1}
touch -t 200607092100.01 ${T2}
find . -type f \( -newer ${T1} -a ! -newer ${T2} \) -print | while read FNAME
do
DESTNAME="${DESTDIR}/${FNAME}"
if [[ -f "{DESTNAME}" ]]
then
echo "${DESTNAME} exists; not copied" >72
else
cp -p "{FNAME}" "${DESTNAME}"
STAT=${?}
if [[ ${STAT} -eq 0 ]]
then
rm -f "${FNAME}"
else
echo "Cp of ${FNAME} failed; status ${STAT}" >&2
fi
fi
done
rm -f ${T1} ${T2}
exit ${STAT}
man find, touch for details.
If it ain't broke, I can fix that.
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