2

I am trying to run below script which allows redirecting the messages to both terminal and a log file. The script is running fine on linux and Mac systems however it is failing while running as part of an AWS SSM command/document.

SSM Command shell script

---
schemaVersion: "2.2"
description: "List files"
mainSteps:
  - action: "aws:runShellScript"
    name: "ListInputFiles"
    precondition:
      StringEquals:
        - "platformType"
        - "Linux"
    inputs:
      runCommand:
        - "LOG_FILE='${ssmCmdLogFile}'"
        - "exec 2> >( tee -a $LOG_FILE ) 3>&1 1>>$LOG_FILE"

Error during SSM command or script execution

/var/lib/amazon/ssm/i-0ad9fa4f86c906342/document/orchestration/012ec968-3045-4aa5-9b1b-264d9a3e9c62/ListInputFiles/_script.sh: line 2: syntax error near unexpected token `>'

/var/lib/amazon/ssm/i-0ad9fa4f86c906342/document/orchestration/012ec968-3045-4aa5-9b1b-264d9a3e9c62/ListInputFiles/_script.sh: line 2: `exec 2> >( tee -a $LOG_FILE ) 3>&1 1>>$LOG_FILE'

failed to run commands: exit status 2

Not sure why this is failing. Please help.

Rob Wilkinson
  • 1,131
  • 5
  • 18
  • 34
  • The first thing to do is probably understand what shell executes these commands. Did you try to add `echo $SHELL` and `$SHELL --version`? – Renaud Pacalet Oct 08 '21 at 04:38
  • Nothing to do with your problem but note that the single quotes in `LOG_FILE='${ssmCmdLogFile}'` probably prevent parameter expansion of `${ssmCmdLogFile}`. If I am right you will redirect your logs to a file named `${ssmCmdLogFile}` (literally). This is probably not what you want. – Renaud Pacalet Oct 08 '21 at 06:14

0 Answers0