Find the answer to your Linux question:
Results 1 to 2 of 2
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined! jdh239's Avatar
    Join Date
    Sep 2006
    Posts
    94

    Function in for loop, passing to ssh, heredoc involved


    I have the following script. The function, in and of itself, works correctly on the guest system when not passing it via ssh.

    Code:
    #!/bin/bash
    
    CSV="/tmp/john.csv"
    
    HOST_NAMES="myhost1
                myhost2"
    
    echo HOST, VM Name, VCPUs, Pin Range >> $CSV
    
    for i in $HOST_NAMES; do
      echo "${i},,,," | tr a-z A-Z >> $CSV
      ssh root@${i} bash -s << EOF
      gather_info(){
        for i in $( xm list | grep -ve ^Domain -e ^Name | awk '{print $1}' ); do
          FPATH=$( find /OVS/Repositories/* -name $i )
          HOST=$( grep ^OVM_simple ${FPATH}/vm.cfg | awk '{print $NF}'  | tr -d \')
          VCPUS=$( grep ^vcpus ${FPATH}/vm.cfg awk '{print $NF}'  | tr -d \' )
          PINNING=$( grep ^cpus ${FPATH}/vm.cfg awk '{print $NF}'  | tr -d \' )
        done
      }
      gather_info
    EOF
    
      echo ",${HOST},${VCPUS},${PINNING}" >> $CSV
    done
    When I execute this the code doesn't get executed on the remote host. I receive the following errors before being prompted for the password for the remote host:

    Code:
    ./cpu_pinning.sh: line 22: xm: command not found
    find: /OVS/Repositories/*: No such file or directory
    grep: /vm.cfg: No such file or directory
    grep: /vm.cfg: No such file or directory
    grep: awk: No such file or directory
    grep: {print $NF}: No such file or directory
    grep: /vm.cfg: No such file or directory
    grep: awk: No such file or directory
    grep: {print $NF}: No such file or directory
    Wondering what I can tweak to make this work. Basically, the guests are XEN hosts, and they have the necessary info on them. I am trying to gather the info from various hosts and create a csv. I will be putting this in a cron job that runs monthly and emails the results.

  2. #2
    Just Joined! jdh239's Avatar
    Join Date
    Sep 2006
    Posts
    94
    -->
    I was able to work around it on a server that had mounts to each of the HOST storage pools, but would still like to know how to do this should someone have any ideas.

    Here is my workaround (understanding I have access to each host locally through ro shares)

    Code:
    echo HOST, VM Name, VCPUs, Pin Range >> $CSV
    
    for host in $HOST_NAMES; do
      echo "${host},,,," | tr a-z A-Z >> $CSV
      GUEST_LIST=$( ssh -i /root/.ssh/my_private_ssh_key root@${host} /usr/sbin/xm list | grep -ve ^Domain -e ^Name | awk '{print $1}' )
      for guest in $GUEST_LIST; do
        FPATH=$( find /mount*/VirtualMachines/* -name $guest )
        HOST=$( grep ^OVM_simple ${FPATH}/vm.cfg | awk '{print $NF}'  | tr -d \')
        VCPUS=$( grep ^vcpus ${FPATH}/vm.cfg | awk '{print $NF}'  | tr -d \' )
        PINNING=$( grep ^cpus ${FPATH}/vm.cfg | awk '{print $NF}'  | tr -d \' )
        echo ",${HOST},${VCPUS},${PINNING}" >> $CSV
      done
    
    done

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •