Coder Social home page Coder Social logo

Exec command with single quotes about sake HOT 4 CLOSED

alajmo avatar alajmo commented on July 19, 2024
Exec command with single quotes

from sake.

Comments (4)

enriquetoledano avatar enriquetoledano commented on July 19, 2024 1

Hi!

This method isn't working for me:

sake exec -s server -o table $'uname -r | awk -v FS=\'-\' \'{print $1}\''

TASKS ***************************************************************************************************

 host       | task-0
------------+---------------------------------------------------------------
 x.x.x.x | awk: cmd. line:1: {print
            | awk: cmd. line:1:       ^ unexpected newline or end of string
            |
            | Process exited with status 1

RECAP ***************************************************************************************************

 x.x.x.x      ok=0  unreachable=0  ignored=0  failed=1  skipped=0

The only way I could make it work was:

sake exec -s server $'uname -r | awk -v FS=\'-\' "{print $ 1}"'

That is, using doble quote for print and with a space between $ and number.

When defined as a task, it runs correctly when using:

  print-kernel:
    name: Kernel
    desc: Print kernel version
    spec: info
    target: all
    cmd: uname -r | awk -v FS='-' "{print $ 1}"

Thank you very much for your help!

from sake.

alajmo avatar alajmo commented on July 19, 2024

Double quotes work for me.

~ $ sake exec -s log "uname -r|awk -v FS='-' '{print $1}'"

TASK [task-0] ************************************************************

192.168.1.203 | 5.15.76-v8+

RECAP ********************************************************************

 192.168.1.203      ok=1  unreachable=0  ignored=0  failed=0  skipped=0

from sake.

enriquetoledano avatar enriquetoledano commented on July 19, 2024

Hi:

Thanks for your quick response.
For me, it keep failing:

$:~# sake exec -s server "uname -r|awk -v FS='-' '{print $1}'"

TASK [task-0] ******************************************************************************************************************************

x.x.x.x | awk: cmd. line:1: {print
x.x.x.x | awk: cmd. line:1:       ^ unexpected newline or end of string
x.x.x.x | Process exited with status 1

RECAP **************************************************************************************************************************************

 x.x.x.x      ok=0  unreachable=0  ignored=0  failed=1  skipped=0

I'm using Ubuntu 20.04, go 1.9 and latest version of sake.

For you, I think it doesn't work either. The output of your command must be 5.15.76, not 5.15.76-v8+. The awk part isn't working.

Best regards

from sake.

alajmo avatar alajmo commented on July 19, 2024

You're correct, this seems to work correct:

sake exec -s log -o table $'uname -r | awk -v FS=\'-\' \'{print $1}\''

TASK [task-0] ***********************************************************

192.168.1.203 | 5.15.76

RECAP *******************************************************************

 192.168.1.203      ok=1  unreachable=0  ignored=0  failed=0  skipped=0

Use $'my \'string\'' to escape characters

from sake.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.