Find the answer to your Linux question:
Results 1 to 4 of 4
I'm trying to create a shell script, when i do the following this works ok : ssh dev08algorel -l algodev "cd /algo/dev6/data; ls -ltr" but if i try this, it ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Oct 2011
    Posts
    14

    ssh script return value


    I'm trying to create a shell script, when i do the following this works ok :

    ssh dev08algorel -l algodev "cd /algo/dev6/data; ls -ltr"

    but if i try this, it fails ?

    ssh dev08algorel -l algodev "cd /algo/dev6/data; ls -ltr | awk '/Release1Batch-R1*/ { f=$NF };END{ print f }'"

    see error message below :

    ./ReleasePackage_Info.sh
    awk: /Release1Batch-R1*/ { f= };END{ print f }
    awk: ^ syntax error

    Please advise what i'm doing wrong ?

    thank you

  2. #2
    Linux Engineer
    Join Date
    Apr 2012
    Location
    Virginia, USA
    Posts
    896
    You awk syntax is wrong.

    awk '/test*/ {print $NF;}'
    in place of what you have.

  3. #3
    Just Joined!
    Join Date
    Oct 2011
    Posts
    14
    thank you,

    though your example show me all the files :

    ls -ltr | awk '/Release1Batch-R1*/ { print $NF; }'
    Release1Batch-R1.2.manifest
    Release1Batch-R1.2.2.manifest
    Release1Batch-R1.2.3.manifest
    Release1Batch-R1.2.3-HF1.manifest
    Release1Batch-R1.2.3-HF3.manifest
    Release1Batch-R1.2.4.manifest
    Release1Batch-R1.2.5.manifest
    Release1Batch-R1.3.1.manifest
    Release1Batch-R1.4.2.manifest

    and my command gets the latest file :

    ls -ltr | awk '/Release1Batch-R1*/ { f=$NF };END{ print f }'
    Release1Batch-R1.4.2.manifest

    though my command does not work when using ssh as per below :


    ssh dev08algorel -l algodev "cd /algo/dev6/data; ls -ltr | awk '/Release1Batch-R1*/ { f=$NF };END{ print f }'"

    see error message below :

    ./ReleasePackage_Info.sh
    awk: /Release1Batch-R1*/ { f= };END{ print f }
    awk: ^ syntax error

    ??? Not sure why

  4. #4
    Linux Engineer
    Join Date
    Apr 2012
    Location
    Virginia, USA
    Posts
    896
    I figured it out.
    make it f=\$NF
    or drop the double quotes will also do the same. Bash is funny about quotes inside of quotes.

Posting Permissions

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