Help with shell script - Calling a script through script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with shell script - Calling a script through script
# 1  
Old 04-18-2011
Help with shell script - Calling a script through script

Hi,

I have written a shell script to grep a certain parameter and send a mail if they found any. Now i want this script to call another script which will restart my application.

Here is my script
Code:
#!/bin/sh

DATE=`date +%Y%m%d%H%M%S`
HOME=/home/dumbren/vfnz_data/AMS_report
LOG_DIR=/apps/prod/vfonline/weblogic100/domains/vfop6dom/servers/ams-stream1-svr1/logs
JKIT=/apps/prod/vfonline/weblogic100/domains/vfop6dom/servers/ams-stream1-svr1
CONSOLE_FILE=console.log.20110405175955
ALERTS_FILE=alerts_ejb1.log.1
CONSOLE_OUTPUT=/home/dumbren/vfnz_data/console
ALERTS_OUTPUT=/home/dumbren/vfnz_data/alerts
APPLICATION_PID=`ps -ef | grep "ams-1" | grep -i java |awk '{ print $2 }'`

#-------------------------------------------------------------------------------------------------------
#
# To find exception "OutOfMemory" in logs and restart application if we found any
#
#-------------------------------------------------------------------------------------------------------

cd $LOG_DIR
tail -f $CONSOLE_FILE > $CONSOLE_OUTPUT &

grep "java.lang.OutOfMemoryError" $CONSOLE_FILE > $CONSOLE_OUTPUT

sleep 10

`ps -ef | sed -n '/tail/{/grep/!p;}' | grep "console.log" |awk '{print$2}' | xargs -i kill {}`

sleep 10

a=`ls -lrth $CONSOLE_OUTPUT |awk '{print$5}'`

if [ $a -eq 0 ];
then
     echo "The file is empty"
else
     echo "The Vaule of A differs, please check"
     #/usr/bin/printf "*****  AMS ALERT - $DATE *****\n\nHost: `hostname` \n\nDATE: `date` \n\n" | /bin/mail -s " AMS Error $DATE  " user@dom.com
m < /home/dumbren/console
fi

exit 0

here is it find any exception then it should directly call the other script "./ams_rc stop" which will stop application and then will start the same with same script "./ams_rc start"

Regards,
SiddheshK

Moderator's Comments:
Mod Comment Please use [code] and [/code] tags when posting code, data or logs etc. to preserve formatting and enhance readability, thanks. Also replace your email address with some dummy address next time, ty.

Last edited by zaxxon; 04-18-2011 at 06:28 AM.. Reason: code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Calling a script from master script to get value from called script

I am trying to call a script(callingscript.sh) from a master script(masterscript.sh) to get string type value from calling script to master script. I have used scripts mentioned below. #masterscript.sh ./callingscript.sh echo $fileExist #callingscript.sh echo "The script is called"... (2 Replies)
Discussion started by: Raj Roy
2 Replies

2. Shell Programming and Scripting

Calling shell script within awk script throws error

I am getting the following error while passing parameter to a shell script called within awk script. Any idea what's causing this issue and how to ix it ? Thanks sh: -c: line 0: syntax error near unexpected token `newline' sh: -c: line 0: `./billdatecalc.sh ... (10 Replies)
Discussion started by: Sudhakar333
10 Replies

3. Shell Programming and Scripting

calling a shell script present on another server using perl script.

Hi, I am working on a sever A. I want to write a perl script to execute a shell script persent on the server B. please help me in this. thanks in advance. (3 Replies)
Discussion started by: anandgodse
3 Replies

4. Shell Programming and Scripting

How we can pass the argument when calling shell script from perl script

Can someone let me know how could I achieve this In one of per script I am calling the shell script but I need to so one thing that is one shell script call I need to pass pne argument.In below code I am calling my ftp script but here I want to pass one argument so how could I do this (e.g:... (5 Replies)
Discussion started by: anuragpgtgerman
5 Replies

5. Shell Programming and Scripting

Error in calling a shell script from another script

HI, We are using two shell scripts, script.sh,env.sh, where env.sh will be called inside script.sh. The variable inside env.sh is used as $var in script.sh.But while running the script its not identifying that variable. Is there any permission needed to call a script inside another script. ... (3 Replies)
Discussion started by: banupriyat
3 Replies

6. Shell Programming and Scripting

Syntax error calling TCL script from shell script

hello everyone i am beginner on shell scripting .and i am working on my project work on ad hoc network i wrote a batch (.sh) to do a looping and execute a tcl script i wrote before in each iteration ..but i got this problem " syntax error near unexpected token `('... (1 Reply)
Discussion started by: marcoss90
1 Replies

7. Shell Programming and Scripting

Calling a shell script from a perl script

Hi, I have one shel script which returns some value and I am calling this shell script from a perl script which needs the out put/return value of shell script. But I don't know how to collect the output/return value of the shell script. Can any one give some idea on it? For example: The... (1 Reply)
Discussion started by: siba.s.nayak
1 Replies

8. Shell Programming and Scripting

How to return the value from the called shell script to the calling sh script

Hi all, I have two ksh scripts #sample1.sh #!/bin/ksh . ./sample2.sh echo $fileExist #sample2.sh #!/bin/ksh func() { i=1 return $a } func echo $? Here how should I return the value of sample2.sh back to sample1.sh? Thanks in advance. (2 Replies)
Discussion started by: gp_singh
2 Replies

9. Shell Programming and Scripting

Box A's perl script calling box B's shell script

Hi all, i have a perl script one server. I am running a cronjob to execute my perl script. #! /usr/bin/perl ... ... ... #call a shell script on another server How can i accomplish #? Do i have to issue a system (" ssh -l username server | shellscript.sh") in my shell script? or is there a... (1 Reply)
Discussion started by: new2ss
1 Replies

10. Shell Programming and Scripting

calling dos2unix on shell script from within the script

I have a build script. It was created on Linux. For some reason, I got it to windows and modified it. And brought it back again to Linux. Since there is the question of the ^M chars appearing, the way out is to do a dos2unix on the script file. This is done manually. Is there a way to call... (4 Replies)
Discussion started by: vino
4 Replies
Login or Register to Ask a Question