How to run script automatically every 12 hour once?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to run script automatically every 12 hour once?
# 1  
Old 05-22-2013
How to run script automatically every 12 hour once?

Hi ! all, I have once script to remove temporary cache and temporary xml files

looks like this, as it is taking more space, I would like to run automatically every 12 hour once, and then I want to receive some log as acknowledgement

Code:
#!/bin/sh
echo "Removing logs and temp files (typically done before starting tomcat)..."
JAVA_HOME="/usr/lib/jvm/jdk1.7.0_11"
JAVA_OPTS="-Djava.awt.headless=true -Xmx256M -Xms256M"
CATALINA_PID="/usr/local/www/html/TOMCAT_DEMO/tomcat/webapps/UI_PID"
CATALINA_HOME="/usr/local/www/html/TOMCAT_DEMO/tomcat"
export JAVA_HOME JAVA_OPTS CLASSPATH CATALINA_PID CATALINA_HOME
rm -rf $CATALINA_HOME/work/Catalina/localhost
rm -rf $CATALINA_HOME/logs/*
rm -rf $CATALINA_HOME/content/thredds/logs/*
rm -rf $CATALINA_HOME/content/ras/conf/server/temp/*
rm -rf $CATALINA_HOME/webapps/ras/output/*.*
find $CATALINA_HOME/content/ras/conf/server/data -type f -exec rm \{} \;
#cp /home/weusijana/RAS_custom_scripts/*.jnl $CATALINA_HOME/content/ras/conf/server/data/scripts
#exec $CATALINA_HOME/bin/catalina.sh start
echo "Done. You can now start tomcat."

please anyone tell me how it can be done.
# 2  
Old 05-22-2013
If by "every 12 hours once" you mean once every 12 hours, you can run it via cron:
Code:
0 0,12 * * * /path/to/your/script

If you don't discard the output in the script, or in the cronjob, you should receive an email with the output. For more output, perhaps you want to use rm's -v option, depending on how many files you expect to be removed.

You may have to source .profile in the cronjob or in the script.
# 3  
Old 05-22-2013
Thank you Sir, it requires root password, what I need to do more ?
# 4  
Old 05-22-2013
Nothing in your script requires root password. You mean the script has to be run as root?

If that's the case, then the cronjob should be installed as root. Are those files not owned by the tomcat user?
# 5  
Old 05-22-2013
no sir..I had not created tomcat user...infact..till date running script as a root user...thank you for your help...if I have any difficulty I will interrupt you once again sir...
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Run the script continously but mail once in 1 hour

Hi, I have a script written for monitoring the queue manager status continously. below is the script. QMGR=`dspmq | awk '{print $1}' | cut -f2 -d "(" | cut -f1 -d ")"` QMSTATUS=`dspmq | awk '{print $2}' | cut -f2 -d "(" | cut -f1 -d ")"` count=`dspmq | awk '{print $1}' | cut -f2 -d "(" | ... (5 Replies)
Discussion started by: Anusha M
5 Replies

2. Shell Programming and Scripting

Shell script to be run every one hour

How can we run shell script every one hour. Anyone having code unit for this? (1 Reply)
Discussion started by: Pratiksha Mehra
1 Replies

3. Shell Programming and Scripting

variable has no value if run the script automatically/scheduled

Hi All, I am using ksh as the shell. I have a script that should store variable after executing "onstat" on informix. I can execute it successfully without any issue if run manually, however the value is not showing up when run automatically(scheduled). Is there anything needed to make the... (1 Reply)
Discussion started by: tungaw2004
1 Replies

4. Shell Programming and Scripting

How to run a script automatically

Hi All, How can i run a script every week automatically. Thanks & regards, Sam (5 Replies)
Discussion started by: sam25
5 Replies

5. Shell Programming and Scripting

Automatically run bash script

Hi! I want to run/execute a bash script automatically everytime when a specific file is created or when its timestamp changes. Is this possible? How? Thank you very much for your answers in advance, Regards, Christoph (1 Reply)
Discussion started by: ckofler
1 Replies

6. Shell Programming and Scripting

how to run shell script automatically

hi , i m trying to run bash scrip automaticially but i dont know how i can do this an anybody tell me how i can autorun shell script when i logon . thanks (9 Replies)
Discussion started by: tahir23
9 Replies

7. Shell Programming and Scripting

Run a script on the hour but only for 30mins

Hi All, I want to run a script on the hour during a 24 - hour period; easy enough cron will take care of that..however I want the script to only run for only 30mins.. so with the script it knows its 30mins are up so exits. any ideas? Any help, greatly appericated. Thanking you all... (2 Replies)
Discussion started by: Zak
2 Replies

8. UNIX for Dummies Questions & Answers

how to run a Script automatically

How to make a script run automatically using a cron?? i do not know abt cron...... if i have simple.sh file and i need this to run everyday at a particular time what needs to be done thanks in advance (4 Replies)
Discussion started by: hamsa
4 Replies

9. UNIX for Dummies Questions & Answers

How to run a script automatically ?????

Hi All, How to run a script automatically using cronjob everyday from Monday to Friday 9A.M to 5P.M at an interval of ONE HOUR.I want the complete syntax means how to put in the cron job and there after. URGENTLY NEED HELP THANKS IN ADVANCE CHEERS Arunava (7 Replies)
Discussion started by: arunava_maity
7 Replies
Login or Register to Ask a Question