- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Help to write a shell script in HPUX
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
02-03-2005 12:41 AM
02-03-2005 12:41 AM
I am trying to write a program in shell script that does the following:
- check if three files (with its date of creation in its name) of today, yesterday and three days ago, exists
- If they exists, remove all the other files older than three days ago. If they do not
exists, do nothing.
I don
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2005 12:42 AM
02-03-2005 12:42 AM
Re: Help to write a shell script in HPUX
Regards,
(the messages was cu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2005 12:42 AM
02-03-2005 12:42 AM
Re: Help to write a shell script in HPUX
Regards,
(the messages was cu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2005 01:19 AM
02-03-2005 01:19 AM
Re: Help to write a shell script in HPUX
company name:
country: spain
personal quote:
certification:
ITRC member since: April 21, 2003
last contribution date: February 03, 2005
I have assigned points to 46 of 134 responses to my questions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2005 01:26 AM
02-03-2005 01:26 AM
Re: Help to write a shell script in HPUX
can you give examples of this filenames.
regards,
Thierry.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2005 01:36 AM
02-03-2005 01:36 AM
Re: Help to write a shell script in HPUX
Jannik : Sorry for the points not assigned; i use to forget to assign, but not in my lasts threads.
The names are in the form:
- filexxx-
Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2005 01:45 AM
02-03-2005 01:45 AM
Re: Help to write a shell script in HPUX
if the file names are in the format *YYYYMMDD*
then somthing like this will get you started.
Some of the guys here have prewritten scripts that do this sort of thing. Use the keyword 'yesterday'in the forum search.
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2005 02:11 AM
02-03-2005 02:11 AM
Re: Help to write a shell script in HPUX
as you still didn't give real examples, how about something general:
#! /usr/bin/ksh
nofiles=`find /yourdir -type f -name "file*.Z" -mtime -4 | wc -l`
if [ $nofiles -ge 4 ]
then
find /yourdir -type f -name "file*.Z" -mtime +4 -exec rm {} \;
fi
notes:
- adapt "name" and "-mtime" to your needs
- test this first without the "-exec rm {} \;"
- find will also work through subdirs, so don't use this if you have subdirs.
regards,
Thierry.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2005 03:19 AM
02-03-2005 03:19 AM
Re: Help to write a shell script in HPUX
The exactly names of the files are:
backup_01-02-05_00_00.dmp.Z , where "01-02-05_00_00" is "day-month-year_hour_minute"
I have already a script with "mtime" but I think it is a bit "dangerous". The script that have sent Peter, works fine to calculate the date; I only need to convert to this date and to remove he older...
Regards,
R.O.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2005 09:05 PM
02-03-2005 09:05 PM
Re: Help to write a shell script in HPUX
Peter, how can I convert four digits of year in two? (tried printf("%02d... but it does not work)
In the other hand, how can I select the files older than the three firsts to delete them??
Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2005 09:33 PM
02-03-2005 09:33 PM
Re: Help to write a shell script in HPUX
1. something like:
two = `echo $four | cut -c3-4`
2.
find /yourdir ! -newer file3daysago ! -name file3daysago
or specify all 3 files:
find /yourdir ! -newer file1 ! -name file1 ! -newer file2 ! -name file2 ! -newer file3 ! -name file3
regards,
Thierry.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2005 09:52 PM
02-03-2005 09:52 PM
Re: Help to write a shell script in HPUX
I want to avoid to select files based upon in its modification time, but in the date inserted in its name. It is possible that someone modifies a file, so the modification time is not valid to do this.
Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2005 10:04 PM
02-03-2005 10:04 PM
Solutionto answer your question re 4/2 digits:
firstdate=`perl -e '($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time-2*86400); $fix_year = $year - 100; $fix_m
on = $mon + 1;printf("%02d%02d%02d\n",$fix_year,$fix_mon,$mday)'`
The difference is rather than adding 1900 you subtract 100 as year is number of years since 1900. The format can then be changed from %04 to %02. Problems MAY occurs with date before 1/1/2000, but this should not be problem for what you want to do.
Regards