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
exit(1)                                                            User Commands                                                           exit(1)

NAME
exit, return, goto - shell built-in functions to enable the execution of the shell to advance beyond its sequence of steps SYNOPSIS
sh exit [n] return [n] csh exit [ ( expr )] goto label ksh *exit [n] *return [n] DESCRIPTION
sh exit will cause the calling shell or shell script to exit with the exit status specified by n. If n is omitted the exit status is that of the last command executed (an EOF will also cause the shell to exit.) return causes a function to exit with the return value specified by n. If n is omitted, the return status is that of the last command exe- cuted. csh exit will cause the calling shell or shell script to exit, either with the value of the status variable or with the value specified by the expression expr. The goto built-in uses a specified label as a search string amongst commands. The shell rewinds its input as much as possible and searches for a line of the form label: possibly preceded by space or tab characters. Execution continues after the indicated line. It is an error to jump to a label that occurs between a while or for built-in command and its corresponding end. ksh exit will cause the calling shell or shell script to exit with the exit status specified by n. The value will be the least significant 8 bits of the specified status. If n is omitted then the exit status is that of the last command executed. When exit occurs when executing a trap, the last command refers to the command that executed before the trap was invoked. An end-of-file will also cause the shell to exit except for a shell which has the ignoreeof option (See set below) turned on. return causes a shell function or '.' script to return to the invoking script with the return status specified by n. The value will be the least significant 8 bits of the specified status. If n is omitted then the return status is that of the last command executed. If return is invoked while not in a function or a '.' script, then it is the same as an exit. On this man page, ksh(1) commands that are preceded by one or two * (asterisks) are treated specially in the following ways: 1. Variable assignment lists preceding the command remain in effect when the command completes. 2. I/O redirections are processed after variable assignments. 3. Errors cause a script that contains them to abort. 4. Words, following a command preceded by ** that are in the format of a variable assignment, are expanded with the same rules as a vari- able assignment. This means that tilde substitution is performed after the = sign and word splitting and file name generation are not performed. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | |Availability |SUNWcsu | +-----------------------------+-----------------------------+ SEE ALSO
break(1), csh(1), ksh(1), sh(1), attributes(5) SunOS 5.10 15 Apr 1994 exit(1)
All times are GMT -4. The time now is 03:50 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy