[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

SCRIPT IN LINUX

Posted on 2005-05-10
7
Medium Priority
?
275 Views
Last Modified: 2010-04-22
I to Everybody.
I need an information.
I have just a little experience in Linux.
I would like to auto some operations that are running every morning.

Es. i need to auto STOP and START of TOMCAT at 4.50 a.m with normal command /etc/init.d/tomcat stop and copy CATALINA.out in CATALINA1.OUT, and after delete CATALINA.out, and after start Tomcat with command /etc/init.d/TOMCAT start.
It's possible? I think yes.... of course.

It's possible to have some example or help?
Thanks in advance.

0
Comment
Question by:CAVALLOSILF
  • 4
  • 3
7 Comments
 

Accepted Solution

by:
praseedgopal earned 750 total points
ID: 13967722
Hi,
      You can do that using a shell script and then after you can run it as cron job.
Steps :
1. Create a shell script file myshell.sh in the path as /tmp or where ever you wish  , type  the following in that file

#! /bin/bash

#To stop the tomcat
/etc/init.d/tomcat stop

#To copy  CATALINA.out to  CATALINA1.OUT & remove. All in one shot
mv CATALINA.out CATALINA1.OUT

#To run the tomcat
/etc/init.d/TOMCAT start

2. Save this file and make the file as executable using

chmod +x myshell

3. Edit /etc/crontab and add the following line the bottom of the file.

50 4 * * * /tmp/myshell.sh

4. Now restart crond daemon, using the command

/etc/init.d/crond restart

Now your task will run at 4:50 am everyday.




0
 

Author Comment

by:CAVALLOSILF
ID: 13967850
FANTASTIC !!!
Thank you very much!!
0
 

Author Comment

by:CAVALLOSILF
ID: 13969708
Dear praseedgopal
i have try to create exe file using

chmod +x myshell.sh but i haven't create....

i have create myshell.sh with using vi editor....

this is myshell.sh and are in /usr/local/tomcat5028/logs

#! /bin/bash
#To cp catalina.out
cp catalina.out catalina2.out

0
Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

 

Expert Comment

by:praseedgopal
ID: 13975303

First create myshell.sh using vi editor.
There is one correction in the step

mv CATALINA.out CATALINA1.OUT

Instead of giving CATALINA.out and CATALINA1.OUT, give absolute path of both these files.
Suppose if they are in /tmp/. Give as

mv /tmp/CATALINA.out /tmp/CATALINA1.OUT

and after saving the file, from console, run the command

chmod +x myshell.sh

this will make your script(myshell.sh) an executable one. Final script will look like.

#-----start----
#! /bin/bash
#To stop the tomcat
/etc/init.d/tomcat stop
#To copy  CATALINA.out to  CATALINA1.OUT & remove. All in one shot
mv /tmp/CATALINA.out  /tmp/ CATALINA1.OUT
#To run the tomcat
/etc/init.d/TOMCAT start
#-----end---

0
 

Author Comment

by:CAVALLOSILF
ID: 13975717
Ok, i have edit script by using vi, but i haven't create an executable after command:

chmod +x myshell.sh

i have also myshell.sh in path of creation an run script (only calling it?) having error:

-su: myshell.sh: command not found

0
 

Expert Comment

by:praseedgopal
ID: 13975971
On the moment you did the command chmod +x myshell.sh, it has turned to a executable file. There is no exe file concept in linux.

while running from same directory use ./myshell.sh not myshell.sh
 
0
 

Author Comment

by:CAVALLOSILF
ID: 13976040
oK, WITH LAST INDICATION I HAVE SOLVING THE PROBLEM!
Thanks a lot. Claudio.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Screencast - Getting to Know the Pipeline
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question