cancel
Showing results for 
Search instead for 
Did you mean: 

running web dispatcher from crontab

Former Member
0 Kudos

We would like to schedule stopping and starting the web dispatcher from a cron job. The script works fine when run manually from the command line, but sapwebdisp fails to start when run from cron. This led me to believe there was an issue with environment variables, so at the top of the script I set all of the same environment variables as the user who can successfully run the script manually. The script still fails to start sapwebdisp when run from cron, and there does not seem to be any output or logs from sapwebdisp or cron which would indicate the cause of the issue.

Has anyone else tried to schedule sapwebdisp from cron or does anyone have any insight into the possible cause of this problem?

Accepted Solutions (0)

Answers (6)

Answers (6)

Former Member
0 Kudos

I did check the mails that were resulting but there wasn't anything helpful in there. I added the "set -x" to the script so that it would produce some output at every step in the mail. I did have the output redirected previously to null because if it worked I didn't want to get the mail every time, but I think you are right I should redirect it to a file now and see if it gives any additional output. I think I will get the same result as what is in the mail but it is worth a shot. Echo would probably be a good idea to try also.

I really appreciate all of your help on this.

Former Member
0 Kudos

I apologize if I misunderstood your question, but I did use "crontab -e" to edit the crontab.

I know the changes to crontab took effect because the script does run when scheduled from cron. The problem is even though it runs it does not successfully start the web dispatcher when run from cron. In other words the last two lines of the script fail to do what they do when the script is run manually, which is start the dispatcher. And I do not see anything in the logs or receive any error indicating why.

Former Member
0 Kudos

Thanks again for clarifying. So one more thing has been ruled out.

For now two other quick guesses come to my mind:

What is the real name of your script that you called myscript.sh above in your crontab entry? It isn't by any chance something like sapwebdisp.sh ? if so, it would fall victim to your kill command.

This line looks strange:

if \"$2\" = \"cron\" || \"$1\" = \"cron\" ; then

I don't think that's correct Bourne shell syntax.

Or maybe the display is wrong. Please use tags!

regards

Former Member
0 Kudos

Thank you so much for all of your responses on this issue, I really appreciate the help.

The name of the script is webdispdown.sh.

I took all of the lines setting environment vars from the .profile of the user that runs the script. I think when I posted it here some extra slashes were added as escape characters or something because I noticed part of it turned into a link. I did not know about the code tags because I am a newbie here but I will repost or edit the previous post if possible.

Former Member
0 Kudos

Here is the code reposted:


# if the --cron flag exists we are running from cron, load .profile env vars
if [ "$2" = "--cron" ] || [ "$1" = "--cron" ]; then
    set -x
    PATH=/usr/bin:/usr/sbin:/sbin:/usr/openwin/bin:/etc/opt/SUNWconn/trunking/bin:/usr/ccs/bin:/usr/sfw/bin
    export PATH
    MANPATH=/opt/SUNWconn/trunking/man:/usr/man:/usr/share/man
    export MANPATH
    ZNAME=`zonename | tr [:lower:] [:upper:]`
    USER=<userid>
    export USER
    PS1="\[\e[31;1m\]${ZNAME} ZONE: \[\e[36;1m\]\u@\[\e[32;1m\]\H> \[\e[0m\]"
    export PS1
    SECUDIR=/usr/sap/<SID>/sapwebdisp/sec
    TERM=dtterm
    export SECUDIR TERM
    LD_LIBRARY_PATH=/usr/sap/<SID>/sapwebdisp
    export LD_LIBRARY_PATH
    JAVA_HOME=/opt/local/j2sdk1.4.2_13
    SAP_JRE_INST=/opt/local/j2sdk1.4.2_13
    export SAP_JRE_INST JAVA_HOME
fi

# get the PID and kill the process
ps -ef | grep sapwebdisp | grep -v grep | awk '{print$2}' | xargs -I{} kill -9 {}

<perform other tasks>

# start the dispatcher
# these are the first 2 lines from /usr/sap/<SID>/sapwebdisp/startWD
/usr/sap/<SID>/sapwebdisp/sapwebdisp pf=/usr/sap/<SID>/sapwebdisp/sapwebdisp.pfl -cleanup
/usr/sap/<SID>/sapwebdisp/sapwebdisp pf=/usr/sap/<SID>/sapwebdisp/sapwebdisp.pfl -f /usr/sap/<SID>/sapwebdisp/trace.txt &

Former Member
0 Kudos

Well, I am afraid now I am running out of good (and even not so good) guesses.

So I think you should try to get some output from your script, to debug it.

You wrote you checked log files. Output from cron often goes to mail, either for root, or the user running it. Did you check that?

Then I think you should add a few helpful commands like echo, date or ps to your script, and redirect output, that is change your crontab entry to something like:

... /full/path/to/myscript.sh --cron >/tmp/myprot 2>&1

hope this helps

Former Member
0 Kudos

This is basically what the script does. It stops the running sapwebdisp, performs some other action, then starts the dispatcher again. It works when run manually, but not when run from cron.

This is what it looked like before I tried to add the environment variables:

  1. get the PID and kill the process

ps -ef | grep sapwebdisp | grep -v grep | awk '{print$2}' | xargs -I{} kill -9 {}

<performs other actions>

  1. start the dispatcher

  2. these are the first 2 lines from /usr/sap/<SID>/sapwebdisp/startWD

/usr/sap/<SID>/sapwebdisp/sapwebdisp pf=/usr/sap/<SID>/sapwebdisp/sapwebdisp.pfl -cleanup

/usr/sap/<SID>/sapwebdisp/sapwebdisp pf=/usr/sap/<SID>/sapwebdisp/sapwebdisp.pfl -f /usr/sap/<SID>/sapwebdisp/trace.txt &

This is what it looks like after I tried to add environment variables hoping it would fix the problem:

  1. if the --cron flag exists we are running from cron, load env vars

if [ "$2" = "cron" ] || [ "$1" = "cron" ]; then

set -x

PATH=/usr/bin:/usr/sbin:/sbin:/usr/openwin/bin:/etc/opt/SUNWconn/trunking/bin:/usr/ccs/bin:/usr/sfw/bin

export PATH

MANPATH=/opt/SUNWconn/trunking/man:/usr/man:/usr/share/man

export MANPATH

ZNAME=`zonename | tr [:lower:] [:upper:]`

USER=<username>

export USER

PS1="\[\e[31;1m\]$ ZONE: \[\e[36;1m\]\u@\[\e[32;1m\]\H> \[\e[0m\]"

export PS1

SECUDIR=/usr/sap/<SID>/sapwebdisp/sec

TERM=dtterm

export SECUDIR TERM

LD_LIBRARY_PATH=/usr/sap/<SID>/sapwebdisp

export LD_LIBRARY_PATH

JAVA_HOME=/opt/local/j2sdk1.4.2_13

SAP_JRE_INST=/opt/local/j2sdk1.4.2_13

export SAP_JRE_INST JAVA_HOME

fi

  1. get the PID and kill the process

ps -ef | grep sapwebdisp | grep -v grep | awk '{print$2}' | xargs -I{} kill -9 {}

  1. start the dispatcher

  2. these are the first 2 lines from /usr/sap/<SID>/sapwebdisp/startWD

/usr/sap/<SID>/sapwebdisp/sapwebdisp pf=/usr/sap/<SID>/sapwebdisp/sapwebdisp.pfl -cleanup

/usr/sap/<SID>/sapwebdisp/sapwebdisp pf=/usr/sap/<SID>/sapwebdisp/sapwebdisp.pfl -f /usr/sap/<SID>/sapwebdisp/trace.txt &

Former Member
0 Kudos

Hello James,

thanks for clarifying;

but there is one question still not quite clear. You edited the crontab entry of user testuser. But how did you did that?

Depending on your flavour of Unix (what is it btw?), testuser's crontab entries are stored in a file, for example in /usr/spool/cron/crontab/testuser. You may edit this file, let's say using vi. But cron will not take notice of your changes, it will still use the old entries.

If you want your changes to be used, you will either have to restart cron, or use a different command, like crontab -e. man crontab for details.

So please make sure cron will take notice!

regards

Former Member
0 Kudos

You are correct, I did not provide enough details - I apologize for that. Let me see if I can make it more clear.

1) As which user?

I have added the script to the crontab of the same user who can run the script from the command line, for the sake of this discussion let's call it testuser.

2) How did you change crontab?

I added one record to the crontab to run the script at a specified time, i.e.:

30 1 18 10 * /full/path/to/myscript.sh --cron

3) How did I define the environment variables?

I copied the way it was being done in the .profile, with some minor modification to prevent errors when the script is running.

4) Which shell am I using?

The script is using the Bourne shell.

I don't know if there is a character limit so I am going to post another post with the basic contents of the script.

Former Member
0 Kudos

Rather than doing that I just loaded the environment variables directly in the script, but it didn't help. Unfortunately I don't think adding them to root's .profile will be an option.

Former Member
0 Kudos

You didn't tell us much about how you are trying with cron.

  • As which user? Try as the same user who can run it from comandline, i.e. not as root.

  • How did you change crontab? Details vary among the various flavours of Unix. There are ways that will not come into effect immediately.

  • The ways how to correctly define environment variables in a script vary among the various flavours of Unix shells. For example export may be necessary.

  • Which shell are you using for your script? Unless specified otherwise cron will start the script with Bourne shell in most Unixes, or perhaps bash in Linux.

regards

Edited by: Joe Bo. on Oct 19, 2009 3:17 PM

(typo)

Former Member
0 Kudos

You may want to add these environment variables to .profile file for the user running the cron e.g. root user