Sponsored Content
Operating Systems AIX Script is not executing as expected when I schedule it in cron Post 302987086 by Nagaraj R on Monday 5th of December 2016 03:08:33 AM
Old 12-05-2016
Script is not executing as expected when I schedule it in cron

Hi,

I have a shell script which fetches the MRP status and the LAG status.

When I execute it manually like, sh <script_name>, it fetches the output as expected, but when I schedule through crontab, it's not working as expected.

Any help would be really appreciated.

Here is the code snippet:

Code:
for pass in $(cat /u/oracle/nagy/passwd.txt)
do

tns=`cat /u/oracle/nagy/passwd.txt | grep $pass | cut -d"@" -f2`
#env=`tnsping $tns | grep HOST | cut -d"-" -f2`
#env=$(echo ${env} | tr '[a-z]' '[A-Z]')
env=PROD
echo "Pass is: $pass"

if [[ "$tns" = "DR514" ]]; then
        echo "I am in IF Loop of LAG Check"
        status=`sqlplus -s "${pass} as sysdba" <<~EOF
        echo "After SQLPLUS in IF LAG CHECK"
        #set pages 999 long 90000 heading off
        SET MARKUP HTML ON SPOOL ON
        #spool /tmp/$FN
        echo "Spooling IF LAGCHECK"
        #@/u/oracle/nagy/check_loggap_DR514.sql
        #SET MARKUP HTML OFF SPOOL OFF
        #spool off
        spool /tmp/MRP_$tns.log
        echo "Spooling ID MRP"
        @/u/oracle/nagy/mrp.sql
        spool off
        exit;
        EOF`
else
        echo "I am in ELSE loop of LAG Check"
        status=`sqlplus -s "${pass} as sysdba" <<~EOF
        echo "After SQLPLUS in ELSE LAGCHECK"
        set pages 999 long 90000 heading off
        #SET MARKUP HTML ON SPOOL ON
        #spool /tmp/$FN
        echo ""Spooling ELSE LAGCHECK"
        #@/u/oracle/nagy/check_loggap.sql
        #SET MARKUP HTML OFF SPOOL OFF
        #spool off
        spool /tmp/MRP_$tns.log
        echo "Spooling ELSE MRP"
        @/u/oracle/nagy/mrp.sql
        spool off
        exit;
        EOF`
fi
done


The issue is, it's not getting into the line "status=`sqlplus -s "${pass} as sysdba" <<~EOF" at all, when I schedule it through cron, but manually it works.

Following is the sample output, when it's scheduled through crontab.

Code:
Pass is: sys/pr0t3ctSYS@DR508
I am in ELSE loop of LAG Check
Pass is: sys/pr0t3ctSYS@DR509_DG
I am in ELSE loop of LAG Check
Pass is: sys/pr0t3ctSYS@DR510
I am in ELSE loop of LAG Check
Pass is: sys/pr0t3ctSYS@DR511
I am in ELSE loop of LAG Check
Pass is: sys/pr0t3ctSYS@DR513
I am in ELSE loop of LAG Check
Pass is: sys/pr0t3ctSYS@DR514
I am in IF Loop of LAG Check


Please note that it's an AIX box.

Please help me out to get this rid of the weird situation and let me know if anything to be corrected in the script.
 

10 More Discussions You Might Find Interesting

1. HP-UX

executing shell script from the cron

This isn't the usual problem that a shell script runs from the command line and not the cron. It's a little different. Among other things, the shell scrip executes my .profile to set a bunch of variables. It then does an env to ensure that it ran OK. There are echos in the shell script and... (2 Replies)
Discussion started by: abNORMal
2 Replies

2. UNIX for Advanced & Expert Users

executing script by cron doesnt give me expected result

Hi frnds... I m facing very irritating problem already waisted my 2 days.. I have a following script..( i am pasting only the main code) ftp -ivn 213.194.40.77 <<FTP user $user $password binary cd $FileDir/out lcd $localpath get $file rename $FileDir/out/$file $FileDir/tmp/$file... (1 Reply)
Discussion started by: clx
1 Replies

3. Shell Programming and Scripting

Script doesn't work as expected when run on cron

The script checks for free space stats on Oracle. If there are any tablespaces with more than 85% usage it prints the details of the tablespace. If all the tablespaces have more than 15% free space, then "All tablespaces have more than 15 pct free space" must be printed on the screen. When I run... (2 Replies)
Discussion started by: RoshniMehta
2 Replies

4. Shell Programming and Scripting

General Q: how to run/schedule a php script from cron jobs maybe via bash from shell?

Status quo is, within a web application, which is coded completely in php (not by me, I dont know php), I have to fill out several fields, and execute it manually by clicking the "go" button in my browser, several times a day. Thats because: The script itself pulls data (textfiles) from a... (3 Replies)
Discussion started by: lowmaster
3 Replies

5. Shell Programming and Scripting

Problem with executing a shell script through the cron

Hi, I have a shell script as below: ORACLE_HOME=/usr/local/opt/oracle/product/dev export ORACLE_HOME PATH=$PATH:$ORACLE_HOME/bin:/usr/bin export PATH OUTFILE=/export/home/`basename $0`.out export OUTFILE export IDEN df -k . | tail -1 | read a b c d e f echo $a >> $OUTFILE echo $b... (4 Replies)
Discussion started by: Abhinav Pandey
4 Replies

6. Shell Programming and Scripting

Executing a script from CRON behaves differently than terminal

Hi have a script which transferers from Microsoft server to Linux box. The scripts(ksh) is on Linux box. If I run script from terminal, it transfers files to directory. Where as If I run script from CRON. It does not. Here is the log of both: Terminal execution log:... (2 Replies)
Discussion started by: dipeshvshah
2 Replies

7. Windows & DOS: Issues & Discussions

Schedule script is not executing some times

Dear Experts, Once again i need your vital help to fix my issue, please do the needfull. Issue:- I have schedule one script on windows server to run's every 10 min.(Script do check the alert log file,if database found down it send the email) While i'm doing the database down manually its... (12 Replies)
Discussion started by: Mohammed Fareed
12 Replies

8. Shell Programming and Scripting

Binary Operator expected while executing the below shell script.

Hi Experts, Iam bit poor in shell scripting, Here my requirement is for generating an alert where the oracle database db_recovery_file_dest_size usage. If it reaches beyond 80% should recieve an alert through an email. Want to schedule this alert in cron. #!/bin/bash .... (9 Replies)
Discussion started by: Jagadish m
9 Replies

9. Shell Programming and Scripting

Script not executing using cron

Hi, I created a script which connects to database and update a table. This script is running fine when i run it manually but when i am trying to execute it scheduling in crontab.script is executing but Data is not getting updated. below is my script sqlplus test/##### >> test_feed.log <<!... (6 Replies)
Discussion started by: sv0081493
6 Replies

10. Shell Programming and Scripting

Expect script not executing via cron

Hello All, I'm having an issue getting an expect script to run as a cron job. The script executes fin if I run it from the command line but I get nothing when trying to run it as a cron job. I've researched other forums and threads and there have been references to the environment, or lack... (16 Replies)
Discussion started by: KingT617
16 Replies
PRINTENV(1)						    BSD General Commands Manual 					       PRINTENV(1)

NAME
printenv, env -- print out the environment, set and print environment SYNOPSIS
printenv [name] env [-i] [name=value ...] [utility [argument ...]] DESCRIPTION
The printenv utility prints out the names and values of the variables in the environment, with one name/value pair per line. If name is specified, only its value is printed. Some shells may provide a builtin printenv command which is similar or identical to this utility. Consult the builtin(1) manual page. The env utility executes utility after modifying the environment as specified on the command line. The option name=value specifies an envi- ronment variable, name, with a value of value. The options are as follows: -i Execute the utility with only those environment values specified. The environment inherited by env is ignored completely. If no utility is specified, env prints out the names and values of the variables in the environment, with one name/value pair per line. The env utility is sometimes useful with the ``#!'' construct (see execve(2)). The only difference between ``#!/usr/local/bin/foo'' and ``#!/usr/bin/env /usr/local/bin/foo'' is that the latter works even if /usr/local/bin/foo is itself interpreted. Using env this way also allows one to reference foo without the path, as well as set up the environment as desired. ENVIRONMENT
The env utility uses the PATH environment variable is used to locate the requested utility if the name contains no '/' characters. DIAGNOSTICS
The printenv utility exits 0 on success, and >0 if an error occurs. The env utility exits 0 on success, and >0 if an error occurs. An exit status of 126 indicates utility was found, but could not be executed. An exit status of 127 indicates utility could not be found. COMPATIBILITY
The env utility accepts the - option as a synonym for -i. SEE ALSO
csh(1), sh(1), execvp(3), environ(7) STANDARDS
The env utility conforms to IEEE Std 1003.1-2001 (``POSIX.1''). HISTORY
The printenv command appeared in 3.0BSD. BUGS
The env utility doesn't handle utility arguments with equal (``='') signs in their names, for obvious reasons. BSD
June 6, 1993 BSD
All times are GMT -4. The time now is 10:06 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy