Skip to content

Instantly share code, notes, and snippets.

@anmolsukki
Created May 5, 2020 13:59
Show Gist options
  • Save anmolsukki/7686bb74ae8e9f51d6a506660b660e9c to your computer and use it in GitHub Desktop.
Save anmolsukki/7686bb74ae8e9f51d6a506660b660e9c to your computer and use it in GitHub Desktop.
[ Shell Script ] Shell Script Basic Command

How to run on windows

Install git bash

open git bash and run file

example

sh file_name.sh
#!/bin/bash
# Calculate the sum of two integers with pre initialize values
# in a shell script
a=10
b=20
sum=$(( $a + $b ))
echo $sum
#!/bin/bash (adding two number)
echo -n "Enter the first number : "
read num1
echo -n "Enter the second number : "
read num2
sum=`expr $num1 + $num2`
echo "sum of two value is $sum"
SOURCE="/Users/anmol/Desktop/folder"
DESTINATION="/Users/anmol/Desktop/folder"
cp -r "$SOURCE/folder_name/"* "$DESTINATION/folder_name/"
#!/bin/bash
FARMTECH_DIR='./farmtech'
REACTJA_BASICS_DIR='../reactjs_basics'
RJ_ZARVES_DIR='../rj_zarves'
##run farmtech application
cd ${FARMTECH_DIR}
rm debug.out
npm start > debug.out &
##run reactjs_basics application
cd ${REACTJA_BASICS_DIR}
rm debug.out
npm start > debug.out &
#run rj_zarves application
cd ${RJ_ZARVES_DIR}
rm debug.out
npm start > debug.out &
# close port with shell script
# For single port
gnome-terminal -e 'sh -c "sudo kill $(sudo lsof -t -i:3000); sleep 10; exec bash"'
# For multiple port
gnome-terminal -e 'sh -c "sudo kill $(sudo lsof -t -i:3001); sudo kill $(sudo lsof -t -i:3002); sleep 10; exec bash"'
echo "addition of two number"
echo "enter a number"
read a
echo "enter a number"
read b
echo "additon is: "
c=`expr $a + $b`
echo $c
#!/bin/sh
# Database Name to backup
MONGO_DATABASE="dbname"
# Database host name
MONGO_HOST="127.0.0.1"
# Database port
MONGO_PORT="27017"
# Backup directory
BACKUPS_DIR="/Users/deepak/Desktop/BackupFile/$MONGO_DATABASE"
# Database user name
DBUSERNAME="username"
# Database password
DBPASSWORD="password"
# Authentication database name
DBAUTHDB="admin"
# Days to keep the backup
DAYSTORETAINBACKUP="1"
#=====================================================================
TIMESTAMP=`date +%F-%H%M`
BACKUP_NAME="$MONGO_DATABASE-$TIMESTAMP"
echo "Performing backup of $MONGO_DATABASE"
echo "--------------------------------------------"
# Create backup directory
if ! mkdir -p $BACKUPS_DIR; then
echo "Can't create backup directory in $BACKUPS_DIR. Go and fix it!" 1>&2
exit 1;
fi;
# Create dump
mongodump -d $MONGO_DATABASE --username $DBUSERNAME --password $DBPASSWORD --authenticationDatabase $DBAUTHDB
# Rename dump directory to backup name
mv dump $BACKUP_NAME
# Compress backup
tar -zcvf $BACKUPS_DIR/$BACKUP_NAME.tgz $BACKUP_NAME
# Delete uncompressed backup
rm -rf $BACKUP_NAME
# Delete backups older than retention period
find $BACKUPS_DIR -type f -mtime +$DAYSTORETAINBACKUP -exec rm {} +
echo "--------------------------------------------"
echo "Database backup complete!"
#!/bin/bash
firefox https://github.com/anmolsukki/ https://youtube.com
echo $n
sleep $n
killall firefox
echo "all done!"
# open new terminal
gnome-terminal command
gnome-terminal command
gnome-terminal command
# run react project with shell script
DIZIO_DIR='./rj_theme'
#run dizio main api server
npm start
# run react project with shell script in specific location project
DIZIO='./ReactJs/rj_theme'
#run dizio main api server
cd ${DIZIO}
sudo npm start
# print text
echo "This script is about to print some text."
echo "Visit my github profile."
echo "Is It helpful?."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment