#!/bin/sh
# FILE: clean_dirs
# GOAL : To clean up directories used in Oracle processing
# LANGUAGE : shell script (sh)
# PARAMETERS : Input_File
# 11/07/02 acri - modified to cd into the directory so it will follow links
# 02/05/07 acri - modified move directories when mask is specified (var 3)
# 10/01/10 brr - modified to add host name to output file.
# 01/17/12 acri - use setup.sh include mod, validate input file is in
# /winixdb/dba/ENV/scripts/infiles
# Insure 1 command line variables
if [ $# != 1 ]; then
echo "Usage: clean_dirs Input_File"
exit 1
fi
#variables
LOG_DIR='/home/devlogic/logs'
SCRIPT_DIR='/home/devlogic/scripts'
# Set up input variables.
INFILE=$1
# Set time stamp
TIMESTAMP=`date +%y%m%d%H%M`
DATE=`date +%y%m%d`
TIME=`date +%H%M`
#set ORACLE_SID so setup.sh does not err out
# it's not used in this shell
#ORACLE_SID=XX
# call common setup.sh
#. /winixdb/dba/prod/scripts/setup.sh
# Name of program
PROGRAM=`basename $0`
# Output file for cleaning out directories.
OUTPUTFILE=${LOG_DIR}/${PROGRAM}.${HOST}.${DATE}.${TIME}
# validate input file
if [ -f ${SCRIPT_DIR}/infiles/${INFILE} ]; then
INPUTFILE=${SCRIPT_DIR}/infiles/${INFILE}
else
echo "${SCRIPT_DIR}/scripts/infiles/${INFILE} not found"
exit 4
# For each directory and age specification found in the input file run the commands shown.
for VALUE in `cat ${INPUTFILE}`
do
echo "VALUE = ${VALUE}"
DIRECTORY=`echo ${VALUE} | cut -f1 -d,`
AGE=`echo ${VALUE} | cut -f2 -d,`
#prepopulate MASK with none, if it changes, then there is a mask
MASK=`echo ${VALUE} | cut -f3 -d,`
echo "DIRECTORY = ${DIRECTORY}"
echo "AGE = ${AGE}"
echo "MASK = ${MASK}"
# check to make sure directory or link exists prior to attempting to process it
if [ -d ${DIRECTORY} ] || [ -h ${DIRECTORY} ]; then
cd ${DIRECTORY}
# List files that will be moved and pipe to the OUTPUTFILE then move the files.
# Echo a message to the screen explaining what is going on.
if [ ${MASK:=none} = 'none' ]; then
echo "${PROGRAM} is removing files ${AGE} days old from ${DIRECTORY}" >>${OUTPUTFILE}
/bin/find . -mtime +${AGE} -ls >>${OUTPUTFILE}
/bin/find . -mtime +${AGE} -exec /bin/rm -f '{}' \;
else
echo "${PROGRAM} is removing files and directories with mask ${MASK}* ${AGE} days old from ${DIRECTORY}" >>${OUTPUTFILE}
/bin/find ./${MASK}* -mtime +${AGE} -ls >>${OUTPUTFILE}
/bin/find ./${MASK}* -mtime +${AGE} -exec /bin/rm -rf '{}' \;
fi
# Check the status of the return code and echo to the output file.
rcout=$?
echo "Return code = ${rcout}" >>${OUTPUTFILE}
else
echo "========================================================" >>${OUTPUTFILE}
echo "============> ${DIRECTORY} does not exist" >>${OUTPUTFILE}
echo "========================================================" >>${OUTPUTFILE}
echo "============> ${DIRECTORY} does not exist"
fi
done
Moderator's Comments:
edit by bakunin: give threads meaningful titles. Do you think "I am stuck. help me." is meaningful? I suggest you read the rules you agreed to obey again (and a good introductory book on Unix too, after this).
Last edited by bakunin; 06-25-2012 at 02:48 PM..
Reason: Please use CodeTags
I have a shell script that does NOT have the '#!' line at the top. It is written for ksh. The shell in my passwd entry is '/usr/bin/ksh' and my SHELL env variable is '/usr/bin/ksh'. Now, here's the issue. I invoke the script on Solaris with './myprog'. This works fine. I also run the same... (3 Replies)
hi,
i am one day old in shell scritpting. how to invoke one shell script from the other?
For eg.i have two shell scripts A.sh and B.sh. Inside A.sh i need to invoke B.sh and the return code of A.sh should be the value returned by B.sh.
it would be better if you provide any sample shell... (3 Replies)
I want to invoke shell script named bubesh.sh when submit button clicked on html/jsp page.I am using an apache server and the html & shell script are in the same working directory.Please help. (2 Replies)
list me commands to invoke a shell script from php once the submit button is clicked in the php page. Requirement is Once a submit button is clicked it should run a script that displays the outcome of the script in a html/php. Please help.
Thanks in Advance,
BubeshJ (2 Replies)
Hi everybody,
I have a script in which I'm invoking another script which runs in a subshell.
after the script is executed I want to return to the parent shell as some variables are set. However i'm unable to return to my original shell as the script which i'm calling inside is invoked in... (5 Replies)
Hi,
I have an HTML form through which I get some text as input. i need to run a shell script say script.sh inside a perl-cgi script named main_cgi.sh on the form input.
I want to write the contents of the form in a file and then perform some command line operations like grep, cat on the text... (2 Replies)
Hi All,
I am using the following command to invoke the shell script from a perl command.
perl -i.bak -pe'BEGIN { $cmd = "/opt/coreservices/tomcat-5.5.9/bin/digest.sh -a sha"; }
s/(password=")(*)/
$1.`$cmd $2|cut -d: -f2|tr -d "\n"`
/e
' $CATALINA_HOME/conf/tomcat-users.xml
I need... (1 Reply)
I have been writing an awk script to calculate and report on sales numbers for a couple different files. The only problem i am having is when i try to call the script.
I want to invoke the script by way of
awk -f report products associates sales
But so far when ever I do that errors are... (2 Replies)
Hello All,
I have a shell script A which is in one unix box. Also i have a script B in another unix box. Now i'm struggling to find a way to invoke A shell script from B shell script. Is it possible to do this in any way..Request you anybody please help me in this point.
Thanks in advance. (6 Replies)
Hi All,
I have a scenario :
1. A list of servers naming server21, server 22, server 23 etc. This list of servers is separate for my environments.
Env1 has 3 server
Env2 has 5 serves
Env3 has 10 servers
2. Each server accesses application through which I want to invoke some method. So... (7 Replies)