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
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()
{
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
while [ ! -f /tmp/wait-script.sh ] | |
do | |
sleep .2 | |
done | |
chmod 755 /tmp/wait-script.sh; /tmp/wait-script.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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") |