Operating System - HP-UX
1819874 Members
2792 Online
109607 Solutions
New Discussion юеВ

Shell scripts fails on Autosys but works when run manually

 
SOLVED
Go to solution
Suman_7
Frequent Advisor

Shell scripts fails on Autosys but works when run manually

I have a simple problem:

I have a shell script that runs every day from Autosys as user auto_user

The script is like this:

###############################

export FILE_DIR=${TOP}/bin
PWD=`<${FILE_DIR}/pwd.txt`

#################################


$TOP is set in the .profile of the auto_user

and autouser has wrx on pwd.txt

What is happending is that when the script runs from Autosys it tries to look for the pwd.txt file from /bin/pwd.txt

Here is the Autosys log:

/home/bin/run_ftp.ksh[24]: /bin/ncadmin_pwd.txt: cannot open












10 REPLIES 10
Patrick Wallek
Honored Contributor

Re: Shell scripts fails on Autosys but works when run manually

You need to set the value of TOP within the script itself, or have it in another file somewhere and source that file from within the script.

If I remember autosys functions correctly, it does NOT actually log in as a user, thus it doesn't get anything that is set within the .profile.

Best practice with any scripts that are run via a scheduler is to either 1) set the value of all variables within the script, or 2) have all variables in another file and source that file from within the script.

Pete Randall
Outstanding Contributor

Re: Shell scripts fails on Autosys but works when run manually

Sounds very similar to cron to me. I suspect that Autosys doesn't source the user's profile. Try putting ". /home/autouser/.profile" into the script.


Pete

Pete
RAC_1
Honored Contributor

Re: Shell scripts fails on Autosys but works when run manually

Why to complicate the things??
Why not just /full_path_of_pwd.txt??

Also typo in your code

export FILE_DIR=${TOP}/bin
PWD=`<${FILE_DIR}/pwd.txt`

< should not be there.
or
PWD='${TOP}/bin/pwd.txt'

Anil
There is no substitute to HARDWORK
RAC_1
Honored Contributor

Re: Shell scripts fails on Autosys but works when run manually

Have you exported the TOP in user's profile??

Within your script, echo $TOP should give you what you have specified in .profile of the user.

Anil
There is no substitute to HARDWORK
Suman_7
Frequent Advisor

Re: Shell scripts fails on Autosys but works when run manually

'<' in the script is correct as the program is supposed to read from the pwd.txt file and not to execute it.

But if I hardcode the path in the program further down the script fails to get the sqlplus uitility. I think its because $ORACLE_HOME is also not set for the autouser.


Thanks
Suman_7
Frequent Advisor

Re: Shell scripts fails on Autosys but works when run manually

Pete,

I tried to exeute the .profile in my script by putting:. /home/autouser/.profile

It gives this error in the log file


Not a terminal
^M^[[3g^M ^[H ^[H ^[H ^[H ^[H ^[H
^[H ^[H ^[H^MNot a terminal
^M^[[3g^M ^[H ^[H ^[H ^[H ^[H ^[H
^[H ^[H ^[H^M/data/bin/pwd.txt
Pete Randall
Outstanding Contributor

Re: Shell scripts fails on Autosys but works when run manually

Those errors are because of terminal related lines in the .profile. You can ignore them or modify the .profile to only execute those lines when a terminal is associated with it - like this:

if [[ -t 0 ]]
then
eval ` tset -s -Q `
stty erase "^H" kill "^U" intr "^C" eof "^D"
stty hupcl ixon ixoff
stty susp ""
stty dsusp ""
tabs
fi



Pete

Pete
Suman_7
Frequent Advisor

Re: Shell scripts fails on Autosys but works when run manually

Pete thanks for your reply.

I wanted to ask you one more question:

The script runs as follows by the autosys

1. user "auto" is the actual autosys user
2. user "auto" logs in as "auto_user" and then exeucte the shell script.
3. auto_user owns the shell script



If I modify the .profile of auto_user and try to execute the .profile file in the beginning of the program will it work?

I don't have access to autosys so i am asking you this question.



Thanks
Pete Randall
Outstanding Contributor
Solution

Re: Shell scripts fails on Autosys but works when run manually

Yes, I believe that will work. Make a backup copy of the .profile just in case.


Pete

Pete
curt larson_1
Honored Contributor

Re: Shell scripts fails on Autosys but works when run manually

sounds like the environment that the command runs in hasn't been set up properly. For autosys the commands are executed in the environment defined inthe profile script. That is either the autosys default /etc/auto.profile, or the one specified in the job definition (which you can define and which preempts the default file).

the profile attribute specifies the file to be sourced by the shell before the specified command is execture. The autosys remote agent always spawns a process and starts the shell in that process, passing it the name of the profile to be sources. this profile typically includes definintons and exports of environment variables, which can be referenced in the job's command. the primary environmnet variable in the profile is the $PATH. if a profile is not specified, the default autosys profile, /etc/auto.profile, is used. if the profile attribute is specified, that profile is searched for on the machine on which the command is to run.

if a command that normally executes when entered at the command line fails when run as an autosys job, it is usually due to the incomplete specification of the required environment for the command in the autosys profile file.