Skip to content

Instantly share code, notes, and snippets.

View anujkaushal's full-sized avatar
🏠
Working from home

Anuj anujkaushal

🏠
Working from home
View GitHub Profile
@anujkaushal
anujkaushal / sshbash-inside-local-shell-script.sh
Created July 26, 2020 19:52
How to open server bash inside a local shell script
#!/bin/bash
var1="important-value"
echo "SEVER BASH - stats here"
ssh -i ./key.pem user@example.com <<-SSHBASH
echo "Successfully connected to example.com"
ls -l ./public_html/index.html
echo "Echo Var1 Value: $var1"
@anujkaushal
anujkaushal / curl-reponse-code-of-urls.sh
Created May 11, 2020 06:47
Check response code of URLs using input file
#!/bin/bash
input="./urls.txt" # input file for list of URLs
output="./result.txt" # output file
echo "ResponseCode, URL" > $output
while IFS= read -r line
do
status_code=$(curl --write-out %{http_code} --silent --output /dev/null $line)
outputStr=$(echo "$status_code, $line")
echo $outputStr
echo $outputStr >> $output
tmpDir="/tmp"
randomName=`date +'%s'``php -r "echo rand();"`
awsUser="xxxxxxx"
awsAcID="xxxxxxxxxxxxx"
region="xx-xxxx-xx"
if [[ ! "$1" ]] ; then
echo "You must supply MFA."
exit 1
@anujkaushal
anujkaushal / restart-mysql-start-stop-in-macos-mojave.sh
Created April 17, 2019 08:20
MySQL Start/Stop for MacOS Mojave
# stop mysql
sudo launchctl unload -F /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist
# start mysql
sudo launchctl load -F /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist
@anujkaushal
anujkaushal / find-smallest-missing-positive-number.php
Last active March 22, 2019 14:31
Write a algorithm/program to find the smallest positive number missing from the array
<?php
function findnumber($numbers)
{
$count = count($numbers);
for ($i = 1; $i <= $count; $i++)
{
$flag = true;
for ($j = 0; $j < $count; $j++)
{
@anujkaushal
anujkaushal / create-folder-tree.sh
Created September 20, 2018 15:22
Create folder tree in single linux command
mkdir -p /main_folder/sub_folder/child_folder
@anujkaushal
anujkaushal / database-and-table-size.sql
Last active December 9, 2022 12:01
SQL Query to get database & table size in MB/GB
SELECT
'Total size in mysql' as `DB / Table Name`,
SUM(ROUND(((DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024),2)) AS `SizeInMB`,
SUM(ROUND(((DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024 / 1024),2)) AS `SizeInGB`
FROM
information_schema.TABLES
UNION
SELECT
@anujkaushal
anujkaushal / remove-db-name-from-db-dump-using-grep.sh
Last active September 10, 2018 12:22
Remove database name from db-dump file
grep -v "USE \`db_name\`" database.sql > database-without-name.sql
@anujkaushal
anujkaushal / mysql-db-import-or-export-in-docker-container.sh
Last active September 16, 2019 11:34
How to import or expoert MySQL DB dump in docker container
# import mysql database in docker container
docker exec -i mysql-container mysql -uuser -ppassword name_db < database-dump.sql
# export mysql database from docker container
docker exec -i mysql-container mysqldump -uroot -proot name_db > database-dump.sql