- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Environment Variables
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
10-15-2001 11:26 PM
10-15-2001 11:26 PM
I have attached a complete document of my requirement regarding the shell script and environment variables.
Its urjent..Please provide me a help..
Thanking you
Rajkumar
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2001 11:34 PM
10-15-2001 11:34 PM
Re: Environment Variables
and modify the script so it gets the directory as an argument.
aha, and make sure you are on the top directory of the directory structure that you want to clean.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2001 11:41 PM
10-15-2001 11:41 PM
Re: Environment Variables
isn't it sufficient for you to run just this part of the script (tune the location to your needs):
COUNT=0
find /Database/J??/* -name "X_*" -mtime +3 | while read FILE ; do
rm $FILE && logger "$0 : $FILE deleted"
(( COUNT = COUNT + 1 ))
done
if [ "$COUNT" -gt 0 ] ; then
logger "$0 : $COUNT files removed"
else
logger "$0 : No matching files found"
fi
regards,
Thierry.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2001 11:42 PM
10-15-2001 11:42 PM
Re: Environment Variables
I didnt understand what you are telling me..
My query is to delete the files from the multiple directories..Can you give me complete picture
Thanks
Rajkumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2001 11:47 PM
10-15-2001 11:47 PM
Re: Environment Variables
That means it will search all the files from the database directory untill this files starting with X_
I am trying out with your script..
Thanks
Rajkumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2001 11:54 PM
10-15-2001 11:54 PM
Re: Environment Variables
find /Database/.... -name "X_*" ....
will give you *ALL* files starting with "X_" in /Database and ALL its subdirectories. You do not have to specify directory per directory, unless you want to skip some specific directories.
BTW it's always a good idea to test those find&delete scripts first with find&display ;)
good luck,
Thierry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2001 12:05 AM
10-16-2001 12:05 AM
SolutionPersonally, if you want to control the directories externally, I'd put them into a file, and read the file in the script:
========================================
#!/bin/ksh
cat file_containing_list_of_directories | while read DIR ; do
if [ ! -d "$DIR" ] ; then
logger "$0 : $DIR not found"
exit 1
fi
COUNT=0
find $DIR -name "X_*" -mtime +3 | while read FILE ; do
rm $FILE && logger "$0 : $DIR - $FILE deleted"
COUNT=$(expr $COUNT + 1)
done
if [ "$COUNT" -gt 0 ] ; then
logger "$0 : $DIR - $COUNT files removed"
else
logger "$0 : No matching files found"
fi
done
exit 0
===========================================
Then you can leave the cronjob as it is, and edit the external file to suit.
Rgds, Robin.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2001 01:47 AM
10-16-2001 01:47 AM
Re: Environment Variables
Please provide more input. Are there any other directories under /Database that you don't want to touch? Do you only want to erase from the specific directories you have in the file? I believe this questions you can answer, right?
E.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2001 04:46 PM
10-16-2001 04:46 PM
Re: Environment Variables
Yes . I have a standard directories which i have to delete..But some times the directories may change..At that time the script dosent workout,because we are declaring the Environment variable and passing it into the script..I have also input parameters.Suppose i have a file which was created on 1st 09:00 AM..So this file has to be deleted for every 3 days and it should be depend on time and date also..
That means Preservation period : (3 days to delete a file). If they want to change it to 4 days ..
Please advise me.
Thanks & Regards
Rajkumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2001 05:09 PM
10-16-2001 05:09 PM
Re: Environment Variables
You can use the same script to achive what you need.
You can provide inputs to this script and it works as well with some modifications.
#!/usr/bin/ksh
if[ $# -ne 3 ]
then
echo "Usage: $0 directory expiry match"
exit 1
fi
DIR=${X:-$1}
EXPIRE=${E:-$2}
MATCH=${M:-$3}
DIRs=`ll -d $DIR`
for I in $DIRs
do
if [ -d $I ]
then
echo $I >> /tmp/valid$$
fi
done
TOTALDIR=`wc -l /tmp/valid$$|awk '{print $1}'`
if [ $TOTALDIR -eq 0 ]
then
logger "$0: No valid directories found"
exit 1
else
logger "$0: $TOTALDIR number of dirs found.. deleting"
fi
for I in `cat /tmp/valid$$`
do
COUNT=0
find $I -name $MATCH -mtime $EXPIRE|while read FILE
do
rm $FILE && logger "$0 : $FILE deleted"
COUNT=$(expr $COUNT+1)
done
logger "$0: deleted $COUNT files in $I"
done
rm /tmp/valid$$
exit 0
//END of the script
Now this script will take three arguments
#input.ksh directory expiry match_string
For ex.,
#input.sh /database/X* 4 X_*
will delete all the files under /database/X* directories that haven't been modified since 4days that match the string X_*.
I suggest you use this script on some temporary directories and see if it works for permitations and combinations of inputs. I don't have a system in front of me. It doesn't do error checking. For ex., input.ksh test test new will give out errors and may also do damage. So, you need to be careful. To do error checking is a big business.
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2001 07:04 PM
10-16-2001 07:04 PM
Re: Environment Variables
Once again
I need to pass two parameters:
a) The files stating with "X_" and
b) Retained time for deleting the renamed file (or) Retained time for deleting the non-renamed file.
(ie.,Time based)
Note: That means users will FTP from the remote server to the local server.So once the file is in the local server it will be renamed to "X_
so If i pass the paramters like
variable1= X_ and time=1 (ie 1 hour)
It has to check the two conditions and file has to be deleted.
Is it possible like that to develop a shell script like that..
Regards
Rajkumar