awk used with grep - no output

0

I have a bashscript which uses grep with awk as following:

#ec2-describe-instances | grep -i instance | awk '{print "Creating -> " $3; system("ec2-create-image " $2 " --name " $3 "-$(date +%F) --no-reboot ")}'

Unfortunately there seems to be an error.
And unfortunately the console output is empty.

How can I output the errors to console?

Skip

Posted 2014-05-23T15:54:29.760

Reputation: 175

1Assuming your prompt is #. What happens when you do ec2-describe-instances | grep -i instance -- is there output for awk to consume? – glenn jackman – 2014-05-23T17:41:32.537

@glenn jackman - That is one which is a bit strange with this line, scripts usually include a space even for comments, and when they signify a root prompt they include the full prompt, such as 'root@computername:/currentworkingdir#'. The # could be a $, but the ec2-xx cannot be a variable, it must a script name. In that case most user scripts start with ./script unless it is elevated to root. Speaking strictly of bash of course. – arch-abit – 2014-05-23T18:07:47.813

1@arch-abit, if the script is in PATH, then it doesn't require the ./ before it. When I provide BSD commands to customers, I often precede each line with a # and I don't always put a space (either forget or get lazy). In any case, unless we know more about 'ec2-describe-instances' and what it is supposed to output, it is not possible to tell what might be wrong with any thing that manipulates that output. – MaQleod – 2014-05-23T20:46:05.677

@MaQleod - thanks, you are correct. 'Use the PATH, Luke!' :) – arch-abit – 2014-05-23T21:15:51.853

Answers

0

Remove the pound sign from the beginning of the script. For the bash shell a # sign is a comment line.

EDIT: Anything bash reads from script or from user input starting with a # bash ignores, and Unix/Linux being terse no output is given. There are some exceptions to this, but they do not seem to apply to your script.

If you copied the script from somewhere the pound sign was not meant to be part of the script. It is commented out, so remove it to make it work

If you are new to bash there is a good starter tutorial here.

arch-abit

Posted 2014-05-23T15:54:29.760

Reputation: 455

The pound may simply be the prompt. It isn't the most common, but it is used (eg freebsd). – MaQleod – 2014-05-23T17:41:25.763