Solved

Store the error output of a command in shell script

Posted on 2013-12-12
4
251 Views
Last Modified: 2013-12-13
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
Comment
Question by:MidwestTapes
  • 2
  • 2
4 Comments
 
LVL 29

Accepted Solution

by:
MikeOM_DBA earned 500 total points
ID: 39715398
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
 

Author Comment

by:MidwestTapes
ID: 39716840
Yea that did the trick but before I close out I curious as to what the 2>&1 means/did.
0
 
LVL 29

Expert Comment

by:MikeOM_DBA
ID: 39717019
It means: send error messages (2) to regular output  (&1)
0
 

Author Comment

by:MidwestTapes
ID: 39717037
Thank you
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This Windows batch file is useful for organizing image files from a digital camera or other source, but can have many other uses.  It simply renames the file(s) to match their create date.  For example, if you took a picture today at 1:40pm and the …
Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now