diff --git a/AWS/s3bucketsize.sh b/AWS/s3bucketsize.sh deleted file mode 100644 index 515783c..0000000 --- a/AWS/s3bucketsize.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash -#Purpose: To Know S3 Bucket Size Shell Script -#Version:1.0 -#Created Date: 09-Jan-2019 -#Modified Date: -#WebSite: https://www.server-computer.com -#Author: Ankam Ravi Kumar -# START # -echo -e "Please Enter your Bucket Name: \c" -read -r BUCKETNAME -aws s3api list-objects --bucket $BUCKETNAME --output json --query "[sum(Contents[].Size)]" > $PWD/s3bucket -sed -i 's/\[//' $PWD/s3bucket -sed -i 's/]//' $PWD/s3bucket -sed -i 's/ //' $PWD/s3bucket -cat $PWD/s3bucket |head -2 |tail -1 |awk '{print int($1/1024)" KB"}' -cat $PWD/s3bucket |head -2 |tail -1 |awk '{print int($1/1024/1024)" MB"}' -cat $PWD/s3bucket |head -2 |tail -1 |awk '{print int($1/1024/1024/1024)" GB"}' -cat $PWD/s3bucket |head -2 |tail -1 |awk '{print int($1/1024/1024/1024/1024)" TB"} diff --git a/Arthemetic-Operators.sh b/Arthemetic-Operators.sh deleted file mode 100644 index 0a29f3f..0000000 --- a/Arthemetic-Operators.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash -#Purpose: Arthemetic Operators -#Version:1.0 -#Created Date: Wed May 9 21:41:53 IST 2018 -#Modified Date: -#Author: Ankam Ravi Kumar -# START # - -echo -e "Please enter some value: \c" -read -r a -echo -e "Please enter another value: \c" -read -r b - -echo "a+b value is $(($a+$b))" #it will add both the values -echo "a-b value is $(($a-$b))" #it will subtract b form a -echo "axb value is $(($a*$b))" #it will multiply both a and b -echo "a/b value is $(($a/$b))" #it will divide b from a -echo "a%b value is $(($a%$b))" #it will give the remainder when a is divided by b - -echo "Completed successfully" - -# END # diff --git a/AutomateLoginSSH.sh b/AutomateLoginSSH.sh deleted file mode 100644 index 2550268..0000000 --- a/AutomateLoginSSH.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/expect -f -## Testing expect command - -## echo the test -puts "\nGet HostName\n" - -## execute ssh command to connect to remote host -spawn ssh 192.168.175.130 "hostname" - -## Look for password string -expect "password:" - -## Send the password -send "redhat\r" - -puts "\nGet df command output\n" -spawn ssh 192.168.175.130 "df -h" -expect "password:" -send "redhat\r" -interact diff --git a/CpuMemDisk.sh b/CpuMemDisk.sh deleted file mode 100644 index 441fe0c..0000000 --- a/CpuMemDisk.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash -## Collect Multiple Servers CPU, MEM and DISK Utilization and store in single file -# Purpose: To Collect Multiple Servers CPU, MEM, DISK usage in single report -# Version:1.0 -# Created Date: 2019-05-02 -# Modified Date: -# WebSite: https://arkit.co.in -# Author: Ankam Ravi Kumar - -HOSTNAME=$(hostname) -DATET=$(date "+%Y-%m-%d %H:%M:%S") -CPUUSAGE=$(top -b -n 2 -d1 | grep "Cpu(s)" | tail -n1 | awk '{print $2}' |awk -F. '{print $1}') -MEMUSAGE=$(free | grep Mem | awk '{print $3/$2 * 100.0}') -DISKUSAGE=$(df -h / | awk '{print $5}' |tail -n 1 |sed 's/%//g') - -echo 'HostName, Date&Time, CPU(%), MEM(%), DISK(%)' >> /opt/usagereport -echo "$HOSTNAME, $DATET, $CPUUSAGE, $MEMUSAGE, $DISKUSAGE" >> /opt/usagereport - -for i in `cat /scripts/hostlist` -do -RHOST=$(ssh $i hostname) -RDATET=$(ssh $i 'date "+%Y-%m-%d %H:%M:%S"') -RCPUUSAGE=$(ssh $i top -b -n 2 -d1 | grep "Cpu(s)" | tail -n1 | awk '{print $2}' |awk -F. '{print $1}') -RMEMUSAGE=$(ssh $i free | grep Mem | awk '{print $3/$2 * 100.0}') -RDISKUSAGE=$(ssh $i df -P / |column -t | awk '{print $5}' |tail -n 1 |sed 's/%//g') - -echo "$RHOST, $RDATET, $RCPUUSAGE, $RMEMUSAGE, $RDISKUSAGE" >> /opt/usagereport -done diff --git a/Even_or_Odd_Number.sh b/Even_or_Odd_Number.sh deleted file mode 100644 index a8294a1..0000000 --- a/Even_or_Odd_Number.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash -## To find given number is Even number or Odd Number - -read -p "Enter a number: " number - -if [ $((number % 2)) -eq 0 ]; then - echo "$number is an even number." -else - echo "$number is an odd number." -fi diff --git a/ExamResults.sh b/ExamResults.sh deleted file mode 100644 index b718bdf..0000000 --- a/ExamResults.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/bash -#Purpose: Validate and report Student subject marks -#Version:1.0 -#Created Date: 2024 sep -#Modified Date: -#Author: Ankam Ravi Kumar -# START # - -echo -e "Please Enter Maths Marks: \c" -read -r m -echo -e "Please Enter Physics Marks: \c" -read -r p -echo -e "Please Enter Chemistry Marks: \c" -read -r c - -if [ $m -ge 35 -a $p -ge 35 -a $c -ge 35 ]; then -total=`expr $m + $p + $c` -avg=`expr $total / 3` -echo "Total Marks = $total" -echo "Average Marks = $avg" - if [ $avg -ge 75 ]; then - echo "Congrats you got Distinction" - elif [ $avg -ge 60 -a $avg -lt 75 ]; then - echo "Congrats you got First Class" - elif [ $avg -ge 50 -a $avg -lt 60 ]; then - echo "You got second class" - elif [ $avg -ge 35 -a $avg -lt 50 ]; then - echo "You Got Third Class" - fi -else -echo "Sorry You Failed" -fi - -# END # diff --git a/Logical-operators.sh b/Logical-operators.sh deleted file mode 100644 index 3e02552..0000000 --- a/Logical-operators.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -#Purpose: Logical Operators/Boolean Operators. Student Marks Validation. -#Version:1.0 -#Created Date: Sat May 12 21:21:03 IST 2018 -#Modified Date: -#Author: Ankam Ravi Kumar -# START # -echo -e "Enter Your Maths Subject Marks: \c" -read -r m -echo -e "Enter Your Physics Subject Marks: \c" -read -r p -echo -e "Enter Your Chemistry Subject Marks: \c" -read -r c - -if test $m -ge 35 -a $p -ge 35 -a $c -ge 35 -then -echo "Congratulations, You have passed in all subjects" -else -echo "Sorry You not upto mark in one of the subject" -fi -# END # diff --git a/README.md b/README.md deleted file mode 100644 index fff2db0..0000000 --- a/README.md +++ /dev/null @@ -1,115 +0,0 @@ -# Shell Scripting Tutorial - -Keep in touch with for any kind of technical questions - -[Shell Scripting for Amazon Web Services to Manage it's resources](https://github.com/techtutorials/shell-scripting-tutorial/tree/FOTV/AWS) - -https://techtutorials.github.io/shell-scripting-tutorial/ - -* [Facebook](https://www.facebook.com/Linuxarkit/) -* [Email List](https://feedburner.google.com/fb/a/mailverify?uri=arkit) -* [Linkedin](https://in.linkedin.com/in/ravi-kumar-94530121) -* [Twitter](https://twitter.com/aravikumar48) -* [Youtube](https://www.youtube.com/Techarkit?sub_confirmation=1) -* [Email Address](aravikumar48@gmail.com) -* [WhatsApp Group](http://bit.ly/wappg) -* [Linux Telegram Group](http://bit.ly/linux-telegram) -* [Reddit TechTutorials](http://bit.ly/redditark) -* [Tumblr](https://www.tumblr.com/blog/aravikumar48) - -A complete begineers guide to learn shell scripting from scratch which includes Videos, Practice scenarios and project idea. I will create one file for one topic with code. - -Before jumping into the Shell scripting below are commands you have to practice for better understanding and familiar with Linux command line interface. - -If you do not learn below commands also fine but i personally recommend you to learn commands first. - -[103 Linux Commands Video Tutorial](https://www.youtube.com/watch?v=VG-MMju9RhQ&list=PLHyfPDPl-JDX_dfDEpsvglu4x3h1RjPkz) - -alias and unalias, arch, arp, at, awk, bc, blkid, cal, cat, cd, chage, chattr, chgrp, chmod, chown, cp, cpio, crontab, curl, cut, date, dd, df, diff, dig, dnf, du, expr, fdisk, file, find, firewall-cmd, free, ftp, grep, head, history, hostname, id, ifconfig, iostat, ip, kill, last, lessandmore, ln, locate, lpstatandlpadmin, ls, lsof, lspci, mail, man, mdadm, mkdirandrmdir, mkisofs, mount, mutt, mv, nano, netstat, nice, renice, nslookup, passwd, pam_tally2, paste, ping, perloneliner, pkill, ps, pwd, reboot, poweroff, rm, rpm, rsync, scp, screen, sed, sort, ss, ssh, sysctl, tail, tar, tcpdump, top, touch, tr, traceroute, umask, uname, uniq, uptime, useradd, vi, vmstat, w, who, watch, wc, wget, ypcat, yppasswd, yum, zip, sar - -After that start learning shell scripting using below topics - -- [Shell Scripting Video Tutorial](https://www.youtube.com/watch?v=7GNUzvjS_mE&list=PL8cE5Nxf6M6b8qW7CSMsdKbEsPdG9pWfu) -- [Shell Scripting course Overview](https://www.youtube.com/watch?v=7GNUzvjS_mE) -- [Linux Basics](https://www.youtube.com/watch?v=IFvMor-0eFM) -- [Linux Directory Structure](https://www.youtube.com/watch?v=rVxpe1_lNFE) -- [Linux Basic Commands](https://www.youtube.com/watch?v=yYC8aaQ3eZA) -- [Copy, Remove, Move and Time Commands](https://www.youtube.com/watch?v=G7XFreQkDB8) -- [Dif and Grep Commands](https://www.youtube.com/watch?v=RwcQ6JzTsmA) -- [Head, tail, sort and more commands](https://www.youtube.com/watch?v=OgV3qrPQulU) -- [tr and wc commands](https://www.youtube.com/watch?v=d40a5zFa8yI) -- [Disk utilities like fdisk, df and du commands](https://www.youtube.com/watch?v=vx1WZepOmKg) -- [Getting Help From Command Line user Interface](https://www.youtube.com/watch?v=GcYu-0IIJas) -- [w, who, hostnamem hostnamectl and uname commands](https://www.youtube.com/watch?v=7shAr5lp_Wc) -- [Search for files and directories using find and locate commands](https://www.youtube.com/watch?v=Rd6e-OrsHpo) -- [top command its output explanation](https://www.youtube.com/watch?v=UQ7rr4_47YY) -- [vi & vim text editor](https://www.youtube.com/watch?v=K3SUrcJ740Y) -- [sed, awk, vmstat and nestat commands](https://www.youtube.com/watch?v=4hJorSKg9E0) -- [vnstat command](https://www.youtube.com/watch?v=KlpE2Ok6Bxo) -- [Introduction to Graphical user interface](https://www.youtube.com/watch?v=Yck_xhz9ku0) -- [cut command](https://www.youtube.com/watch?v=kBZNJdw7RQQ) -- [Merge multiple files using paste command](https://www.youtube.com/watch?v=_Efd6PxhNq4) -- [Connect and Manage remote machine using SSH](https://www.youtube.com/watch?v=Dp9J7aktYDs) -- [Changing files and directory permissions](https://www.youtube.com/watch?v=NNAxqSyTsUI) -- [tar and zip commands](https://www.youtube.com/watch?v=lVQppyhgERA) -- [Scheduling future jobs using crontab](https://www.youtube.com/watch?v=OOOabNTnSwY) -- [difference between scripting and programming](https://www.youtube.com/watch?v=5UuTNosxNgI) -- [what is shell scripting and it's advantages](https://www.youtube.com/watch?v=m2DvuF_S4Ac) -- [PATH environment variable](https://www.youtube.com/watch?v=4TZyWegxzGY) -- [Symbols used shell scripting](https://www.youtube.com/watch?v=L8IxV7bvBHU) -- [Make Shell Script Template](https://www.youtube.com/watch?v=7KEQJ7jtkTg) -- [Quotes single, double and reverse - Know difference between each](https://www.youtube.com/watch?v=9_fhRI-dos4) -- [Bash colors](https://arkit.co.in/coloring-style-text-shell-scripting/) -- [Script exit status](https://arkit.co.in/shell-scripting-exit-status-shell-scripting-return-codes/) -- [Variables and it's rules](https://www.youtube.com/watch?v=839s_OtTqDA) -- [Special Variables](https://www.youtube.com/watch?v=PfxzX4XNYRE) -- [Environment Variables, system variables and user defined variables](https://www.youtube.com/watch?v=PfxzX4XNYRE) -- [Constant variables, Local & Global variables and Special variables](https://www.youtube.com/watch?v=839s_OtTqDA) -- [Positional Parameters](https://www.youtube.com/watch?v=PfxzX4XNYRE) -- [Count number command line arguments $#](https://www.youtube.com/watch?v=YizjrX9ph10) -- [Arithmetic Operators](https://www.youtube.com/watch?v=qxNQ_D8txPo) -- [Relational Operators](https://www.youtube.com/watch?v=U-u1wx5VeTU) -- [LogicalOperators](https://www.youtube.com/watch?v=m_F1FTKdUU4) -- [Boolean Operators](https://www.youtube.com/watch?v=U-u1wx5VeTU) -- [Maths using expr command](https://www.youtube.com/watch?v=qxNQ_D8txPo) -- [Real maths using bc command](https://www.youtube.com/watch?v=qxNQ_D8txPo) -- [if statement](https://www.youtube.com/watch?v=gncu9vzmILw) -- [if-else statement](https://www.youtube.com/watch?v=nDhbOeEQeNY) -- [if-else-if statement](https://www.youtube.com/watch?v=UJET-9cmaqU) -- [Nested if statement](https://www.youtube.com/watch?v=Kd1SJFnmj9k) -- [Case statement](https://www.youtube.com/watch?v=JJ7mAPU0KhI) -- [For Loop](https://www.youtube.com/watch?v=1fnAUUS4qg0) -- [While Loop](https://www.youtube.com/watch?v=nBMuVIRGpwY) -- [Until Loop](https://www.youtube.com/watch?v=zdk795qFgWk) -- [Functions](https://www.youtube.com/watch?v=jXv1otUXMG4) -- [Arrays](https://www.youtube.com/watch?v=2Fetj2V6rrM) -- [Eval command](https://www.youtube.com/watch?v=AjqBRGwLmLc&list=PL8cE5Nxf6M6b8qW7CSMsdKbEsPdG9pWfu&index=57&t=0s) -- [Shifting parameters using shift command](https://www.youtube.com/watch?v=48j0kxOFKZE) -- [IFS - Input Field Separator](https://www.youtube.com/watch?v=so8IRuhWjEM) -- [Writing CPU Usage script](https://www.youtube.com/watch?v=NQx43bY4lNo) -- [Writing Disk Utilization script](https://www.youtube.com/watch?v=yXhdDV13nrA) -- [Trouble shooting debugging shell scripts](https://www.youtube.com/watch?v=kgj-4_gmvi4) -- [Checking shell script errors and improvements using shellcheck.net site](https://www.youtube.com/watch?v=kgj-4_gmvi4) -- [Here Document to write paragraphs of text](https://www.youtube.com/watch?v=r9lb0ZxGFqE) -- [Getopts Function](https://www.youtube.com/watch?v=j-lEoC0DWI8) -- [Executing Multiple scripts from single script](https://youtu.be/hs-FK681D50) -- [logger logging messages to log file](https://youtu.be/_kMXvtn1RRQ) - -**Resource to Download** - -- [Shell Scripting Book](https://arkit-in.tradepub.com/free/w_wile48/) -- [Shell Scripting Book](https://arkit-in.tradepub.com/free/w_pack42/) -- [Shell Scripting Book](https://arkit-in.tradepub.com/free/w_advb01/) -- [Shell Scripting Book](https://arkit-in.tradepub.com/free/w_wile54/) - -**Write Your Own Method of Script for below Scenario** - -- **Scenario:** Everyday from Monday to Friday one directory will be created under /fullbackup/dailybackup/YYYY-MM-DD and it will move backup to its parent directory everyday midnight /fullbackup/archive/, However Saturday, Sunday and Monday directories will move to /fullbackup/archive path every monday evening. - -- **Directory Names Example:** 2018-12-24 2018-12-25 2018-12-26 2018-12-27 2018-12-28 - -- **Question:** I would like to delete directories older than two days from /fullbackup/archive path. How do you do it using any scripting methods. - -- **Problem Statement:** I was trying to use ```find /path/ -type d -mtime +2 -print0 | xargs -r0 rm --```. This command does not work as expected due to directory modified date for SAT, SUN and MON moved directories same for all as Monday date. - -- **How Do you solve it.??** Write Shell Script to accomplish this task. Should run through crontab and clear directories older than two days. diff --git a/_config.yml b/_config.yml new file mode 100644 index 0000000..c419263 --- /dev/null +++ b/_config.yml @@ -0,0 +1 @@ +theme: jekyll-theme-cayman \ No newline at end of file diff --git a/add.sh b/add.sh deleted file mode 100644 index 8909fed..0000000 --- a/add.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash -################################################## -# Purpose: eval command Evaluating twice -# Version:1.0 -# Created Date: Wed Jun 13 22:09:59 IST 2018 -# Modified Date: -# WebSite: https://arkit.co.in -# Author: Ankam Ravi Kumar -################################################## -# START # - -echo "addition of X+Y" -echo "Enter X" -read X -echo "Enter Y" -read Y -echo "X+Y = $X+$Y = $[ X+Y ]" - -# END # diff --git a/agtb.sh b/agtb.sh deleted file mode 100644 index 0a67093..0000000 --- a/agtb.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash -#Purpose: eval command Evaluating twice -#Version:1.0 -#Created Date: Wed Jun 13 22:09:59 IST 2018 -#Modified Date: -#WebSite: https://arkit.co.in -#Author: Ankam Ravi Kumar -# START # - -echo -e "enter the a value: \c" -read a -echo -e "enter the b value: \c" -read b -if test "$a" -gt "$b" ; then - echo "$a is greater than $b" -else - echo "$b is greater than $a" -fi - -# END # \ No newline at end of file diff --git a/answers.sh b/answers.sh deleted file mode 100644 index 697f19b..0000000 --- a/answers.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/expect - -set timeout -1 - -spawn ./questions.sh -expect "Hi\r" -send -- "Hi\r" - -expect "How are you?\r" -send -- "I am fine\r" - -expect "Whats your Name?\r" -send -- "My name is Ravi\r" - -expect eof diff --git a/arithmetic.sh b/arithmetic.sh deleted file mode 100644 index a6b46d8..0000000 --- a/arithmetic.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash -#Purpose:Arthmetic operators using expr command -#Version:1.0 -#Created Date: Wed May 9 21:47:04 IST 2018 -#Modified Date: -#website: https://arkit.co.in -#Author: Ankam Ravi Kumar -# START # -echo -e "Enter value: \c" -read -r a -echo -e "Enter value: \c" -read -r b - -echo "addition values `expr $a + $b`" -echo "minus values `expr $a - $b`" -echo "multiplied by values `expr $a \* $b`" -echo "devided by values `expr $a / $b`" -echo "remainder values `expr $a % $b`" -echo "addition values `expr $a + $b`" - -echo "Completed Sucessfully" -# END # diff --git a/array.sh b/array.sh deleted file mode 100644 index 7c61603..0000000 --- a/array.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash -#Purpose: Array Example -#Version:1.0 -#Created Date: Mon May 28 22:59:22 IST 2018 -#Modified Date: -#WebSite: https://arkit.co.in -#Author: Ankam Ravi Kumar -# START # - -fruits=( "Apple" "Orange" "Banana" "Sapota" ) -fruits[3]='Green Apple' -for fruit in ${fruits[@]} -do - echo "Fruit Name is $fruit" -done - -echo "Number of Fruits in Bucket is" ${#fruits[@]} -echo "All Fruits ${fruits[@]}" - -# END # diff --git a/casestatement.sh b/casestatement.sh deleted file mode 100644 index e68b229..0000000 --- a/casestatement.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/bash -#Purpose: Example for Case Statement -#Version:1.0 -#WebSite: https://arkit.co.in -#Created Date: Mon May 21 20:37:59 IST 2018 -#Modified Date: -#Author: Ankam Ravi Kumar -# START # -echo -e "Enter a number: \c" -read -r a -echo -e "Enter b number: \c" -read -r b - -echo "1. Sum of values" -echo "2. Substraction" -echo "3. Multiplication" -echo "4. Division" -echo "5. Modulo division" -echo -e "Enter Your Choice from above menu: \c" -read -r ch -case $ch in -1) echo "Sum of $a + $b = "`expr $a + $b`;; -2) echo "Subsctraction = "`expr $a - $b`;; -3) echo "Multiplication = "`expr $a \* $b`;; -4) echo "Division = "`expr $a / $b`;; -5) echo "Modulo Division = "`expr $a % $b`;; -*) echo "Invalid Option provided" -esac -# END # diff --git a/collectroothistory.sh b/collectroothistory.sh deleted file mode 100644 index 6e0c9e1..0000000 --- a/collectroothistory.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash -## Collect Root Commands History - -# Mailing List -MAILLIST="YOUREMAIL@DOMAIN" - -# Log path -AUDLOG="/rootcommands" - -cp /root/.bash_history /tmp/history -sed -i 's/#//g' /tmp/history -for i in `cat /tmp/history |grep ^[0-9]` -do -CONVT=`date -d @$i` -sed -i "s/$i/$CONVT/g" /tmp/history -done - -sed -i 'N;s/\n/ /' /tmp/history -sleep 10 - -/bin/touch ${AUDLOG}$HOSTNAME-root-hist.log.`date +%h%d%y` -/bin/grep "$DATE" /tmp/history > ${AUDLOG}$HOSTNAME-root-hist.log.`date +%h%d%y` -/bin/chmod 0440 ${AUDLOG}$HOSTNAME-root-hist.log.`date +%h%d%y` - -# Mail notification -/bin/cat ${AUDLOG}$HOSTNAME-root-hist.log.`date +%h%d%y` |mail -s "HOST: $HOSTNAME - `whoami` Daily root Commands Log" ${MAILLIST} diff --git a/continue.sh b/continue.sh deleted file mode 100644 index ee5694e..0000000 --- a/continue.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/bash -#Purpose: While loop Continue Statement -#Version:1.0 -#Website: https://arkit.co.in -#Created Date: Tue May 22 22:03:02 IST 2018 -#Modified Date: -#Author: Ankam Ravi Kumar -# START # -opt=y -while [ $opt = y -o $opt = Y ] -do -echo -e "Please enter the number: \c" -read -r num -if [ $num -le 50 ]; then -sq=`expr $num \* $num` -echo "Square of provided number $num: $sq" -else -echo "Number not in the given Range" -fi - -echo -e "Do you want to continue [y/n]: \c" -read -r wish -if [ $wish = y -o $wish = Y ]; then -continue -else -echo "Thank You for Exiting.." -exit -fi -done - -# END # diff --git a/convert_and_update_mysql.sh b/convert_and_update_mysql.sh deleted file mode 100644 index 98f4d25..0000000 --- a/convert_and_update_mysql.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/bin/bash - -n=1 -until [ $n -gt 11196 ] -do -EXIRECORDS=$(mysql -u root -pPASSWORD -h 192.168.2.100 -e "SELECT sn,tarsize from DATABASE.Table1 where sn='"$n"'" |tail -n1 |grep $n) - -RECORDNUMBER=$(echo $EXIRECORDS |awk '{print $1}') -FOLDERSIZE=$(echo $EXIRECORDS |awk '{print $2}') - -KB=$(echo $EXIRECORDS |awk '{print $2}' |grep K |wc -l) - if [ $KB -ge 1 ]; then - K=$(echo $EXIRECORDS |awk '{print $2}' |sed 's/K//g') - BYTES=$($K * 1024 |bc |awk -F. '{print $1}') - mysql -u root -pPASSWORD -h 192.168.2.100 -e "UPDATE DATABASE.Table1 SET tarsize='"$BYTES"' where sn='"$RECORDNUMBER"'" - fi - -MB=$(echo $EXIRECORDS |awk '{print $2}' |grep M |wc -l) - if [ $MB -ge 1 ]; then - M=$(echo $EXIRECORDS |awk '{print $2}' |sed 's/M//g') - BYTES=$(echo $M*1024*1024 |bc |awk -F. '{print $1}') - mysql -u root -pPASSWORD -h 192.168.2.100 -e "UPDATE DATABASE.Table1 SET tarsize='"$BYTES"' where sn='"$RECORDNUMBER"'" - fi - -GB=$(echo $EXIRECORDS |awk '{print $2}' |grep G |wc -l) - if [ $GB -ge 1 ]; then - G=$(echo $EXIRECORDS |awk '{print $2}' |sed 's/G//g') - BYTES=$(echo $G*1024*1024*1024 |bc |awk -F. '{print $1}') - mysql -u root -pPASSWORD -h 192.168.2.100 -e "UPDATE DATABASE.Table1 SET tarsize='"$BYTES"' where sn='"$RECORDNUMBER"'" - fi - -TB=$(echo $EXIRECORDS |awk '{print $2}' |grep T |wc -l) - if [ $TB -ge 1 ]; then - T=$(echo $EXIRECORDS |awk '{print $2}' |sed 's/T//g') - BYTES=$(echo $T*1024*1024*1024*1024 |bc |awk -F. '{print $1}') - mysql -u root -pPASSWORD -h 192.168.2.100 -e "UPDATE DATABASE.Table1 SET tarsize='"$BYTES"' where sn='"$RECORDNUMBER"'" - fi - - -n=`expr "$n" + 1` - -done diff --git a/countargs.sh b/countargs.sh deleted file mode 100644 index e25e305..0000000 --- a/countargs.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash -################################################## -# Purpose: Counting given postional parameters. -# Version:1.0 -# Created Date: Mon May 7 21:55:05 IST 2018 -# Modified Date: -# Author: Ankam Ravi Kumar -################################################## - -# START # -echo "Your current given parameters are $#" -if [ $# -lt 1 ];then -echo "Program Usage is './scriptname.sh' options" -else -echo "Program executed successfully" -fi -# END # diff --git a/cpualert.sh b/cpualert.sh deleted file mode 100644 index a5c6b13..0000000 --- a/cpualert.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/bash -#Purpose: Real time CPU utilization Monitoring -#Version:1.0 -#Created Date: Tue Jun 5 21:33:38 IST 2018 -#Modified Date: -#WebSite: https://arkit.co.in -#Author: Ankam Ravi Kumar -# START # -PATHS="/" -HOSTNAME=$(hostname) -CRITICAL=98 -WARNING=90 -CRITICALMail="YOUREMAILaddresS@Domain.com" -MAILWAR="YOUREMAIL@Domain.in" -mkdir -p /var/log/cputilhist -LOGFILE=/var/log/cputilhist/cpusage-`date +%h%d%y`.log - -touch $LOGFILE - -for path in $PATHS -do - CPULOAD=`top -b -n 2 -d1 | grep "Cpu(s)" | tail -n1 | awk '{print $2}' |awk -F. '{print $1}'` -if [ -n $WARNING -a -n $CRITICAL ]; then -if [ "$CPULOAD" -ge "$WARNING" -a "$CPULOAD" -lt "$CRITICAL" ]; then -echo "`date "+%F %H:%M:%S"` WARNING - $CPULOAD on Host $HOSTNAME" >> $LOGFILE -echo "Warning Cpuload $CPULOAD Host is $HOSTNAME" | mail -s "CPULOAD is Warning" $MAILWAR -exit 1 -elif [ "$CPULOAD" -ge "$CRITICAL" ]; then -echo "`date "+%F %H:%M:%S"` CRITICAL - $CPULOAD on Host $HOSTNAME" >> $LOGFILE -echo "CRITICAL Cpuload $CPULOAD Host is $HOSTNAME" | mail -s "CPULOAD is CRITICAL" $CRITICALMail -exit 2 -else -echo "`date "+%F %H:%M:%S"` OK - $CPULOAD on $HOSTNAME" >> $LOGFILE -exit 0 -fi -fi -done - -# END # diff --git a/details.sh b/details.sh deleted file mode 100644 index cf701a3..0000000 --- a/details.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash -#Purpose: eval command Evaluating twice -#Version:1.0 -#Created Date: Wed Jun 13 22:09:59 IST 2018 -#Modified Date: -#WebSite: https://arkit.co.in -#Author: Ankam Ravi Kumar -# START # - -echo "WEL COME TO $USERNAME" -echo "Your present working directory is `pwd`" -echo "current logged in users are `who`" -echo "Today date is `date`" - -# END # diff --git a/diskover-2.1.1.zip b/diskover-2.1.1.zip deleted file mode 100644 index 8bf687f..0000000 Binary files a/diskover-2.1.1.zip and /dev/null differ diff --git a/diskspace.sh b/diskspace.sh deleted file mode 100644 index f1de88f..0000000 --- a/diskspace.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash -#Purpose: Monitoring Disk Space Utilization and Send Email Alert -#Version:1.0 -#Created Date: Wed Jun 6 22:38:01 IST 2018 -#Modified Date: -#WebSite: https://arkit.co.in -#Author: Ankam Ravi Kumar -# START # -THRESHOULD=40 -mailto="root" -HOSTNAME=$(hostname) - -for path in `/bin/df -h | grep -vE 'Filesystem|tmpfs' | awk '{print $5}' |sed 's/%//g'` -do - if [ $path -ge $THRESHOULD ]; then - df -h | grep $path% >> /tmp/temp - fi -done - -VALUE=`cat /tmp/temp | wc -l` - if [ $VALUE -ge 1 ]; then - mail -s "$HOSTNAME Disk Usage is Critical" $mailto < /tmp/temp - fi - -#rm -rf /tmp/temp - - -# END # diff --git a/echo.sh b/echo.sh deleted file mode 100644 index f8e8f8c..0000000 --- a/echo.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash -#Purpose: eval command Evaluating twice -#Version:1.0 -#Created Date: Wed Jun 13 22:09:59 IST 2018 -#Modified Date: -#WebSite: https://arkit.co.in -#Author: Ankam Ravi Kumar -# START # - -echo "current location files are `ls`" -echo "current working directory is `pwd`" - -# END # diff --git a/eval.sh b/eval.sh deleted file mode 100644 index 1d9bcf1..0000000 --- a/eval.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash -#Purpose: eval command Evaluating twice -#Version:1.0 -#Created Date: Wed Jun 13 22:09:59 IST 2018 -#Modified Date: -#WebSite: https://arkit.co.in -#Author: Ankam Ravi Kumar -# START # -COMMAND="ls -ltr /etc" -echo "$COMMAND" -eval $COMMAND -# END # diff --git a/for-loop.sh b/for-loop.sh deleted file mode 100644 index d431716..0000000 --- a/for-loop.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash -#Purpose: For loop example -#Version:1.0 -#website: https://arkit.co.in -#Created Date: Wed May 16 19:26:02 IST 2018 -#Modified Date: -#Author: Ankam Ravi Kumar -# START # -for server in `cat /scripts/servers` -do -ping -c 1 $server > /tmp/ping -valid=`echo $?` -if [ $valid -eq 0 ]; then -echo "$server is up" -else -echo "$server is Down" -fi -done -# END # diff --git a/forloop.sh b/forloop.sh deleted file mode 100644 index c423d12..0000000 --- a/forloop.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash -#Purpose: One more example for for loop -#Version: -#Created Date: Wed May 16 19:31:50 IST 2018 -#Modified Date: -#Author: Ankam Ravi Kumar -# START # -for i in 1 2 3 4 5 -do -echo $i -done -# END # diff --git a/function.sh b/function.sh deleted file mode 100644 index 48dbf17..0000000 --- a/function.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash -#Purpose: Function example. Taking Backup of Particular File -#Version:1.0 -#Created Date: 2024 Sep 21 -#Modified Date: -#WebSite: https://arkit.co.in -#Author: Ankam Ravi Kumar - -# START # -function takebackup (){ - if [ -f $1 ]; then - BACKUP="/home/aravi/$(basename ${1}).$(date +%F).$$" - echo "Backing up $1 to ${BACKUP}" - cp $1 $BACKUP - fi -} - -takebackup /etc/hosts - if [ $? -eq 0 ]; then - echo "BAckup Success" - fi -function testing (){ -echo "Just TEsting Function" -} - -testing -# END # diff --git a/functions.sh b/functions.sh deleted file mode 100644 index 61e1a95..0000000 --- a/functions.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -#Purpose: Example for Functions -#Version:1.0 -#Created Date: Sat May 26 00:17:19 IST 2018 -#Modified Date: -#WebSite: https://arkit.co.in -#Author: Ankam Ravi Kumar -# START # -function takebackup (){ - if [ -f $1 ]; then - BACKUP="/tmp/$(basename ${1}).$(date +%F).$$" - echo "Backing up $1 to ${BACKUP}" - cp $1 $BACKUP - fi -} - -takebackup /etc/hosts - if [ $? -eq 0 ]; then - echo "Backup Success" -fi -# END # diff --git a/generate_win_host_config.sh b/generate_win_host_config.sh deleted file mode 100644 index cc6259e..0000000 --- a/generate_win_host_config.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash -## Purpose: To Generate Nagios Configuration files within minute of time. -## Author: Ankam Ravi Kumar - -mkdir -p /scripts/WinServers -cat /scripts/serverlist.txt | while read LINE -do - HostIP=`echo $LINE | cut -d, -f1` - HostName=`echo $LINE | cut -d, -f2` - -NSCLIENTSTATE=$(/usr/local/nagios/libexec/check_nt -H $HostIP -p 12489 -v CLIENTVERSION -s Password | echo $?) -if [ $NSCLIENTSTATE -eq 0 ]; then - sed -e "s/XXXX/$HostName/g; s/ZZZZ/$HostIP/g" /scripts/Template-Windows.cfg > /scripts/WinServers/$HostName.cfg - -for i in D E F G H I J K L M N O P Q R S T U V W X Y Z; -do -/usr/local/nagios/libexec/check_nt -H $HostIP -p 12489 -v USEDDISKSPACE -s Password -l $i -w 90 -c 95 -COMMANDSTATUS=$(echo $?) -if [ $COMMANDSTATUS -eq 0 ] || [ $COMMANDSTATUS -eq 2 ];then -sed -e "s/XXXX/$HostName/g; s/ZZZZ/$i/g" /scripts/Drives.cfg >> /scripts/WinServers/$HostName.cfg -fi -done -fi -done diff --git a/getopts.sh b/getopts.sh deleted file mode 100644 index 4028ba9..0000000 --- a/getopts.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash -#Purpose: Getopts Examples working with arguments -#Version:1.0 -#Created Date: Wed May 30 22:30:51 IST 2018 -#Modified Date: -#WebSite: https://arkit.co.in -#Author: Ankam Ravi Kumar -# START # - -while getopts :a:b: options; do - case $options in - a) ap=$OPTARG;; - b) bo=$OPTARG;; - ?) echo "I Dont know What is $OPTARG is" - esac -done - -echo "Option A = $ap and Option B = $bo" - -# END # diff --git a/helloworld.sh b/helloworld.sh deleted file mode 100644 index 49967e6..0000000 --- a/helloworld.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash -#Purpose: This is the Sample template File -#Version: 1.0 -#Created Date: Thu May 3 11:55:43 IST 2018 -#Modified Date: -#Author: Ankam Ravi Kumar -# START # -echo "Testing template file" -# END # diff --git a/heredoc.sh b/heredoc.sh deleted file mode 100644 index 2f9a966..0000000 --- a/heredoc.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash -#Purpose: Here Document Example -#Version:1.0 -#Created Date: Tue Jun 12 22:50:23 IST 2018 -#Modified Date: -#WebSite: https://arkit.co.in -#Author: Ankam Ravi Kumar -# START # -ftp -n <<- EOF 2> /dev/null - open ftp.server.com - user ftp ftp - ascii - cd uploadfolder - mput file1 file1 file2 - bye -EOF - diff --git a/hi.sh b/hi.sh deleted file mode 100644 index 6652c64..0000000 --- a/hi.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash -#Purpose: eval command Evaluating twice -#Version:1.0 -#Created Date: Wed Jun 13 22:09:59 IST 2018 -#Modified Date: -#WebSite: https://arkit.co.in -#Author: Ankam Ravi Kumar -# START # - -tmp=`date | cut -c12-13` -if [ $tmp -lt 11 ] ; then -echo "Good Mornind have a nice day $USERNAME" -elif [ $tmp -gt 11 -a $tmp -lt 16 ] ; then -echo "Good Ofter noon $USERNAME" -elif [ $tmp -gt 15 -a $tmp -lt 19 ] ; then -echo "Good Evening $USERNAME" -else -echo "Good Night Sweet dreams $USERNAME" -fi -echo "Now the time is `date |cut -c12-19`" - -# END # diff --git a/if-elif-if.sh b/if-elif-if.sh deleted file mode 100644 index da88e28..0000000 --- a/if-elif-if.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash -#Purpose: Find biggest Number among 4 digits -#Version:1.0 -#Created Date: Wed May 16 18:45:58 IST 2018 -#Modified Date: -#Author: Ankam Ravi Kumar -# START # - -echo -e "Please Enter a Value: \c" -read -r a -echo -e "Please Enter b Value: \c" -read -r b -echo -e "Please Enter c Value: \c" -read -r c -echo -e "Please Enter d Value: \c" -read -r d - -if [ $a -gt $b -a $a -gt $c -a $a -gt $d ]; then -echo "$a a is big" -elif [ $b -gt $c -a $b -gt $d ]; then -echo "$b b is big" -elif [ $c -gt $d ]; then -echo "$c c is big" -else -echo "$d d is big" -fi - -# END # diff --git a/if-else-statement.sh b/if-else-statement.sh deleted file mode 100644 index 7e5b04f..0000000 --- a/if-else-statement.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash -#Purpose: If else statement example -#Version:1.0 -#Created Date: Sat May 12 23:49:15 IST 2018 -#Modified Date: -#Website: https://arkit.co.in -#Author: Ankam Ravi Kumar -# START # -echo -e "Enter any value: \c" -read -r a -echo -e "Enter any value: \c" -read -r b - -if [ $a -gt $b ]; then -echo "$a is greater than $b" -else -echo "$b is greater than $a" -fi -# END # diff --git a/if-statement.sh b/if-statement.sh deleted file mode 100644 index 2d99ec4..0000000 --- a/if-statement.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash -#Purpose: If statement example -#Version:1.0 -#Created Date: Sat May 12 23:41:50 IST 2018 -#Modified Date: -#Author: Ankam Ravi Kumar -# START # -echo -e "Please provide Value below ten: \c" -read -r value - -if [ $value -le 10 ] -then -echo "You provided value is $value" -touch /tmp/test{1..100}.txt -echo "Script completed successfully" -fi - -# END # diff --git a/ifs.sh b/ifs.sh deleted file mode 100644 index 9663330..0000000 --- a/ifs.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash -#Purpose: Internal Field Seperator -#Version:1.0 -#Created Date: Wed Jun 13 21:58:18 IST 2018 -#Modified Date: -#WebSite: https://arkit.co.in -#Author: Ankam Ravi Kumar -# START # -LINE=`cat /etc/passwd |grep $1` -IFS=: -set $LINE -echo "User Name = $1" -echo "Password = $2" -echo "UID = $3" -echo "GID = $4" -echo "Description = $5" -echo "Home Directory = $6 " -echo " Current Shell = $7" - -# END # diff --git a/index.md b/index.md new file mode 100644 index 0000000..12be9d7 --- /dev/null +++ b/index.md @@ -0,0 +1,169 @@ +# Shell Scripting Tutorial for Beginners + +Keep in touch with for any kind of technical questions +[Facebook](https://www.facebook.com/Linuxarkit/) +[Email List](https://feedburner.google.com/fb/a/mailverify?uri=arkit) +[Linkedin](https://in.linkedin.com/in/ravi-kumar-94530121) +[Google Plus](https://plus.google.com/u/0/+RedhatEnterpriseLinuxStepbyStepGuide/posts) +[Twitter](https://twitter.com/aravikumar48) +[Youtube](https://www.youtube.com/Techarkit?sub_confirmation=1) +[Email Address](aravikumar48@gmail.com) + +A complete begineers guide to learn shell scripting from scratch which includes Videos, Practice scenarios and project idea. I will create one file for one topic with code. + +Before jumping into the Shell scripting below are commands you have to practice for better understanding and familiar with Linux command line interface. + +If you do not learn below commands also fine but i personally recommend you to learn commands first. + +[103 Linux Commands Video Tutorial](https://www.youtube.com/watch?v=VG-MMju9RhQ&list=PLHyfPDPl-JDX_dfDEpsvglu4x3h1RjPkz) + +alias and unalias, arch, arp, at, awk, bc, blkid, cal, cat, cd, chage, chattr, chgrp, chmod, chown, cp, cpio, crontab, curl, cut, date, dd, df, diff, dig, dnf, du, expr, fdisk, file, find, firewall-cmd, free, ftp, grep, head, history, hostname, id, ifconfig, iostat, ip, kill, last, lessandmore, ln, locate, lpstatandlpadmin, ls, lsof, lspci, mail, man, mdadm, mkdirandrmdir, mkisofs, mount, mutt, mv, nano, netstat, nice, renice, nslookup, passwd, pam_tally2, paste, ping, perloneliner, pkill, ps, pwd, reboot, poweroff, rm, rpm, rsync, scp, screen, sed, sort, ss, ssh, sysctl, tail, tar, tcpdump, top, touch, tr, traceroute, umask, uname, uniq, uptime, useradd, vi, vmstat, w, who, watch, wc, wget, ypcat, yppasswd, yum, zip, sar + +After that start learning shell scripting using below topics + +[Shell Scripting Video Tutorial](https://www.youtube.com/watch?v=7GNUzvjS_mE&list=PL8cE5Nxf6M6b8qW7CSMsdKbEsPdG9pWfu) + +[Shell Scripting course Overview](https://www.youtube.com/watch?v=7GNUzvjS_mE) + +[Linux Basics](https://www.youtube.com/watch?v=IFvMor-0eFM) + +[Linux Directory Structure](https://www.youtube.com/watch?v=rVxpe1_lNFE) + +[Linux Basic Commands](https://www.youtube.com/watch?v=yYC8aaQ3eZA) + +[Copy, Remove, Move and Time Commands](https://www.youtube.com/watch?v=G7XFreQkDB8) + +[Dif and Grep Commands](https://www.youtube.com/watch?v=RwcQ6JzTsmA) + +[Head, tail, sort and more commands](https://www.youtube.com/watch?v=OgV3qrPQulU) + +[tr and wc commands](https://www.youtube.com/watch?v=d40a5zFa8yI) + +[Disk utilities like fdisk, df and du commands](https://www.youtube.com/watch?v=vx1WZepOmKg) + +[Getting Help From Command Line user Interface](https://www.youtube.com/watch?v=GcYu-0IIJas) + +[w, who, hostnamem hostnamectl and uname commands](https://www.youtube.com/watch?v=7shAr5lp_Wc) + +[Search for files and directories using find and locate commands](https://www.youtube.com/watch?v=Rd6e-OrsHpo) + +[top command its output explanation](https://www.youtube.com/watch?v=UQ7rr4_47YY) + +[vi & vim text editor](https://www.youtube.com/watch?v=K3SUrcJ740Y) + +[sed, awk, vmstat and nestat commands](https://www.youtube.com/watch?v=4hJorSKg9E0) + +[vnstat command](https://www.youtube.com/watch?v=KlpE2Ok6Bxo) + +[Introduction to Graphical user interface](https://www.youtube.com/watch?v=Yck_xhz9ku0) + +[cut command](https://www.youtube.com/watch?v=kBZNJdw7RQQ) + +[Merge multiple files using paste command](https://www.youtube.com/watch?v=_Efd6PxhNq4) + +[Connect and Manage remote machine using SSH](https://www.youtube.com/watch?v=Dp9J7aktYDs) + +[Changing files and directory permissions](https://www.youtube.com/watch?v=NNAxqSyTsUI) + +[tar and zip commands](https://www.youtube.com/watch?v=lVQppyhgERA) + +[Scheduling future jobs using crontab](https://www.youtube.com/watch?v=OOOabNTnSwY) + +[difference between scripting and programming](https://www.youtube.com/watch?v=5UuTNosxNgI) + +[what is shell scripting and it's advantages](https://www.youtube.com/watch?v=m2DvuF_S4Ac) + +[PATH environment variable](https://www.youtube.com/watch?v=4TZyWegxzGY) + +[Symbols used shell scripting](https://www.youtube.com/watch?v=L8IxV7bvBHU) + +[Make Shell Script Template](https://www.youtube.com/watch?v=7KEQJ7jtkTg) + +[Quotes single, double and reverse - Know difference between each](https://www.youtube.com/watch?v=9_fhRI-dos4) + +[Bash colors](https://arkit.co.in/coloring-style-text-shell-scripting/) + +[Script exit status](https://arkit.co.in/shell-scripting-exit-status-shell-scripting-return-codes/) + +[Variables and it's rules](https://www.youtube.com/watch?v=839s_OtTqDA) + +[Special Variables](https://www.youtube.com/watch?v=PfxzX4XNYRE) + +[Environment Variables, system variables and user defined variables](https://www.youtube.com/watch?v=PfxzX4XNYRE) + +[Constant variables, Local & Global variables and Special variables](https://www.youtube.com/watch?v=839s_OtTqDA) + +[Positional Parameters](https://www.youtube.com/watch?v=PfxzX4XNYRE) + +[Count number command line arguments $#](https://www.youtube.com/watch?v=YizjrX9ph10) + +[Arithmetic Operators](https://www.youtube.com/watch?v=qxNQ_D8txPo) + +[Relational Operators](https://www.youtube.com/watch?v=U-u1wx5VeTU) + +[LogicalOperators](https://www.youtube.com/watch?v=m_F1FTKdUU4) + +[Boolean Operators](https://www.youtube.com/watch?v=U-u1wx5VeTU) + +[Maths using expr command](https://www.youtube.com/watch?v=qxNQ_D8txPo) + +[Real maths using bc command](https://www.youtube.com/watch?v=qxNQ_D8txPo) + +[if statement](https://www.youtube.com/watch?v=gncu9vzmILw) + +[if-else statement](https://www.youtube.com/watch?v=nDhbOeEQeNY) + +[if-else-if statement](https://www.youtube.com/watch?v=UJET-9cmaqU) + +[Nested if statement](https://www.youtube.com/watch?v=Kd1SJFnmj9k) + +[Case statement](https://www.youtube.com/watch?v=JJ7mAPU0KhI) + +[For Loop](https://www.youtube.com/watch?v=1fnAUUS4qg0) + +[While Loop](https://www.youtube.com/watch?v=nBMuVIRGpwY) + +[Until Loop](https://www.youtube.com/watch?v=zdk795qFgWk) + +[Functions](https://www.youtube.com/watch?v=jXv1otUXMG4) + +[Arrays](https://www.youtube.com/watch?v=2Fetj2V6rrM) + +[Eval command](https://www.youtube.com/watch?v=AjqBRGwLmLc&list=PL8cE5Nxf6M6b8qW7CSMsdKbEsPdG9pWfu&index=57&t=0s) + +[Shifting parameters using shift command](https://www.youtube.com/watch?v=48j0kxOFKZE) + +[IFS - Input Field Separator](https://www.youtube.com/watch?v=so8IRuhWjEM) + +[Writing CPU Usage script](https://www.youtube.com/watch?v=NQx43bY4lNo) + +[Writing Disk Utilization script](https://www.youtube.com/watch?v=yXhdDV13nrA) + +[Trouble shooting debugging shell scripts](https://www.youtube.com/watch?v=kgj-4_gmvi4) + +[Checking shell script errors and improvements using shellcheck.net site](https://www.youtube.com/watch?v=kgj-4_gmvi4) + +[Here Document to write paragraphs of text](https://www.youtube.com/watch?v=r9lb0ZxGFqE) + +[Getopts Function](https://www.youtube.com/watch?v=j-lEoC0DWI8) + +Tput making menu's + +Executing Multiple scripts from single script + +$(()) - Pass command to sub-shell + +logger logging messages to log file + +Exec to send input to terminal + +Resource to Download + +[Shell Scripting Book](https://arkit-in.tradepub.com/free/w_wile48/) + +[Shell Scripting Book](https://arkit-in.tradepub.com/free/w_pack42/) + +[Shell Scripting Book](https://arkit-in.tradepub.com/free/w_advb01/) + +[Shell Scripting Book](https://arkit-in.tradepub.com/free/w_wile54/) + diff --git a/info.sh b/info.sh deleted file mode 100644 index caac61a..0000000 --- a/info.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash -#Purpose: eval command Evaluating twice -#Version:1.0 -#Created Date: Wed Jun 13 22:09:59 IST 2018 -#Modified Date: -#WebSite: https://arkit.co.in -#Author: Ankam Ravi Kumar -# START # - -echo "Hi you there" -echo "what is your name? (Type your name here and press Enter)" -read NM -echo "Hi $NM Good Morning" -echo "your currently logged in as $USERNAME" -echo "your present working directory is `pwd`" - -# END # diff --git a/memusage.sh b/memusage.sh deleted file mode 100644 index 45187ca..0000000 --- a/memusage.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash -## Monitoring Memory usage of the server -# Version:1.0 -# Created Date: 2022-Jan-07 -# WebSite: https://arkit.co.in -# Author: Ankam Ravi Kumar - -HOSTNAME=$(hostname) -DATED=$(date "+%Y-%m-%d %H:%M:%S") -THRESHOLD=80 -TOADDRESS=aravikumar48@gmail.com - -MEMUSAGE=$(free | grep Mem | awk '{print $3/$2 * 100.0}' |awk -F. '{print $1}') -if [ $MEMUSAGE -ge $THRESHOLD ]; then -echo "$HOSTNAME, $DATED, %MEMUSAGE" >> /var/log/memusage_history -echo "$HOSTNAME, $DATED, %MEMUSAGE" > /tmp/memusage -mail -s "$HOSTNAME $DATED Mem Usage: $MEMUSAGE" $TOADDRESS <<< /tmp/memusage -fi diff --git a/morethanxdays.sh b/morethanxdays.sh deleted file mode 100644 index 2a89a07..0000000 --- a/morethanxdays.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash -## Delete the Directories older than 2 days based on directory name validation -## Refer YouTube Link for Explanation https://youtu.be/1Sh6PWcgXAA -ls -ltr /fullbackup/archive/ | awk '{print $9}' > /scripts/dirs -for i in `cat /scripts/dirs`; do -STARTTIME=$(date +%s -d"$i 00:00:00") -ENDTIME=$(date +%s) -echo $((ENDTIME-STARTTIME)) | awk '{print int($1/60)}' > /scripts/value -COUNT=`cat /scripts/value` -if [ $COUNT -gt 2880 ]; then -echo "Directories are older than 2days $i" >> /scripts/joblog -rm -rf /fullbackup/archive/$i -fi -done diff --git a/multiplication.sh b/multiplication.sh deleted file mode 100644 index b135a70..0000000 --- a/multiplication.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash -#Purpose: eval command Evaluating twice -#Version:1.0 -#Created Date: Wed Jun 13 22:09:59 IST 2018 -#Modified Date: -#WebSite: https://arkit.co.in -#Author: Ankam Ravi Kumar -# START # - -echo "multification of X*Y" -echo "Enter X" -read X -echo "Enter Y" -read Y -echo "X*Y = $X*$Y = $[ X*Y ]" - -# END # \ No newline at end of file diff --git a/myfirstscript.sh b/myfirstscript.sh deleted file mode 100644 index 2c39c40..0000000 --- a/myfirstscript.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash -#Purpose: This is my first script in this shell scripting video tutorial -#Date: Wed May 2 17:10:13 IST 2018 -#Author: Ankam Ravi Kumar -#Version: 1.0 -#Modified Date: -#Modified by: - -# START -echo "Welcome $USERNAME" -echo "Your present working directory is `pwd`" -echo "Today date is `date`" -# END diff --git a/nestedif.sh b/nestedif.sh deleted file mode 100644 index 17d421b..0000000 --- a/nestedif.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/bash -#Purpose: Validate and report Student subject marks -#Version:1.0 -#Created Date: Wed May 16 19:00:52 IST 2018 -#Modified Date: -#Author: Ankam Ravi Kumar -# START # - -echo -e "Please Enter Maths Marks: \c" -read -r m -echo -e "Please Enter Physics Marks: \c" -read -r p -echo -e "Please Enter Chemistry Marks: \c" -read -r c - -if [ $m -ge 35 -a $p -ge 35 -a $c -ge 35 ]; then -total=`expr $m + $p + $c` -avg=`expr $total / 3` -echo "Total Marks = $total" -echo "Average Marks = $avg" - if [ $avg -ge 75 ]; then - echo "Congrats you got Distinction" - elif [ $avg -ge 60 -a $avg -lt 75 ]; then - echo "Congrats you got First Class" - elif [ $avg -ge 50 -a $avg -lt 60 ]; then - echo "You got second class" - elif [ $avg -ge 35 -a $avg -lt 50 ]; then - echo "You Got Third Class" - fi -else -echo "Sorry You Failed" -fi - -# END # diff --git a/or-operator.sh b/or-operator.sh deleted file mode 100644 index 2931df0..0000000 --- a/or-operator.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash -#Purpose: OR operator example -#Version:1.0 -#Created Date: Sat May 12 21:26:51 IST 2018 -#Modified Date: -#Author: Ankam Ravi Kumar -# START # - -echo -e "Enter First Numeric Value: \c" -read -r t -echo -e "Enter Second Numeric Value: \c" -read -r b - -if [ $t -le 20 -o $b -ge 30 ]; then -echo "Statement is True" -else -echo "False Statement, Try Again." -fi - -# END # diff --git a/oroper.sh b/oroper.sh deleted file mode 100644 index af78a02..0000000 --- a/oroper.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash -#Website: https://arkit.co.in -if ! [[ $1 -lt 20 || $2 -ge 30 ]]; then -echo "Statement is True" -else -echo "Statment is False" -fi diff --git a/questions.sh b/questions.sh deleted file mode 100644 index c93a791..0000000 --- a/questions.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash -## Questions - -echo "Hi" -read $REPLY - -echo "How are you?" -read $REPLY - -echo "Whats your Name?" -read $REPLY diff --git a/quotes.sh b/quotes.sh deleted file mode 100644 index f66f673..0000000 --- a/quotes.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash -#Purpose: Verifying Difference between quotation marks -#Version: 1.0 -#Created Date: Fri May 4 20:16:55 IST 2018 -#Modified Date: -#Author: Ankam Ravi Kumar -# START # -VAR1=123456 -TEST=TechArkit - -# Double Quotes -echo "Execute double quotes $VAR1 $TEST" - -# Single Quotes -echo 'Excute Single Quotes $VAR1 $TEST' - -# Reverse Quotes -echo "This Hostname is: `cal`" - -# END # diff --git a/regex.sh b/regex.sh deleted file mode 100755 index 376bb77..0000000 --- a/regex.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/bash -#Purpose: regex examples -#Version: 1.0 -#Create Date: Sun Nov 27 00:27:33 EST 2022 -#Modified Date: - -# START # - -numString1="1234" -numString2="16789" -numString3="1579" - - -echo "Example 1" -if [[ $numString1 =~ ^1 ]]; then - echo "String \"$numString1\" starts with a \"1\", and matches regex: ^1" -fi - -echo "Example 2" -if [[ $numString2 =~ ^1 ]]; then - echo "String \"$numString2\" starts with a \"1\", and matches regex: ^1" -fi - -echo "Example 3" -if [[ $numString3 =~ ^1.7 ]]; then - echo "String \"$numString2\" starts with a \"1\", followed by any character, and followed by a 7. " - echo "This string matches the regex: ^1.7" -fi - -echo "Example 4" -if [[ ! $numString1 =~ ^1.7 ]]; then - echo "String \"$numString1\" does not start with a \"1\", followed by any character, and followed by a 7. " - echo "This string does not match the regex: ^1.7" -fi - -echo "Example 5" -if [[ $numString2 =~ 9$ ]]; then - echo "String \"$numString2\" ends with a \"9\", and matches the regex: 9$" -fi - diff --git a/relationaloper.sh b/relationaloper.sh deleted file mode 100644 index 5b35a7a..0000000 --- a/relationaloper.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash -#Purpose: Relational Operators examples -#Version:1.0 -#Created Date: Thu May 10 22:43:16 IST 2018 -#Modified Date: -# Website: https://arkit.co.in -#Author: Ankam Ravi Kumar -# START # -echo -e "Please provide one number: \c" -read -r h -echo -e "Please provide one number: \c" -read -r g - -test $h -lt $g;echo "$?"; -test $h -le $g;echo "$?"; -test $h -gt $g;echo "$?"; -test $h -ge $g;echo "$?"; -test $h -eq $g;echo "$?"; -test $h -ne $g;echo "$?"; -# END # diff --git a/remoteload.sh b/remoteload.sh deleted file mode 100644 index 83da24b..0000000 --- a/remoteload.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash -################################################## -# # -# Author: Ankam Ravi Kumar # -# Website: server-computer.com # -# Date: 23-02-2019 16:59:56 # -# Purpose: Capture and Store System Load Average # -# CPU Usage and Memory Usage # -################################################## -# Log File Path -LOGFILE=/var/log/systemload.log - -echo "" > /tmp/remotelog - -for i in `cat /opt/hostnames`; -do -cat /root/systemload.sh | ssh $i >> /tmp/remotelog -done - -cat /tmp/remotelog |grep -vE "^Last|^There" >> $LOGFILE diff --git a/rhcsa-ex200-certification.md b/rhcsa-ex200-certification.md new file mode 100644 index 0000000..b0523d5 --- /dev/null +++ b/rhcsa-ex200-certification.md @@ -0,0 +1,9 @@ +A Red Hat Certified System Administrator (RHCSA) is able to perform the following tasks: + +Understand and use essential tools for handling files, directories, command-line environments, and documentation +Operate running systems, including booting into different run levels, identifying processes, starting and stopping virtual machines, and controlling services +Configure local storage using partitions and logical volumes +Create and configure file systems and file system attributes, such as permissions, encryption, access control lists, and network file systems +Deploy, configure, and maintain systems, including software installation, update, and core services +Manage users and groups, including use of a centralized directory for authentication +Manage security, including basic firewall and SELinux configuration diff --git a/serverinformation.sh b/serverinformation.sh deleted file mode 100644 index 85d4d14..0000000 --- a/serverinformation.sh +++ /dev/null @@ -1,118 +0,0 @@ -#!/bin/bash - -mkdir -p /Inventory -sudo chmod -R 777 /Inventory/ -mkdir -p /tmp/asset -touch /tmp/asset/hostname.txt -if [ -f /tmp/asset/hostname.txt ];then - echo "File /tmp/asset/hostname.txt Exists" -else - mkdir /tmp/asset - touch /tmp/asset/hostname.txt -fi -touch /tmp/temptext -TEMP=/tmp/temptext -LOG=`ls /tmp/asset/hostname.txt` -echo "## Host Information" > $LOG -echo "Host Name : `hostname` " >> $LOG -echo "`sudo /sbin/ifconfig -a |grep "inet" | awk 'BEGIN { FS = ":" } ; { print $2 }'`" >> $TEMP -echo "IP Address : `egrep '^10' $TEMP |awk '{ print $1}'`" >> $LOG -echo "IP Address: `hostname -I`" >> $LOG -echo "ip a |grep inet |grep -v "::" |awk '{print $2}'" >> $LOG -echo "iDrac Details: `racadm getniccfg |grep "IP Address" |grep -v "::"`" >> $LOG -echo "Server Type: `servertype=$(lscpu | grep Hypervisor | wc -l); if [ $servertype -gt 0 ]; then echo "VitualMachine"; else echo "Physical"; fi`" >> $LOG -echo -en '\n' >> $LOG - -## Collecting Hardware Details ## -echo " " >> $LOG -echo "## Hardware Information" >> $LOG -echo " " >> $LOG -echo "Serial Number : `sudo lshal |grep system.hardware.serial`" >> $LOG -echo "Serial Number : `sudo /usr/sbin/dmidecode -s system-serial-number`" >> $LOG -echo "Serial Number : `sudo cat /sys/class/dmi/id/product_serial`" >> $LOG -echo "Model Number : `sudo lshal |grep system.hardware.product`" >> $LOG -echo "Model Number : `sudo /usr/sbin/dmidecode |grep "SKU Number"`" >> $LOG -echo "Model Number : `sudo cat /sys/class/dmi/id/product_name`" >> $LOG -echo "Hardware Vendor : `sudo lshal |grep system.hardware.vendor`" >> $LOG -echo "Hardware Vendor : `sudo cat /sys/class/dmi/id/chassis_vendor`" >> $LOG -echo "Hardware Info : `sudo dmesg |grep DMI`" >> $LOG - -## Redhat Version ## -echo " " >> $LOG -echo "## OS Version" >> $LOG -head -n1 /etc/issue >> $LOG -cat /etc/redhat-release >> $LOG -echo "Kernel Version: `uname -r`">> $LOG -echo "OS Version: `hostnamectl | egrep "Operating System" | cut -d ' ' -f5-`" >> $LOG - -## CPU Info ## -echo " " >> $LOG -echo " " >> $LOG -echo "## CPU Information" >> $LOG -grep "model name" /proc/cpuinfo |uniq >> $LOG -COUNTT=$(cat /proc/cpuinfo |grep "model name" | wc -l) -echo "$COUNTT Cores" >> $LOG - -## RAM/MEMORY Info ## -echo " " >> $LOG -echo " " >> $LOG -echo "## Memory Information" >> $LOG -grep MemTotal /proc/meminfo >> $LOG -y=`grep MemTotal /proc/meminfo |awk '{ print $2 }'` -mb="$(( $y / 1024 ))" -gb="$(( $mb / 1024 ))" -echo "RAM : $gb GB" >> $LOG - -## Swap Information ## -echo " " >> $LOG -echo "## Swap Information" >> $LOG -y1=$(free -k |grep Swap |awk '{print $2}') -mb1="$(( $y1 / 1024 ))" -gb1="$(( $mb1 / 1024 ))" -echo "Swap Size: $gb1 GB" >> $LOG - -## Disk Information ## -echo " " >> $LOG -echo "## Disk Information" >> $LOG -lsblk |grep -E 'part|disk' $LOG - -## LVM Information ## -echo " " >> $LOG -echo "## Physical Volumes" >> $LOG -pvs >> $LOG - -echo " " >> $LOG -echo "## Volume Groups" >> $LOG -vgs >> $LOG - -echo " " >> $LOG -echo "## Logical Volumes" >> $LOG -lvs >> $LOG -echo " " >> $LOG - -## Partition Information ## -echo "## DF Command Output" >> $LOG -echo " " >> $LOG -df -Ph -x tmpfs -x devtmpfs| sed s/%//g | awk '{ if($5 > 0) print $0;}' >> $LOG - -echo " " >> $LOG -echo "## Port Information" >> $LOG -ss -alntup |column -t |grep -E 'tcp|udp' >> $LOG - -echo " " >> $LOG -echo "## Service Information" >> $LOG -systemctl list-units --type=service --state=running |grep -vE 'systemd|selinux' >> $LOG - -echo " " >> $LOG -echo "## Docker Containers" >> $LOG -sudo docker ps -a >> $LOG - -echo " " >> $LOG -echo "## DNS Server Details" >> $LOG -cat /etc/resolv.conf >> $LOG - -echo "" >> $LOG -echo "## Server Uptime" >> $LOG -uptime >> $LOG - -sudo cp /tmp/asset/`hostname`.txt /Inventory/`hostname`-`date "+%Y-%m-%d"`.txt diff --git a/setbashfeature.sh b/setbashfeature.sh deleted file mode 100644 index c918db2..0000000 --- a/setbashfeature.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash -#Purpose: Set assigns its arguments to the positional parameters -#Version:1.0 -#website: https://arkit.co.in -#Created Date: Tue May 22 23:10:17 IST 2018 -#Modified Date: -#Author: Ankam Ravi Kumar -# START # -set `date` -echo "Today is $1" -echo "Month is $2" -echo "Date is $3" -echo "Time H:M:S $4" -echo "TimeZone is $5" -echo "Year is $6" -set -x -# END # diff --git a/shiftparameters.sh b/shiftparameters.sh deleted file mode 100644 index 5a825da..0000000 --- a/shiftparameters.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash -#Purpose: Shifting positional parameters automatically -#Version:1.0 -#Website: https://arkit.co.in -#Created Date: Tue May 22 22:55:50 IST 2018 -#Modified Date: -#Author: Ankam Ravi Kumar -# START # -set `date` -echo "Count $#" -echo "$1 $2 $3 $4 $5" -shift 2 -echo "$1 $2 $3 $4 $5" -# END # diff --git a/spacialvariables.sh b/spacialvariables.sh deleted file mode 100644 index 68400b7..0000000 --- a/spacialvariables.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash -#Purpose: To learn special variables -#Version:1.0 -#Website: https://arkit.co.in -#Created Date: Sun May 6 15:23:12 IST 2018 -#Modified Date: -#Author: Ankam Ravi Kumar -# START # -echo "'$*' output is $*" -echo "'$#' output is $#" -echo "'$1 & $2' output $1 and $2" -echo "'$@' output of $@" -echo "'$?' output is $?" -echo "'$$' output is $$" -sleep 400 & -echo "'$!' output is $!" - -echo "'$0' your current program name is $0" - -# END # diff --git a/systemload.sh b/systemload.sh deleted file mode 100644 index 3f7d663..0000000 --- a/systemload.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash -################################################## -# # -# Author: Ankam Ravi Kumar # -# Website: server-computer.com # -# Date: 23-02-2019 16:59:56 # -# Purpose: Capture and Store System Load Average # -# CPU Usage and Memory Usage # -################################################## -# Log File Path -LOGFILE=/var/log/systemload.log - -HOSTNAME=$(hostname) -DATE=$(date "+%d-%m-%Y %H:%M:%S") -SYSTEMLOAD=$(uptime | awk '{ print $8,$9,$10,$11,$12}') -CPULOAD=$(top -b -n 2 -d1 | grep "Cpu(s)" | tail -n1 |awk '{print $2}') -MEMORYUSAGE=$(free -m |grep Mem: |tail -n1 |awk '{print $2,$3}') - -echo "$DATE $HOSTNAME LoadAverage: $SYSTEMLOAD CPU: $CPULOAD Memory: $MEMORYUSAGE" >> $LOGFILE diff --git a/uadd.sh b/uadd.sh deleted file mode 100644 index 722e934..0000000 --- a/uadd.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash -#Purpose: eval command Evaluating twice -#Version:1.0 -#Created Date: Wed Jun 13 22:09:59 IST 2018 -#Modified Date: -#WebSite: https://arkit.co.in -#Author: Ankam Ravi Kumar -# START # - -echo "ecnter the user name $NM" -read NM -echo "`useradd -d /users/$NM $NM`" - -# END # diff --git a/ud.sh b/ud.sh deleted file mode 100644 index 1c34e9d..0000000 --- a/ud.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash -#Purpose: eval command Evaluating twice -#Version:1.0 -#Created Date: Wed Jun 13 22:09:59 IST 2018 -#Modified Date: -#WebSite: https://arkit.co.in -#Author: Ankam Ravi Kumar -# START # - -echo "WEl COME TO $USER" -echo " Your present Wroking Directory is `pwd`" -echo "Present Processes are `ps -a`" -echo "Now Time is `date`" -echo "current logged in Details are `finger $USER`" - -# END # diff --git a/untiloop.sh b/untiloop.sh deleted file mode 100644 index 7994e64..0000000 --- a/untiloop.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash -#Purpose: Until Loop Example for Host Ping -#Version:1.0 -#Created Date: Mon May 28 22:18:52 IST 2018 -#Modified Date: -#WebSite: https://arkit.co.in -#Author: Ankam Ravi Kumar -# START # -echo -e "Please Enter the IP Address to Ping: \c" -read -r ip -until ping -c 3 $ip -do - echo "Host $ip is Still Down" - sleep 1 -done - -echo "Host $ip is Up Now" - -# END # diff --git a/useradd.sh b/useradd.sh deleted file mode 100644 index 21f061b..0000000 --- a/useradd.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash -# Script to add a user to Linux system -if [ $(id -u) -eq 0 ]; then - read -p "Enter username : " username - read -s -p "Enter password : " password - egrep "^$username" /etc/passwd >/dev/null - if [ $? -eq 0 ]; then - echo "$username exists!" - exit 1 - else - pass=$(perl -e 'print crypt($ARGV[0], "password")' $password) - useradd -m -p $pass $username - [ $? -eq 0 ] && echo "User has been added to system!" || echo "Failed to add a user!" - fi -else - echo "Only root may add a user to the system" - exit 2 -fi diff --git a/useradd_improved.sh b/useradd_improved.sh deleted file mode 100644 index d41a150..0000000 --- a/useradd_improved.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/bin/bash -## Author: Ankam Ravi Kumar -## Date: 21st Sep 2024 -## Purpose: To Create a users in Linux - -check_command_success() { - if [ $? -ne 0 ]; then - echo "Error: $1" - exit 1 - fi -} - -if [ $(id -u) -ne 0 ]; then - echo "Error: Only root may add a user to the system." - exit 2 -fi - -# Prompt for the username and password -read -p "Enter username: " username -read -s -p "Enter password: " password -echo - -if id "$username" &>/dev/null; then - echo "Error: User '$username' already exists!" - exit 1 -fi - -encrypted_password=$(perl -e 'print crypt($ARGV[0], "password")' "$password") -check_command_success "Failed to encrypt the password." - -useradd -m -p "$encrypted_password" "$username" -check_command_success "Failed to add the user." - -passwd -e "$username" -check_command_success "Failed to set password expiry." - -echo "Success: User '$username' has been added to the system!" diff --git a/userexists.sh b/userexists.sh deleted file mode 100644 index 1b8dde7..0000000 --- a/userexists.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash -##Purpose: Check given user Exits Or Not -##Date: 27th Oct 2016 -##Author: Ankam Ravi Kumar -##WebSite: https://arkit.co.in - -##Start -echo -e "Please Enter User name you want check: \c" -read user -grep $user /etc/passwd > /dev/null -if [ $? -eq 0 ]; then -grep $user /etc/passwd -echo "$user Exists in this Machine" -else -echo "$user does not exists" -fi - -##END diff --git a/variables.sh b/variables.sh deleted file mode 100644 index 7f3128d..0000000 --- a/variables.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash -#Purpose: What is variable.? How is help us in writing shell scripts -#Version:1.0 -#Created Date: Sat May 5 20:25:21 IST 2018 -#Modified Date: -#website: https://arkit.co.in -#Author: Ankam Ravi Kumar -# START # - -A=10 -Ba=23 -BA=45 -HOSTNAME=$(hostname) -DATE=`date` -1value=333 -False@Var=False -Hyphen_a=WrongValue - -echo "Variable A Value: $A" -echo "Variable Ba Vaule: $Ba" -echo "Variable BA Vaule: $BA" -echo "Variable HOST value: $HOSTNAME" -echo "Variable DATE value: $DATE" -echo "Wrong Variable 1value $1value" -echo 'False @ Variable' $False@Var -echo "hyphen-a Variable Value: $Hyphen_a" - -# END # diff --git a/webserver_ubuntu.sh b/webserver_ubuntu.sh deleted file mode 100755 index 6a28ea9..0000000 --- a/webserver_ubuntu.sh +++ /dev/null @@ -1,142 +0,0 @@ -#!/usr/bin/env bash - -############################################################# -# # -# NOME: webserver_ubuntu.sh # -# # -# AUTOR: Amaury B. Souza (amaurybsouza@gmail.com) # -# # -# DESCRIÇÃO: O script faz a instalação da stack LAMP # -# # -# USO: ./webserver_ubuntu.sh # -############################################################# - -function menuprincipal () { - clear - echo " " - echo LAMP Stack Ubuntu $0 - echo " " - echo "Escolha uma opção abaixo para começar! - - 1 - Instalar Apache no sistema - 2 - Instalar o banco de dados MariaDB no sistema - 3 - Instalar o PHP7.2 no sistema - 4 - Instalar a stack LAMP completa no sistema - 0 - Sair do menu de instalação" -echo " " -echo -n "Opção escolhida: " -read opcao -case $opcao in - 1) - function apache () { - TIME=2 - echo Atualizando seu sistema... - sleep $TIME - apt update && apt upgrade -y - echo Iniciando a instalação do Apache no Ubuntu... - sleep $TIME - #sudo iptables -I INPUT -p tcp --dport 80 -j ACCEPT - #sudo ufw allow http - #sudo chown www-data:www-data /var/www/html/ -R - apt install -y apache2 apache2-utils - sudo systemctl start apache2 - sudo systemctl enable apache2 - echo " " - if [ $? -eq 0 ] - then - echo O Apache foi instalado no seu sistema. - else - echo Ops, ocorreu algum erro, vamos tentar de novo! - fi - } - apache - read -n 1 -p " para menu principal" - menuprincipal - ;; - - 2) - function maria () { - TIME=2 - echo Iniciando a instalação do MariaDB... - sleep $TIME - sudo apt -y install mariadb-server mariadb-client - sudo systemctl start mariadb - sudo systemctl enable mariadb - if [ $? -eq 0 ] - then - echo Agora vamos configurar o banco... - sleep $TIME - sudo mysql_secure_installation - echo " " - echo Opa, parabéns, o banco foi instalado e configurado! - sleep $TIME - else - echo Ops, vamos resolver isso? Acho que deu errado. - fi - } - maria - read -n 1 -p " para menu principal" - menuprincipal - ;; - - 3) - function php () { - echo Iniciando a instalação do PHP... - sudo apt install -y php7.2 libapache2-mod-php7.2 php7.2-mysql php-common php7.2-cli php7.2-common php7.2-json php7.2-opcache php7.2-readline - sudo a2enmod php7.2 - sudo systemctl restart apache2 - echo " " - echo O PHP 7.2 foi instalado, que legal! - #Para testar o PHP instalado... - #sudo vim /var/www/html/info.php - } - php - read -n 1 -p " para menu principal" - menuprincipal - ;; - - 4) - function lamp () { - TIME=2 - #apache - echo Vamos iniciar a instalação da stack LAMP no seu sistema... - sleep $TIME - echo Instalando o Apache... - sleep $TIME - apt install -y apache2 apache2-utils - sudo systemctl start apache2 - sudo systemctl enable apache2 - echo Instalando o banco de dados... - sleep $TIME - #banco de dados - sudo apt -y install mariadb-server mariadb-client - sudo systemctl start mariadb - sudo systemctl enable mariadb - #PHP - echo Instalando o PHP... - sleep $TIME - sudo apt install -y php7.2 libapache2-mod-php7.2 php7.2-mysql php-common php7.2-cli php7.2-common php7.2-json php7.2-opcache php7.2-readline - sudo a2enmod php7.2 - sudo systemctl restart apache2 - echo Instalação concluída com êxito! - sleep $TIME - } - lamp - read -n 1 -p " para menu principal" - menuprincipal - ;; - - 0) - function sair () { - TIME=2 - echo " " - echo Saindo do sistema... - sleep $TIME - exit 0 - } - sair - ;; - -esac -} -menuprincipal diff --git a/while-loop.sh b/while-loop.sh deleted file mode 100644 index 3f314c7..0000000 --- a/while-loop.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash -# While Loop Example with 2 table, print any given number table. -# See Full Explanation of this above shell script [while loop](https://www.youtube.com/Techarkit?sub_confirmation=1) - -#START - -echo -e "Please provide one value: \c" -read -r c -i=1 -while [ $i -le 10 ] -do -b=`expr $c \* $i` -echo "$c * $i = $b" -i=`expr $i + 1` -done - -#END \ No newline at end of file