Skip to content

Instantly share code, notes, and snippets.

@abhilash1in
abhilash1in / Run RequestBin local server
Last active October 3, 2018 03:45
Shell script to run RequestBin local server on a linux machine - https://github.com/Runscope/requestbin
#!/bin/bash
# https://github.com/Runscope/requestbin
sudo apt-get update
mkdir $HOME/scripts
curl -fsSL https://get.docker.com -o $HOME/scripts/get-docker.sh
https://youtu.be/wnBSoYxfh4s
@abhilash1in
abhilash1in / userdata.sh
Last active September 12, 2018 13:51
Simple Webserver for Amazon Linux AMI
#!/bin/bash
yum update -y
yum install httpd -y
chkconfig httpd on
service httpd start
echo "Private IP:" > /var/www/html/index.html
curl http://169.254.169.254/latest/meta-data/local-ipv4 >> /var/www/html/index.html
echo "Public IP:" >> /var/www/html/index.html
curl http://169.254.169.254/latest/meta-data/public-ipv4 >> /var/www/html/index.html
@abhilash1in
abhilash1in / user-data.sh
Created April 24, 2018 17:06
Install nvm and NodeJS using AWS EC2 user data script
#!/bin/bash
apt-get -y update
cat > /tmp/subscript.sh << EOF
# START UBUNTU USERSPACE
echo "Setting up NodeJS Environment"
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.9/install.sh | bash
echo 'export NVM_DIR="/home/ubuntu/.nvm"' >> /home/ubuntu/.bashrc
echo '[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm' >> /home/ubuntu/.bashrc
# Dot source the files to ensure that variables are available within the current shell
. /home/ubuntu/.nvm/nvm.sh
@abhilash1in
abhilash1in / nginx-config
Created April 22, 2018 09:57
nginx config to be used in /etc/nginx/sites-available/<name>
server {
listen 80;
server_name <website-url>;
location / {
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;
proxy_pass "http://127.0.0.1:3000";
}
}
@abhilash1in
abhilash1in / nginx.conf
Last active April 22, 2018 09:54
nginx configuration for portainer with multiple websites reverse proxied to different ports based on hostname
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
^\d[a-zA-Z]\w{1}\d{2}[a-zA-Z]\w{1}\d{3}$
@abhilash1in
abhilash1in / rebootAll.sh
Created February 8, 2017 10:52
Reboot systems over SSH
#!/bin/bash
USERNAME=5c
HOST="172.1.4."
SCRIPT="echo aryabhatta | sudo -S reboot"
for i in {59..67} ; do
sshpass -p"aryabhatta" ssh -o StrictHostKeyChecking=no ${USERNAME}@${HOST}$i "${SCRIPT}"
done
for i in {69..150} ; do
sshpass -p"aryabhatta" ssh -o StrictHostKeyChecking=no ${USERNAME}@${HOST}$i "${SCRIPT}"
done
@abhilash1in
abhilash1in / copyImmutableFile.sh
Created February 8, 2017 10:50
Copy a file to other systems on the network which cannot be deleted by them directly
#!/bin/bash
USERNAME=sem6c
HOST="172.1.6."
#SCRIPT="echo aristotle | sudo -S reboot"
#SCRIPT="echo aristotle | sudo -S touch /home/sem6c/Desktop/youvebeenhacked.txt"
SCRIPT="touch /home/sem6c/Desktop/youvebeenhacked.txt; echo aristotle | sudo -S chattr +i /home/sem6c/Desktop/youvebeenhacked.txt; sudo chmod 000 /home/sem6c/Desktop/youvebeenhacked.txt"
for i in {40..127} ; do
sshpass -p"aristotle" ssh -o StrictHostKeyChecking=no -o ConnectTimeout=2 ${USERNAME}@${HOST}$i "${SCRIPT}"
done
for i in {129..150} ; do
#!/bin/bash
USERNAME=sem6c
HOST="172.1.6."
SCRIPT="nohup sh -c \" echo aristotle | sudo -S add-apt-repository ppa:webupd8team/java -y && echo aristotle | sudo -S apt-get update && echo aristotle | sudo -S apt-get install oracle-java8-installer && echo aristotle | sudo -S apt-get install oracle-java8-set-default\" > /dev/null 2>&1 &"
for i in {40..255} ; do
sshpass -p"aristotle" ssh -o StrictHostKeyChecking=no ${USERNAME}@${HOST}$i "${SCRIPT}"
done