Shell_StudentNotes
Shell_StudentNotes
Special Files:
/dev/null
/dev/tty
Variables:
1. Predifined
2. User defined
- Null Variables
- unsetting a varaible
- Storing File Names ( Wild Cards ? & *)
- Storing File contents to a varaible
- Storing Commands to a variable
- Exporting Variables
Which shell you are currently in
ps -p $$
echo $$
echo $0 ( it wont work for csh)
tcsh - set var=name
- Echo/print command & formats "\t \n \\ \b"
Perment assigning the variables
Reading A variable:
- less arguments
- More i/p than arguments
- reading from a file
- exit status ?
Note: read -p "hi enter a vallue:" a
Expressions:
Mathametical
ex: take a,b & explain +,/,*,%,-
Decision Making :
if
if-then-else
elif-ladder
Relational operators
<,>,<=,>=,!=
ex: take 2 values & explain them the use of releations
File expressions
-f ,-d ,-x & etc
Logical Operations
&&,!!
ex: student score example
while loop
case
ex: take +,/,%,*,- operators
for loop
select loop
ex: calculator program
Loop Direction:
Input Redirection:
while
output Redirection:
while
for
Input Piping:
while
ex: cat serverslist |while read data;do echo $data;done
output piping:
while
ex: cat serverslist |while read data;do echo $data;done|wc -l
Argument Validation:
Debuggin scripts:
ksh -o xtrace *.scr
-x
set -x
Realtime examples ::
1. Write a code that should accept only 3 arguments oprend1,oprend2 & operator
based on operator it should
return output
uname -a
df -hT
3. Write the code which accepts only two arguments source & target buckets it
should copy data from source to target bucket.
4. Collect the server data as per the question 2 & send one email to your manager
([email protected])
ex path:
/var/logs/
6. Checking the server connectivity & preparing reachable & not reachable servers
list
case $httpd_version in
"2.4.43") echo "httpd is already with latest version";
exit 0;;
*) echo "Installing Latest package";
yum update httpd -y;
exit 0;;
esac