Sponsored Content
Top Forums Shell Programming and Scripting Script not working in crontab Post 302683751 by Corona688 on Wednesday 8th of August 2012 12:37:24 PM
Old 08-08-2012
Why is this in backticks?
Code:
`$ESAHOMEINSTALL/ESA/bin/reportEvent raise APP 1 .1.1.1.3 "Messaging Server Down"`

What is it, anyway? It may be the thing that's demanding a terminal, since I don't see much else that would.

There's some worryingly long pipe chains in there. You can reduce that in lots of ways.

1) You don't need wc -l to check if grep found anything. grep returns a code like any other program.

2) If you have grep | sed | grep | kitchen | sink, you can reduce that by putting them all in one awk call.

3) You're using functions in /bin/sh. /bin/sh is not guaranteed to have functions. Use ksh or bash if you really need functions.

4) You're not using functions in a way that really organizes your program anyway.

5) You're not using if/elif/else properly, nesting more if's inside instead of using elif.

Code:
if ps -ef | awk '/java/ && /[mM][sS]1@[iI][pP][xX][.][cC][oO][mM]/ { exit 0 } END { exit 1 }'
then
        echo "MS is down, please check"
        # What application is this?  Is it supposed to be interactive?
        $ESAHOMEINSTALL/ESA/bin/reportEvent raise APP 1 .1.1.1.3 "Messaging Server Down"
elif $ESAHOMEINSTALL/ESA/bin/printActiveAlarms | grep "Messaging Server Down" >/dev/null
then
	$ESAHOMEINSTALL/ESA/bin/reportEvent clear APP 1 .1.1.1.3 "Messaging Server Down"
else
        # Why?
        echo " "
fi


if ps -ef | awk '/java/ && /[nN][aA][mM][eE]=[tT][rR][aA][fF]_[sS][vV][rR]/ { exit 0 } END { exit 1 }'
then
        echo "TS is down.. Please check "

      $ESAHOMEINSTALL/ESA/bin/reportEvent raise APP 2 .1.1.1.3 "Traffic Server Down"

elif $ESAHOMEINSTALL/ESA/bin/printActiveAlarms | grep "Traffic Server Down" >/dev/null
then
        $ESAHOMEINSTALL/ESA/bin/reportEvent clear APP 2 .1.1.1.3 "Traffic Server Down"
else
        # why?
        echo " "
fi

These 2 Users Gave Thanks to Corona688 For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script is not working when put in crontab

Hi there, this is part of my script: /usr/bin/cd /u01/oradata /usr/bin/cp `/bin/ls -1 . |grep -v "^DIMStemp01.dbf$" | grep -v "^DIMSts01.dbf$"|grep -v "^DIMStects01.dbf$"` /backup It's working fine when I manually run on telnet session. /bin/ls -1 . -- to list all the files inside... (2 Replies)
Discussion started by: *Jess*
2 Replies

2. Shell Programming and Scripting

script not working from crontab, executes individual

Hi, This script is working successfully when i executed from shell prompt, but the same script scheduled in crontab its not deleting the files, #! /bin/bash DAY_1=`(date --date='4 months ago' '+%Y-%m')` log=/tmp/cleant adir=/u01/app/oracle/admin/talon/adump... (4 Replies)
Discussion started by: saha
4 Replies

3. Shell Programming and Scripting

Expect Script Not working with Crontab

I have the following expect script sitting on a Linux box. === #!/usr/bin/expect -f # # backup.expect # # Expect script to backup a firewall via a SSH session # # set firewall set username set password set prompt set filename match_max 50000 spawn ssh -l... (2 Replies)
Discussion started by: alagondar
2 Replies

4. Shell Programming and Scripting

My script stops working when using crontab

I have made a shell script(/bin/sh) that starts a perl script (that I haven't made my self) that's starts a ssh session. The ssh session uses a private/public key to login so no password is needed. The Perl script works perfect. But when I put it in a cronjob (crontab) the ssh connection asks... (6 Replies)
Discussion started by: splinter_cell
6 Replies

5. UNIX for Dummies Questions & Answers

Script is not longer working in the crontab

This is the crontab it is supossed to be running everyday but it didnt 5 0 * * * /export/app/CO/opge/scr/Informe_parametros_colombia.ksh >/dev/null 2>&1 Inside the above script connects to a database and extract data to a flat file, manually i run the script at about 2 a.m. and Works OK,... (6 Replies)
Discussion started by: alexcol
6 Replies

6. Shell Programming and Scripting

Expect script not working in crontab with minicom

Hi All, I am testing expect script in command prompt without issue, but in crontab it is not working, i check the output error as below: #cat /var/log/testexp.log spawn minicom -C /var/log/minicom1.log No cursor motion capability (cm) AT+COPS=? I am new in scripting, together... (1 Reply)
Discussion started by: elingtey
1 Replies

7. Red Hat

Script not working if crontab scheduled

Hi all, I'm working to a script with /bin/bash shebang. The script works perfectly if I run from command line. The script runs under a non root user and inside the commands are set with sudo command in a such a way they can be run under root, for example (first rows of the script):... (5 Replies)
Discussion started by: idro
5 Replies

8. Shell Programming and Scripting

Script not working via crontab

Hi, I have written one script which is connecting to the the database and generating one CSV, it is running fine when i ran it manually though it is throwing any warning but CSV is generating and working fine but same script when i have configured in crontab not working and giving error, kindly... (6 Replies)
Discussion started by: ash12345
6 Replies

9. Shell Programming and Scripting

Script not working via crontab

Hi, I have written one script which is connecting to the the database and generating one CSV, it is running fine when i ran it manually though it is throwing any warning but CSV is generating and working fine but same script when i have configured in crontab not working and giving error, kindly... (1 Reply)
Discussion started by: ash1234
1 Replies

10. Red Hat

Linux ksh script not working in crontab

I am Not sure why following script is not capturing the counts only when using crontab !! when I run it fromt he command line it is fine ! what is missing here ! #!/usr/bin/ksh host=`uname -n` tdate=`date` userid='dbid/password' totalevents=`sqlplus -s $userid << - set timing off ... (1 Reply)
Discussion started by: mrn6430
1 Replies
getusershell(3C)					   Standard C Library Functions 					  getusershell(3C)

NAME
getusershell, setusershell, endusershell - get legal user shells SYNOPSIS
#include <unistd.h> char *getusershell(void); void setusershell(void); void endusershell(void); DESCRIPTION
The getusershell() function returns a pointer to a legal user shell as defined by the system manager in the file /etc/shells. If /etc/shells does not exist, the following locations of the standard system shells are used in its place: /bin/bash /bin/csh /bin/jsh /bin/ksh /bin/ksh93 /bin/pfcsh /bin/pfksh /bin/pfsh /bin/sh /bin/tcsh /bin/zsh /sbin/jsh /sbin/pfsh /sbin/sh /usr/bin/bash /usr/bin/csh /usr/bin/jsh /usr/bin/ksh /usr/bin/ksh93 /usr/bin/pfcsh /usr/bin/pfksh /usr/bin/pfsh /usr/bin/sh /usr/bin/tcsh /usr/bin/zsh /usr/sfw/bin/zsh /usr/xpg4/bin/sh The getusershell() function opens the file /etc/shells, if it exists, and returns the next entry in the list of shells. The setusershell() function rewinds the file or the list. The endusershell() function closes the file, frees any memory used by getusershell() and setusershell(), and rewinds the file /etc/shells. RETURN VALUES
The getusershell() function returns a null pointer on EOF. BUGS
All information is contained in memory that may be freed with a call to endusershell(), so it must be copied if it is to be saved. NOTES
Restricted shells should not be listed in /etc/shells. SunOS 5.11 1 Nov 2007 getusershell(3C)
All times are GMT -4. The time now is 09:21 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy