AIX

AIX

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


#Power
 View Only
Expand all | Collapse all

Calling dsh from shell script seems to finish the shellscript directly after the dsh call

  • 1.  Calling dsh from shell script seems to finish the shellscript directly after the dsh call

    Posted Fri February 18, 2022 09:07 AM
    Hello all,
    i am new to AIX  and have a hard time with dsh.

    At a customers site we have about 30 LPARs and I want to create a formatted list of available space in volume groups for all LPARs and similar stuff. As a starting point I want to use the NIM server.

    I created the dsh snippets already and they do what I want if I call them directly at the prompt from the NIM server.

    Consider:
    dsh -N all \
        ls -d  /*/oracle/product/*  2> /dev/null | \
        sed -e "s/\.<censored>:/ $(date +"%Y%m%d%H%M")/" 1> /stage/shared/betr_meta/out.new/oracle_homes.out
    ​
    # gives the desired reult:
    root@p9kau-p1nim:~ -> head -5 /stage/shared/betr_meta/out.new/oracle_homes.out
    p9kau-p1h 202202181420 /zebparch/oracle/product/19_3_0
    p9kau-t1a 202202181420 /orazebe/oracle/product/19_3_0
    p9kau-t1a 202202181420 /orazebt/oracle/product/11.2
    p9kau-t1a 202202181420 /orazebt/oracle/product/11.2.0.4
    p9kau-t1a 202202181420 /orazebt/oracle/product/19_3_0
    

    But If i put this `dsh`block in a shell-script this ends directly after the return of the dsh call: 

    The follwing script `oracle_homes.dsh.sh`
    #!/bin/bash
    set -euo pipefail
    set -x
    IFS=$' \n\t'
    # Liste aller ORACLE_HOMEs
    # Spalten
    # * Hostname
    # * Zeitpunkt
    # * ORACLE_HOME - Pfad
    echo $$
    dsh -N all \
        ls -d  /*/oracle/product/*  2> /dev/null | \
        sed -e "s/\<censored>/ $(date +"%Y%m%d%H%M")/" 1> /stage/shared/betr_meta/out.new/oracle_homes.out
    echo Hello​

    Ends without error but does not print 'Hello' . Why ?
    root@p9kau-p1nim:~ -> /stage/shared/betr_meta/oracle_homes.dsh.sh
    + IFS='
            '
    + echo 17760586
    17760586
    ++ date +%Y%m%d%H%M
    + dsh -N all ls -d '/*/oracle/product/*'
    + sed -e 's/<censored> 202202181427/'
    ​

    I planned to integrate several dsh calls in one shell script but I have no idea how to do it.

    Can anybody help ?


    Thanks for your time


    Norbert





    ------------------------------
    Norbert Klamann
    ------------------------------


  • 2.  RE: Calling dsh from shell script seems to finish the shellscript directly after the dsh call

    Posted Mon February 21, 2022 09:45 AM
    Norbert, might it be as simple as quoting the string containing your command pipeline? (from the "ls -d ... | sed -e ..." should all be executed remotely as a single pipelined command?) Also, don't forget to break down your remote command piece by piece before concluding what the result might be. Run the "ls -d" by itself, first and examine the output. It may not look the way you expect it to look. (IIRC, dsh prepends each line of stdout from the command with the hostname on which it was executed.) Good luck!

    ------------------------------
    Mackey Morgan
    ------------------------------



  • 3.  RE: Calling dsh from shell script seems to finish the shellscript directly after the dsh call

    Posted Tue February 22, 2022 03:49 AM

    @Mackey Morgan is right, you need to quote the command you want to run in the other side if you want to run multiple commands (this includes pipes and ';').

    This is due to the fact that your script is being interpreted by the local shell, and "dsh cmd1 | cmd2" is broken up as "dsh cmd1" | "cmd2".

    ​Your other options are:

    1. copy the script you want to run to all the machines with "dcp /script1 /script1", then invoke it with "dsh /script1" (or "dsh ksh /script1")
    2. cat the script into dsh:  "cat /script1 | dsh ".  This won't leave a bunch of script copies lying around.  Beware of "while read x" loops, which can have entertaining side effects.



    ------------------------------
    José Pina Coelho
    IT Specialist at Kyndryl
    ------------------------------



  • 4.  RE: Calling dsh from shell script seems to finish the shellscript directly after the dsh call

    Posted Tue February 22, 2022 05:22 AM
    Edited by Norbert Klamann Tue February 22, 2022 05:22 AM
    Thank you all for your ideas !
    I know that the second part of the command ( after  the | symbol ) runs locally on the nim server. And indeed the results are what I want. My problem is that the bash script ends after the dsh-call with the pipe . id does not continue, no error, nothing:
    echo Hello​​
    is not executed. That is my only problem. The call to dsh in itself works fine.

    Thanks again !

    Norbert

    ------------------------------
    Norbert Klamann
    ------------------------------



  • 5.  RE: Calling dsh from shell script seems to finish the shellscript directly after the dsh call

    Posted Tue February 22, 2022 06:42 AM
    Try replacing
    sed -e "s/\<censored>/ $(date +"%Y%m%d%H%M")/"​

    with

    sed -e 's/\<censored>/ '$(date +"%Y%m%d%H%M")'/'


    ------------------------------
    José Pina Coelho
    IT Specialist at Kyndryl
    ------------------------------



  • 6.  RE: Calling dsh from shell script seems to finish the shellscript directly after the dsh call

    Posted Tue February 22, 2022 07:37 AM
    That does not change anything.

    ------------------------------
    Norbert Klamann
    ------------------------------



  • 7.  RE: Calling dsh from shell script seems to finish the shellscript directly after the dsh call

    Posted Wed February 23, 2022 09:49 AM
    Also, the "-e" option will do this for you.   The argument given to -e is the name of the script.  dsh will copy it to the machines in the collective, execute the script and remove the temporary copy.  

    I've done this as Jose describes and also have used the -e option.

    Best regards,

    David Nordgren
    Costco Wholesale

    ------------------------------
    Dave Nordgren
    ------------------------------



  • 8.  RE: Calling dsh from shell script seems to finish the shellscript directly after the dsh call
    Best Answer

    Posted Thu February 24, 2022 05:46 AM
    Try running the dsh command from the command line and check the exit code (echo $?)
    You have set -e in the beginning of the script which will cause the script to exit if a command returns a non-zero exit code.

    ------------------------------
    Zaki Jääskeläinen
    ------------------------------



  • 9.  RE: Calling dsh from shell script seems to finish the shellscript directly after the dsh call

    Posted Mon February 28, 2022 04:08 AM
    Thanks a lot Zaki  ! 

    The -e option was the culprit !


    Norbert

    ------------------------------
    Norbert Klamann
    ------------------------------