- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- script question
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
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
Community
Resources
Forums
Blogs
- 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
01-25-2002 09:05 PM
01-25-2002 09:05 PM
OLD="14"
TODAY=$(date +%Y%m%d)
DIR="/test/test"
LOGFILE="test.log"
log_file() {
if [ -f ${DIR}/${LOGFILE} ]
then
cp -f ${DIR}/${LOGFILE} ${DIR}/${LOGFILE}.${TODAY}
cp /dev/null ${DIR/${LOGFILE}
gzip -f ${DIR}/${LOGFILE}.${TODAY}
done
print "Checking for files older than $OLD old days old."
print "Removing Files ..."
find ${DIR} -name "${LOGFILE}.*" -mtime +$OLD -exec rm -f {} \;
}
Thanks for the time and help.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2002 09:16 PM
01-25-2002 09:16 PM
Re: script question
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2002 09:19 PM
01-25-2002 09:19 PM
Re: script question
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2002 09:20 PM
01-25-2002 09:20 PM
Re: script question
Which line is line 17? And what was the error message?
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2002 09:27 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2002 09:41 PM
01-25-2002 09:41 PM
Re: script question
In case you are wondering what "fi" is, the loop structure for if is:
if ... # your condition here
then
# your code here
fi
You use done in a while loop:
while ... # your condition here
do
# your code here
done
Hope this explains it out for you. Regards.
Steven Sim Kok Leong
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2002 09:55 PM
01-25-2002 09:55 PM
Re: script question
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2002 03:28 AM
01-26-2002 03:28 AM
Re: script question
There are a few issues with this script:
1) log_file function is not called anywhere in the script. Preferably, it should be called after the function definition.
2) There is a typo in your cp statement which explains why /test/test/test.log was not created. There is a missing closing parenthesis.
>> cp /dev/null ${DIR/${LOGFILE}
It should be
cp /dev/null ${DIR}/${LOGFILE}
3) The gzip parameters are not correct. If you want your script to backup directories and files and keep the output log and errors during the archiving,
Instead of
>> gzip -f ${DIR}/${LOGFILE}.${TODAY}
It should be
gzip -f backup.gz list_of_dirs_and_files > ${DIR}/${LOGFILE} 2>&1
The backup log will be /test/test/test.log
Hope this helps. Regards.
Steven Sim Kok Leong
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2002 03:30 AM
01-26-2002 03:30 AM
Re: script question
Btw, to call your log_file function, simply insert at the bottom of your script:
log_file
Hope this helps. Regards.
Steven Sim Kok Leong
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2002 07:18 AM
01-26-2002 07:18 AM
Re: script question
You don't have to define your code as a function. As Steven points out, a function must be called, it is not executed simply because it is defined.
So, if this is simply a script you want to run from time to time, keep it simple by deleting the funciton definition lines:
log_file{} {
}
You wouldn't have the need for a statement to execute the code then.
If you do intend to add more code to the script and want to call log_file multiple times, then you have done well to code the function.
Darrell
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2002 04:15 PM
01-26-2002 04:15 PM
Re: script question
I need to make one correction to my posting above regarding your gzip statement. gzip is used for compressing individual files and not for archiving. If you are specifically talking about archiving (tar) and compressing the tar file (gzip) later, then you should use a combination of tar and gzip:
tar cvf - /home/* | gzip > /home/home.tar.gz > ${DIR}/${LOGFILE} 2>&1
Hope this helps. Regards.
Steven Sim Kok Leong