AIX

AIX

Connect with fellow AIX users and experts to gain knowledge, share insights, and solve problems.


#Power
#Power
 View Only
  • 1.  Odd behaviour in AIX Shell scripts

    Posted Thu October 22, 2009 06:46 PM

    Originally posted by: Mehrdad


    Hi Gurus
    We have recently migrated a bunch of shell scripts from Solaris 8 to AIX 5.3 .
    The problem is we are experiencing some odd behavior with shell scripts on the new platform that we have no clue where they are coming from.
    First of all the issues I'm explaining below are intermittent, and we can't always recreate the problem.

    Issue 1) The process exit value gets lost in the next statement:
    
    #!/bin/sh grep 
    "text" /a/file 
    
    if [ $? -eq 
    "0" ]; then 
    
    do something; fi
    


    Eventually $? does not always reflect the correct exit value of "grep"; this is script is being called by a custom scheduler engine written in C and ported to AIX. the scheduler uses "system()" function to execute the script.
    The odd is script works perfectly fine when we call is from shell; but when it gets called from the C app, it fails to get the correct exit value intermittently.
    The problem is not just with grep, we have had the same issue with oracle's sqlplus program.

    Issue 2) I/O doesn't seem to be in sync in consecutive create and test statements:
    
    #!/bin/sh ls -ntr /dir > filelist.lst 
    
    if [ ! -f 
    "filelist.lst" ]; then 
    
    do something; fi
    


    The above script has a similar problem to the one in issue #1, the "-f" test fails intermittently when the script gets called by AIX cron daemon. We have never managed to get it fail when calling the script from within standard shell.

    I'm not sure if it is something related to AIX AIO servers or shell implementation; but there's obviously something wrong in our setup that I'm seeking your advice for.

    Thanks in advance.
    #AIX-Forum


  • 2.  Re: Odd behaviour in AIX Shell scripts

    Posted Fri October 23, 2009 07:40 AM

    Originally posted by: SystemAdmin


    Issue 1, will look into later. Need more time on this.

    Issue 2, what I think is that since you are executing from cron....cron does not have environment variables. So trying changing all the relative path names to absolute paths and check if the problem still persists.

    Eg, ls -ntr /dir > /home/user01/filelist.lst
    if http:// ! -f /home/user01/filelist.lst ; then

    And also ensure that the user has permissions to write to the directory where filelist.1st is being created.

    r/
    R
    #AIX-Forum


  • 3.  Re: Odd behaviour in AIX Shell scripts

    Posted Fri October 23, 2009 07:41 AM

    Originally posted by: SystemAdmin


    Oh I do not know how that changed to http.....but the idea is to use absolute paths

    r/
    R
    #AIX-Forum


  • 4.  Re: Odd behaviour in AIX Shell scripts

    Posted Fri October 23, 2009 11:26 AM

    Originally posted by: Montecarlo


    As far as issue 1 is concerned I would suspect your scheduler.
    Just curious, why are you using sh rather than ksh? I thought ksh was the aix default shell.
    For both problems you might try the following:
    Run the script in debug mode and dump the environment at the beginning of script execution. Do this on the command line and in the scheduler or cron and compare the outputs.
    Regards, Simon
    #AIX-Forum


  • 5.  Re: Odd behaviour in AIX Shell scripts

    Posted Tue October 27, 2009 07:10 PM

    Originally posted by: Mehrdad


    Thanks for your replies, as I've insisted in my original post, the problem is intermittent; i.e. we can't recreate the problem as we wish.
    so if there are any issues with file permissions or path information, the script should break everytime we run it.
    These scripts were working as part of a complex solution on Solaris for over 10 years; so I'm sure the original developers have taken care of first class development standards.
    in terms of sh instead of ksh; the reason being is its a legacy code migrated from Solaris and we assumed sh should behave the same way in AIX.
    #AIX-Forum


  • 6.  Re: Odd behaviour in AIX Shell scripts

    Posted Wed October 28, 2009 07:06 AM

    Originally posted by: nh4aix


    Hi.. just a word about "sh" vs "ksh". On AIX, the default shell is ksh. What this means is that /usr/bin/sh is a hard link to /usr/bin/ksh (check out ls -il /usr/bin/sh /usr/bin/ksh). I am not a Solaris expert, but I thought that the default shell on Solaris was the born shell (bsh). I would recommend changing your first line to state explicitly what shell you were using on Solaris bsh (/usr/bin/bsh) or C Shell (/usr/bin/csh), etc.. Although bsh and ksh are very similar, they are not 100% the same.

    Good luck..
    joe
    #AIX-Forum


  • 7.  Re: Odd behaviour in AIX Shell scripts

    Posted Thu October 29, 2009 11:37 PM

    Originally posted by: Mehrdad


    I found an interesting thread related to issue #1, seems its almost certainly the system() function implementation causing trouble in AIX:
    bug-m4@gnu.org/msg02639.html">http://www.mail-archive.com/bug-m4@gnu.org/msg02639.html

    Re the default shell in Solaris, its definitely /usr/bin/sh and not bash (sizes are hugely different). is there anyway that I could find an equivalent/compatible implementation of Solaris's /usr/bin/sh in AIX? would bsh do better than ksh in terms of compatibility?

    Cheers
    Mehrdad
    #AIX-Forum