Here’s how to isolate a process via the top command.
top -c -p $(pgrep -f process_name | head -20 | tr "\\n" "," | sed 's/,$//') |
cloud engineer
Here’s how to isolate a process via the top command.
top -c -p $(pgrep -f process_name | head -20 | tr "\\n" "," | sed 's/,$//') |
top -c -p $(pgrep -f process_name | head -20 | tr "\\n" "," | sed 's/,$//')
Run Terraform in a Docker container.
docker run --rm -it --name terraform -v ~/.aws:/root/.aws -v $(pwd):/workspace -w /workspace hashicorp/terraform:latest |
docker run --rm -it --name terraform -v ~/.aws:/root/.aws -v $(pwd):/workspace -w /workspace hashicorp/terraform:latest
Create an alias.
alias terraform='docker run --rm -it --name terraform -v ~/.aws:/root/.aws -v $(pwd):/workspace -w /workspace hashicorp/terraform:latest' |
alias terraform='docker run --rm -it --name terraform -v ~/.aws:/root/.aws -v $(pwd):/workspace -w /workspace hashicorp/terraform:latest'
Run the command
terraform --version
Terraform v1.0.2
on linux_amd64 |
terraform --version Terraform v1.0.2 on linux_amd64
You can run a gcloud commands in a Docker container.
docker run -ti --name gcloud-config google/cloud-sdk gcloud auth login |
docker run -ti --name gcloud-config google/cloud-sdk gcloud auth login
Create an alias.
alias gcloud='docker run --rm -ti --volumes-from gcloud-config google/cloud-sdk:latest gcloud' |
alias gcloud='docker run --rm -ti --volumes-from gcloud-config google/cloud-sdk:latest gcloud'
Run the command.
gcloud --version Google Cloud SDK 348.0.0 alpha 2021.07.09 app-engine-go 1.9.71 app-engine-java 1.9.90 app-engine-python 1.9.93 app-engine-python-extras 1.9.93 beta 2021.07.09 bigtable bq 2.0.70 cbt 0.10.0 cloud-datastore-emulator 2.1.0 cloud-firestore-emulator 1.13.0 cloud-spanner-emulator 1.2.0 core 2021.07.09 datalab 20190610 gsutil 4.65 kpt 0.39.3 local-extract 1.2.0 pubsub-emulator 0.4.1 |
gcloud --version Google Cloud SDK 348.0.0 alpha 2021.07.09 app-engine-go 1.9.71 app-engine-java 1.9.90 app-engine-python 1.9.93 app-engine-python-extras 1.9.93 beta 2021.07.09 bigtable bq 2.0.70 cbt 0.10.0 cloud-datastore-emulator 2.1.0 cloud-firestore-emulator 1.13.0 cloud-spanner-emulator 1.2.0 core 2021.07.09 datalab 20190610 gsutil 4.65 kpt 0.39.3 local-extract 1.2.0 pubsub-emulator 0.4.1
Create one for gsutil.
alias gsutil='docker run --rm -ti --volumes-from gcloud-config google/cloud-sdk:latest gsutil' |
alias gsutil='docker run --rm -ti --volumes-from gcloud-config google/cloud-sdk:latest gsutil'
Here’s another way to add startup scripts to your instance during creation.
UserData: Fn::Base64: !Sub | #cloud-config repo_upgrade: none runcmd: # Cloud init startup script - "bash /root/setup.sh" write_files: # Cloud init startup script - owner: root:root permissions: '0644' path: /root/setup.sh content: | #! /bin/bash -x write_files: # Cloud init startup script - owner: root:root permissions: '0644' path: /root/setup.sh content: | #! /bin/bash -x # run your bash commands here date > log.txt uptime >> log.txt |
UserData: Fn::Base64: !Sub | #cloud-config repo_upgrade: none runcmd: # Cloud init startup script - "bash /root/setup.sh" write_files: # Cloud init startup script - owner: root:root permissions: '0644' path: /root/setup.sh content: | #! /bin/bash -x write_files: # Cloud init startup script - owner: root:root permissions: '0644' path: /root/setup.sh content: | #! /bin/bash -x # run your bash commands here date > log.txt uptime >> log.txt
The above script creates a file setup.sh and executes it during instance creation. The output is dumped to log.txt file.
You can run MySQL commands from the terminal by using -e switch. Here are a few examples.
mysql -u username -p -e "create database mydb" mysql -u username -p -e "use mydb" mysql -u username -p database -e "select * from mytable" |
mysql -u username -p -e "create database mydb" mysql -u username -p -e "use mydb" mysql -u username -p database -e "select * from mytable"
If you have .mycnf configured, you can omit the username and password.
mysql -e "create database mydb" mysql -e "use mydb" mysql -e "select * from mytable" |
mysql -e "create database mydb" mysql -e "use mydb" mysql -e "select * from mytable"
To run multiple commands from a single line, separate the commands using a semicolon.
mysql -e "create database somedb; use mydb; select * from mytable;" |
mysql -e "create database somedb; use mydb; select * from mytable;"
Here’s the command to run the Ansible playbook.
ansible-playbook -t hosts playbook.yml |
ansible-playbook -t hosts playbook.yml
Or simply run it like this.
ansible-playbook playbook.yml |
ansible-playbook playbook.yml
This Docker image contains Apache (httpd), a web server.
Here’s the Dockerfile.
FROM httpd:2.4 COPY ./public-html/ /usr/local/apache2/htdocs/ |
FROM httpd:2.4 COPY ./public-html/ /usr/local/apache2/htdocs/
Build and run your Docker image.
docker build -t my-app . docker run -dit --name my-running-app -p 8080:80 my-app |
docker build -t my-app . docker run -dit --name my-running-app -p 8080:80 my-app
Visit http://localhost:8080 to view your app.
Here’s how to run a shell script from your website. You’ll need 2 files.
Here’s the contents of foo.php. Wrap your output with ‘pre’ for better formatting.
<?php $output = shell_exec('/var/www/html/bar.sh 2>&1'); echo "$output"; |
<?php $output = shell_exec('/var/www/html/bar.sh 2>&1'); echo "$output";
Here’s the content of bar.sh. Output will be displayed on web page.
#!/bin/bash now="$(date +'%y%m%d')" echo $now aws s3 ls |
#!/bin/bash now="$(date +'%y%m%d')" echo $now aws s3 ls