Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 265
  • Last Modified:

Store the error output of a command in shell script

I am able to store the output of a command when it completes successfully.
example

#!/bin/sh
createimage=$(aws ec2 create-image --instance-id i-bb68f5df --name ftp.b2b.backup.12-1 --no-reboot --description ftp.b2b.backup.test)
echo "$createimage"

script returns
{
    "ImageId": "ami-f5113e9c"
}

however when the command fails in the script the output is not being stored in the createimage variable.
0
MidwestTapes
Asked:
MidwestTapes
  • 2
  • 2
1 Solution
 
MikeOM_DBACommented:
Try:
createimage=$(aws ec2 create-image --instance-id i-bb68f5df --name ftp.b2b.backup.12-1 --no-reboot --description ftp.b2b.backup.test  2>&1 )

Open in new window

0
 
MidwestTapesAuthor Commented:
Yea that did the trick but before I close out I curious as to what the 2>&1 means/did.
0
 
MikeOM_DBACommented:
It means: send error messages (2) to regular output  (&1)
0
 
MidwestTapesAuthor Commented:
Thank you
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now