Uly.me

cloud engineer

  • Home
  • About
  • Archives
Home/Archives for run

January 15, 2021

CloudFormation Userdata

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.

November 29, 2020

Running MySQL commands from the Terminal

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;"

June 16, 2020

Run Ansible Playbook

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

  • 1
  • 2
  • 3
  • Next Page »
  • Cloud
  • Linux
  • Git

Copyright © 2012–2021