How to run aws bash commands consecutively? - bash

How can I execute the following bash commands consecutively?
aws logs create-export-task --task-name "cloudwatch-log-group-export1" \
--log-group-name "/my/log/group1" \
--from 1488708419000 --to 1614938819000 \
--destination "my-s3-bucket" \
--destination-prefix "my-log-group1"
aws logs create-export-task --task-name "cloudwatch-log-group-export" \
--log-group-name "/my/log/group2" \
--from 1488708419000 --to 1614938819000 \
--destination "my-s3-bucket" \
--destination-prefix "my-log-group2"
The problem I have with the above commands is that after the first command completes execution, the script will stuck at the following state, making the second command not reachable.
{
"taskId": "0e3cdd4e-1e95-4b98-bd8b-3291ee69f9ae"
}
It seems that I should find a way to wait for cloudwatch-log-group-export1 task to complete.

You could have to crate a waiter function which uses describe-export-tasks to get current status of an export job.
Example of such function:
wait_for_export() {
local sleep_time=${2:-10}
while true; do
job_status=$(aws logs describe-export-tasks \
--task-id ${1} \
--query "exportTasks[0].status.code" \
--output text)
echo ${job_status}
[[ $job_status == "COMPLETED" ]] && break
sleep ${sleep_time}
done
}
Then you use it:
task_id1=$(aws logs create-export-task \
--task-name "cloudwatch-log-group-export1" \
--log-group-name "/my/log/group1" \
--from 1488708419000 --to 1614938819000 \
--destination "my-s3-bucket" \
--destination-prefix "my-log-group1" \
--query 'taskId' --output text)
wait_for_export ${task_id1}
# second export

aws-cli auto access to vim edit mode by default.
You can avoid it by setting AWS_PAGER environment variable is "" before execute aws command.
export AWS_PAGER=""
aws logs create-export-task...
Or, you can fix it in to aws's config file (~/.aws/config):
[default]
cli_pager=

Related

Yocto do_install action not performed

here is my bbappend file.
LICENSE = "MIT"
IMAGE_LINGUAS = " "
# User preferences
inherit extrausers
# Change root password (note the capital -P)
EXTRA_USERS_PARAMS = "\
usermod -P toor root; \
useradd -P michael -G sudo michael; \
useradd -P nfi -G sudo nfi; \
"
# uncomment the line %sudo ALL=(ALL) ALL in /etc/sudoers
modify_sudoers() {
sed 's/# %sudo/%sudo/' < ${IMAGE_ROOTFS}${sysconfdir}/sudoers > ${IMAGE_ROOTFS}${sysconfdir}/sudoers.tmp
mv ${IMAGE_ROOTFS}${sysconfdir}/sudoers.tmp ${IMAGE_ROOTFS}${sysconfdir}/ROOTFS
}
sudoers_POSTPROCESS_COMMAND_append = " modify_sudoers;"
IMAGE_INSTALL = "base-files \
base-passwd \
busybox \
mtd-utils \
mtd-utils-ubifs \
libconfig \
swupdate \
swupdate-www \
${#bb.utils.contains('SWUPDATE_INIT', 'tiny', 'virtual/initscripts-swupdate', 'initscripts systemd', d)} \
util-linux-sfdisk \
mmc-utils \
e2fsprogs-resize2fs \
lua \
debugconfigs \
"
IMAGE_FSTYPES = "ext4.gz.u-boot ext4 cpio.gz.u-boot"
PACKAGE_EXCLUDE += " jailhouse kernel-module-jailhouse libncursesw5 libpanelw5 libpython3 python3* perl* apt dpkg "
SRC_URI += "file://set-ttymxc0-permissions.sh"
do_install() {
install -d ${D}${sysconfdir}/init.d
install -m 0755 ${WORKDIR}/set-ttymxc0-permissions.sh ${D}${sysconfdir}/init.d/
}
addtask install after do_build
I am using SWUpdate. I can build their kernel and run it on my device. However I cannot login as root or any user I have created. It seems this could be related to user permissions in the getty serial terminal ttymxc0. So I am attempting to add a script to init.d. The script contains
#!/bin/sh
# Set permissions on ttymxc0
chmod 660 /dev/ttymxc0
chown root:tty /dev/ttymxc0
The bitbake file I am appending to is swupdate-image.bb. This file does not do much. It does not have a do_install section. So I am attempting to add one. However it is never run. Can anyone speculate as to why?
You actually noticed that the file swupdate-image.bb require an other file swupdate-image.inc.
You should pay attention to this line:
${#bb.utils.contains('SWUPDATE_INIT', 'tiny', 'virtual/initscripts-swupdate', 'initscripts systemd', d)} \
${#bb.utils.contains() is a (Python) function. Basically it will check the SWUPDATE_INIT variable, if there is a match with tiny then it will return virtual/initscripts-swupdate to IMAGE_INSTALL. Else, it will return initscripts systemd to IMAGE_INSTALL.
So you should only set your variable SWUPDATE_INIT= "tiny" in a .bbappend file.
Adding this should install rcS.swupdate in your final image according to initscripts-swupdate recipe:
https://github.com/sbabic/meta-swupdate/blob/master/recipes-core/initscripts-swupdate/initscripts-swupdate-usb.bb
N.B: I have noticed that you added resize2fs. If you want to add this binary make sure that the right kernel flag is set ! You will more likely need to create a .bbappend file and add the following :
EXTRA_OECONF_append_class-target = " --enable-resizer"

aws-cli gateway how to encode newlines in integration response templates invoked from bash

I am using "aws apigateway update-integration-response" from a bash script to update an integration response template. my problem is that newlines did not appear in the web console. I tried all combinations of slash n, back-slash n, even unicode for the newline without success.. below there is the bash command and the output as it appears in aws web console:
bash:
echo "update integration response script mapping for ${CODE} ${2}"
aws apigateway update-integration-response \
--rest-api-id ${APIID} \
--resource-id ${RESOURCEID} \
--http-method ${METHOD} \
--status-code ${CODE} \
--patch-operations \
"op='add',path='/responseTemplates/application~1json',value='#set(\$errorMessageObj = \$util.parseJson(\$input.path(\'\$.errorMessage\')))NEWLINE/nA//nB///nX////nC\nD\\nE\\\nF\\\\n \u000A unicodeA Cg== unicodeB #if(\"\$errorMessageObj.get(\'error-code\')\" != \"\")\n{\n \"error-code\": \"\$errorMessageObj[\'error-code\']\",\n \"error-message\": \"\$errorMessageObj[\'error-message\']\"\n}\\n#else\n{\n \"error-code\": \"AWS\",\n \"error-message\": \"\$input.path(\'\$.errorMessage\')\"\n}\n#end'"
Output in the aws web console:
#set($errorMessageObj = $util.parseJson($input.path('$.errorMessage')))NEWLINE/nA//nB///nX////nC\nD\nE\nF\n \u000A unicodeA Cg== unicodeB #if("$errorMessageObj.get('error-code')" != "")\n{\n "error-code": "$errorMessageObj['error-code']",\n "error-message": "$errorMessageObj['error-message']"\n}\n#else\n{\n "error-code": "AWS",\n "error-message": "$input.path('$.errorMessage')"\n}\n#end

Dockerfile: How to replace a placeholder in environment variable with build-arg's?

I have a web application which I want to run on Docker for testing purposes.
The application uses a database as storage and the configuration for the database is maintained in an environment variable (JSON).
Below you can see the env variable definition in my Dockerfile (see also my approaches below)
ENV CONFIG '{ \
"credentials":{ \
"hostname": "172.17.0.5", \
"password": "PWD", \
"port": "1234", \
"username": "${USER}" \
}, \
"name":"database", \
"tags":[] \
}, \
...
If I hardcode all parameters for the database everything is working but I don't want to change my Dockerfile only because the IP address of the database has changed.
Therefore I want to use Docker build-args.
I already tried two approaches:
Directly reference the variable (see line with "${USER}")
Replace a placeholder like "PWD" with the following command RUN CONFIG=$(echo $CONFIG | sed 's/PWD/'$db_pwd'/g')
The first approach results in no replacement so ${USER} is ${USER}. The second approach seems to work (at least in terminal) but it seems like the variable assignment is not working.
Do you have any idea how I can make this work? Feel free to suggest other approaches. I just don't want to have hardcoded parameters in my Dockerfile.
Thanks!
Variable expansion can only work in double-quoted strings. This is working:
ENV CONFIG "{ \
\"credentials\":{ \
\"hostname\": \"172.17.0.5\", \
\"password\": \"PWD\", \
\"port\": \"1234\", \
\"username\": \"${USER}\" \
}, \
\"name\":\"database\", \
\"tags\":[] \
}"
A simple example:
FROM alpine
ENV USER foo
ENV CONFIG "{ \
\"credentials\":{ \
\"hostname\": \"172.17.0.5\", \
\"password\": \"PWD\", \
\"port\": \"1234\", \
\"username\": \"${USER}\" \
}, \
\"name\":\"database\", \
\"tags\":[] \
}"
ENTRYPOINT env | sort
_
$ docker build -t test .
$ docker run -it --rm test
CONFIG={ "credentials":{ "hostname": "172.17.0.5", "password": "PWD", "port": "1234", "username": "foo" }, "name":"database", "tags":[] }
HOME=/root
HOSTNAME=43d29bd12bc5
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PWD=/
SHLVL=1
TERM=xterm
USER=foo

Custom garmin map have no name

I created a Garmin map from my own OSM files (using JOSM and my own GPS records, no input from Openstreetmap).
The whole process run well, but I have just a little problem : when I load the final map to Basecamp, the name of this map is empty (blank).
Any idea ?
Here is the code. Before, some variables :
PREFIX=640000
ORIGINALNAME=$(echo ${PREFIX}00)
NAME=$(echo ${PREFIX}01)
ID_PUBLIC=64
DIR="/home/Carto"
GMAPIBUILDER="/Applications/Carto/gmapi-builder.py"
MKGMAP="/Applications/Carto/mkgmap/mkgmap.jar"
First, create img files from different layers
for f in $DIR/src/public/*.osm ; do
g=$(basename $f .osm) ;
d=$(dirname $f)
java -Xmx2G -jar $MKGMAP \
--transparent --add-pois-to-areas \
--keep-going --draw-priority=$drawpriority \
--description="[iero] "$g \
--family-name="iero Congo" \
--series-name="iero Congo" \
--mapname=$NAME --family-id=$ID --product-id=$ID \
--country-name=Congo --country-abbr=CG \
--style-file=$DIR/styles --style=iero \
--copyright-message="[iero.org] Congo $DATE" \
--product-version=$VERSION \
--latin1 --output-dir=$DIR/output/imgs/public $f 1> /dev/null;
cp $DIR/output/imgs/public/${NAME}.img $DIR/output/imgs/public/${NAME}.img
let NAME++ ;
let nbfiles++ ;
let drawpriority++ ;
done
Next, concatenate those files in unique img file
java -jar $MKGMAP --tdbfile --gmapsupp $DIR/output/imgs/public/*.img \
--keep-going \
--style-file=$DIR/styles --style=iero \
--family-name="iero Congo" \
--series-name="iero Congo" \
--description="[iero] Congo map" \
--mapname=$ORIGINALNAME --family-id=${ID_PUBLIC} --product-id=${ID_PUBLIC} \
--copyright-message="[iero.org] Congo $DATE" \
--product-version=$VERSION \
--output-dir=$DIR/output/gps/public 1> /dev/null;
Then, create gmapi files, ready for Basecamp :
python $GMAPIBUILDER -t $DIR/output/gps/public/osmmap.tdb -b $DIR/output/gps/public/osmmap.img -o $DIR/output/basecamp/mac/public $DIR/output/imgs/public/*.img
If you want to see the problem, final files can be downloaded in my website : http://www.iero.org/blog/2014/06/carte-du-congo/
Thanks !
Greg
I have done testing and only get the blank names with versions of mkgmap after they introduced the overview map feature. I built a map with r2585 and the name showed correctly.

Installing Magento using SSH to bypass web based installer

I know that I am supposed to use (;) to separate multiple commands but what is the correct format for issuing all these commands in a single line to install magento using ssh to bypass the web based installer?
php-cli -f install.php -- \
--license_agreement_accepted "yes" \
--locale "en_US" \
--timezone "America/Los_Angeles" \
--default_currency "USD" \
--db_host "DB_HOST" \
--db_name "DB_NAME" \
--db_user "DB_USER" \
--db_pass "DB_PASS" \
--url "SITE_URL" \
--use_rewrites "yes" \
--use_secure "no" \
--secure_base_url "" \
--use_secure_admin "no" \
--admin_firstname "FIRST_NAME" \
--admin_lastname "LAST_NAME" \
--admin_email "EMAIL_ADDRESS" \
--admin_username "USERNAME" \
--admin_password "PASSWORD"
Those don't seem to be commands but parameters. Putting them all into a single line:
php-cli -f install.php --license_agreement_accepted "yes" --locale "en_US" ...
should work.

Resources