Introduction To Automation With Bash
Introduction To Automation With Bash
You can type the following command in your terminal to see which shell you are
using:
[root@wm1 home]# echo $0
-bash
cat /etc/shells
systemctl status httpd
vi mycmd
ls
pwd
sh mycmd
wget http://apachemirror.wuchna.com/tomcat/tomcat-9/v9.0.27/bin/apache-tomcat-
9.0.27.tar.gz
tar -xvzf apache-tomcat-9.0.27.tar.gz
rm apache-tomcat-9.0.27.tar.gz
mv apache-tomcat-9.0.27 tomcat9
rm -rf tomcat9
vi install_tomcat.sh
[root@node ~]# which $SHELL
/bin/bash
vi install_tomcat.sh
#!/bin/bash/
wget http://apachemirror.wuchna.com/tomcat/tomcat-9/v9.0.27/bin/apache-tomcat-
9.0.27.tar.gz
tar -xvzf apache-tomcat-9.0.27.tar.gz
rm apache-tomcat-9.0.27.tar.gz
mv apache-tomcat-9.0.27 tomcat9
/bin/bash install_tomcat.sh
ls -lrt
rm -rf tomcat9
chmod +x install_tomcat.sh
chmod -x install_tomcat.sh
chmod u+x install_tomcat.sh
./install_tomcat.sh
hmod +x freem
freem
mkdir usercmds
cd usercmds
mkdir bin
cd bin
pwd
mv /home/ec2-user/bin/freem /home/ec2-user/usercmds/bin/
cd
pwd
/home/ec2-user/
freem no such file or directory
[root@node usercmds]# cd
[root@node ~]# freem
-bash: /usr/bin/freem: No such file or directory
[root@node ~]# sh freem
sh: freem: No such file or directory
[root@node ~]#
echo $PATH
Eexport PATH=$PATH}:/home/ec2-user/usercmds/bin
echo $PATH
freem
exit
reconnect
echo $PATH
vi .bash_profile
freem -command not found
source .bash_profile
echo $PATH
free
chmod +x hello.sh
vi hello.sh
#!/bin/bash
echo "hello, welcome to shell scripting course"
echo 'this messege using single quotes'
echo "hi"
echo 'hi'
echo hi
vi hello.sh
#!/bin/bash
echo "hello, welcome to shell scripting course"
echo 'this messege is using single quotes'
echo "the below output is using echo command for ls command"
echo "---------------with double quotes----------"
echo "$(ls)"
echo "---------------with single quotes----------"
echo '$(ls)'
echo "---------------without any quotes----------"
echo $(ls)
5. Concepts of Variables
==================================================================================
vi about_variables.sh
#!/bin/bash
x=4
y=55
z=7
chmod +x about_variables.sh
[root@node ~]# ./about_variables.sh
[root@node ~]#
vi about_variables.sh
#!/bin/bash
x=4
y=55
z=7
ls
[root@node ~]# ./about_variables.sh
about_variables.sh Desktop Downloads initial-setup-ks.cfg Music Public
tomcat9 Videos
anaconda-ks.cfg Documents hello.sh install_tomcat.sh Pictures Templates
usercmds
[root@node ~]#