Skip to content

Instantly share code, notes, and snippets.

View ivbor7's full-sized avatar

Ivan Boriskin ivbor7

View GitHub Profile
@ivbor7
ivbor7 / TCP config data
Last active December 19, 2020 10:17
Collect the TCP configuration data in Linux
#!/bin/bash
#---------------------------------------------------------
# Usage: sudo ./collect_data.sh <network-interface-name>
#---------------------------------------------------------
# Define some variables
LOGFILE=/tmp/tcp_conf.log
DateStr=$(date +"%Y-%m-%d %H:%M:%S")
@ivbor7
ivbor7 / ssh_key.tf
Created August 28, 2020 22:01 — forked from irvingpop/ssh_key.tf
Terraform external data source example - dynamic SSH key generation
# ssh key generator data source expects the below 3 inputs, and produces 3 outputs for use:
# "${data.external.ssh_key_generator.result.public_key}" (contents)
# "${data.external.ssh_key_generator.result.private_key}" (contents)
# "${data.external.ssh_key_generator.result.private_key_file}" (path)
data "external" "ssh_key_generator" {
program = ["bash", "${path.root}/../ssh_key_generator.sh"]
query = {
customer_name = "${var.customer_name}"
customer_group = "${var.customer_group}"
@ivbor7
ivbor7 / README-Template.md
Created August 7, 2020 11:33 — forked from PurpleBooth/README-Template.md
A template to make good README.md

Project Title

One Paragraph of project description goes here

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

@ivbor7
ivbor7 / curl.md
Created June 1, 2020 19:14 — forked from subfuzion/curl.md
curl POST examples

Common Options

-#, --progress-bar Make curl display a simple progress bar instead of the more informational standard meter.

-b, --cookie <name=data> Supply cookie with request. If no =, then specifies the cookie file to use (see -c).

-c, --cookie-jar <file name> File to save response cookies to.

@ivbor7
ivbor7 / Run script if it exists
Created April 10, 2020 15:05
Check if the script exists and run it
while [ ! -f /tmp/wait-script.sh ]
do
sleep .2
done
chmod 755 /tmp/wait-script.sh; /tmp/wait-script.sh
@ivbor7
ivbor7 / postgresql_backup.md
Last active March 31, 2021 15:20
Postgresql backup tips
  1. pg_dump is a nifty utility designed to output a series of SQL statements that describes the schema and data of your database. You can control what goes into your backup by using additional flags.
    Backup: pg_dump -h localhost -p 5432 -U postgres -d mydb > backup.sql

    Restore: psql -h localhost -p 5432 -U postgres -d mydb < backup.sql

    -h is for host.
    -p is for port.
    -U is for username.
    -d is for database.

@ivbor7
ivbor7 / read_file
Created March 31, 2020 17:46
Read file line by line in BASH
#read a file from the command line without using the cat command
```sh
$ while IFS= read -r line; do echo $line; done < file.txt
```
#bash script and read any file line by line
```sh
#!/bin/bash
n=1
while IFS= read -r line; do
@ivbor7
ivbor7 / root_shell.md
Last active March 31, 2020 09:26
Example of root login shell

Create the file /root/rbash.sh (this can be any name or path, but should be chown root:root and chmod 700):

#!/bin/bash

commands=("man" "pwd" "ls" "whoami")
timestamp(){ date +'%Y-%m-%s %H:%M:%S'; }
log(){ echo -e "$(timestamp)\t$1\t$(whoami)\t$2" > /var/log/rbash.log; }
trycmd()
{
@ivbor7
ivbor7 / Terminal_Cheat_sheet.md
Last active March 31, 2020 12:36
Shell cheat sheet

Terminal commands Cheat Sheet


echo $-             # shows the attributes enabled on the shell
[[ $- == *i* ]] && echo 'Interactive' || echo 'not-interactive'   # detect if you are in an interactive or non-interactive shell with
echo $0                 # display if the login_shell or not login_shell is used
shopt login_shell       # the same meaning as above command 
echo $SHELL             # display which shell is used