Skip to content

Instantly share code, notes, and snippets.

@rafamdr
rafamdr / ftp_recurs_get.sh
Created November 16, 2020 11:47
How to recursively download a folder via FTP on Linux
wget -r -nH --cut-dirs=5 -nc ftp://user:pass@server//absolute/path/to/directory
# -nH avoids the creation of a directory named after the server name
# -nc avoids creating a new file if it already exists on the destination (it is just skipped)
# --cut-dirs=5 allows to take the content of /absolute/path/to/directory and to put it in the directory where you launch wget. The number 5 is used to filter out the 5 components of the path. The double slash means an extra component.
# Source: https://stackoverflow.com/questions/113886/how-to-recursively-download-a-folder-via-ftp-on-linux#answer-5567776:~:text=Just%20to%20complement%20the%20answer%20given%20by%20Thibaut%20Barr%C3%A8re.
@rafamdr
rafamdr / sudo_mult_cmd_user.sh
Created November 5, 2020 18:51
Execute multiple commands under another linux user
sudo -u devil -- sh -c "whoami; cd ~/ && pwd"
# Expected result
# devil
# /some/hell/path/devil
@rafamdr
rafamdr / ssh_embed_creds.sh
Created November 5, 2020 18:40
Bash script to execute a command through SSH passing username/password as parameters
#!/bin/bash
#!/usr/bin/expect
if [ ! "$BASH_VERSION" ] ; then
exec /bin/bash "$0" "$@"
fi
echo -n "SSH User":
read -r sshusertemp
@rafamdr
rafamdr / gist:f52a1cd74c6bd03864ca0da3828da30f
Last active April 12, 2021 11:12
Command to extract content from hadoop gziped files
cat hadoop_file.bin | gzip -d
@rafamdr
rafamdr / aws_ecr_image_move.sh
Created October 19, 2020 16:39
Bash cmds to move AWS ECR image from one account to another
$(aws ecr get-login --no-include-email --region us-east-1 --profile account1)
docker pull 000000000001.dkr.ecr.us-east-1.amazonaws.com/some-repo:latest
$(aws ecr get-login --no-include-email --region us-west-2 --profile account2)
docker tag 000000000001.dkr.ecr.us-east-1.amazonaws.com/some-repo:latest 000000000002.dkr.ecr.us-west-2.amazonaws.com/some-repo
docker push 000000000002.dkr.ecr.us-west-2.amazonaws.com/some-repo:latest
@rafamdr
rafamdr / gist:57636f94a325582024fbfe747f7d800c
Created October 19, 2020 16:24
Powershell cmds to start locust master and workers
For ($i=0; $i -le 6; $i++) { Start-Process -FilePath "python" -ArgumentList "-m","locust","-f","locustfile.py","--worker","--master-host=localhost" }
python -m locust -f locustfile.py --master
@rafamdr
rafamdr / locust_starter.sh
Created October 19, 2020 16:21
Bash script to start Locust master and workers
#!/bin/bash
set -e
if [ ! "$BASH_VERSION" ] ; then
exec /bin/bash "$0" "$@"
fi
for i in {1..7}
do
locust -f locust_file --worker --master-host=localhost &
done
locust -f locust_file --master
@rafamdr
rafamdr / gist:350cd8d7731d0c1e4fbb6978c93387ab
Created October 19, 2020 16:18
TCPdump cmd to listem different ports on any interface and save data into a file
tcpdump -i any -nn -s0 -v -w ./tcpdump.cap port '(80 or 5201 or 5202 or 5203 or 5204 or 5205 or 5206 or 5207)'
@rafamdr
rafamdr / curl_sendfile_http.sh
Created October 19, 2020 16:16
cURL cmd to send file to a page with a component called "uploadfile"
curl -i -X POST -L --insecure --progress-bar -o sending_output.txt -H 'Content-Type: multipart/form-data' -F 'uploadfile=@./b.bin' localhost:8001/demo/upload
@rafamdr
rafamdr / gist:abc58240e0786f8166d3dfa9b5fe8eea
Created October 19, 2020 16:13
Nginx config snippet for capturing HTTP user agent
log_format compression '$time_local - $remote_addr: "$http_user_agent"';
access_log /var/log/nginx/access.log compression;