SlideShare una empresa de Scribd logo
1 de 10
Descargar para leer sin conexión
Scripting 101
My First Sony ^H^H^H hellscript

#!/bin/bash
echo “Hello World!”




$ sh script.sh
 Hello World
Output redirection
There are 3 file descriptors:               Examples:
   stdin, stdout and stderr.
                                            1.    ls -l > ls-l.txt
Basically you can:                          2.   grep da * 2> grep-errors.txt
    redirect stdout to a file              3.   grep da * 1>&2
    redirect stderr to a file              4.   grep * 2>&1
    redirect stdout to a stderr            5.   rm -f $(find / -name core) &>
                                                 /dev/null
    redirect stderr to a stdout
    redirect stderr and stdout to a file
    redirect stderr and stdout to
     stdout
    redirect stderr and stdout to stderr

1 'represents' stdout and 2 stderr.
Pipes

Pipes can redirect output from one command to
  another

Example:

$ cat /etc/passwd | grep „whoami‟
Variables
STR=“Hello World!”
OF=“/var/my-backup-$(date +%Y%m%d).tgz”



#!/bin/bash
STR=“Hello World!”
echo $STR



#!/bin/bash
OF=“/var/my-backup-$(date +%Y%m%d).tgz”
tar -cZf $OF /home/me/
Local variables

#!/bin/bash
HELLO=Hello
function hello {
    local HELLO=World
    echo $HELLO
}
echo $HELLO
hello
echo $HELLO
Conditions
if [expression];                    Examples:
then
    code if 'expression' is true.   #!/bin/bash
                                    if [ "foo" = "foo" ]; then
fi                                       echo “expression
                                         evaluated as true”
                                    fi


                                    #!/bin/bash
if … then                           T1="foo"
else                                T2="bar"
                                    if [ "$T1" = "$T2" ]; then
elseif                                   echo “expression
                                         evaluated as true”
                                    else
                                           echo “expression
                                           evaluated as false”
                                    fi
Loops

3 kinds of loops   Examples:

                   #!/bin/bash
 for loop         for i in `seq 1 10`; do
                     echo $i
 while loop       Done
 until loop
                   #!/bin/bash
                   COUNTER=0
                   while [ $COUNTER -lt 10 ]; do
                     echo “The counter is “ $COUNTER
                     let COUNTER=COUNTER+1
                   done
Assignment:

Write a linux shell script to automagically
create 1000 user accounts. Make sure their
default password is “Hello123”

(hint: you cannot set the pasword with the –p
option….)
Useful files and commands

nano, joe, vi (editors)
/etc/passwd
useradd
passwd
rm -rf

Más contenido relacionado

La actualidad más candente

Rc - The Plan 9 Shell
Rc - The Plan 9 ShellRc - The Plan 9 Shell
Rc - The Plan 9 Shelltwopoint718
 
Unix shell scripting basics
Unix shell scripting basicsUnix shell scripting basics
Unix shell scripting basicsManav Prasad
 
Introduction to Bash Scripting, Zyxware Technologies, CSI Students Convention...
Introduction to Bash Scripting, Zyxware Technologies, CSI Students Convention...Introduction to Bash Scripting, Zyxware Technologies, CSI Students Convention...
Introduction to Bash Scripting, Zyxware Technologies, CSI Students Convention...Zyxware Technologies
 
Neoito — *NIX kungfu for web devs
Neoito — *NIX kungfu for web devsNeoito — *NIX kungfu for web devs
Neoito — *NIX kungfu for web devsNeoito
 
Unix Shell Scripting Basics
Unix Shell Scripting BasicsUnix Shell Scripting Basics
Unix Shell Scripting BasicsSudharsan S
 
Unix And C
Unix And CUnix And C
Unix And CDr.Ravi
 
Shell实现的windows回收站功能的脚本
Shell实现的windows回收站功能的脚本Shell实现的windows回收站功能的脚本
Shell实现的windows回收站功能的脚本Lingfei Kong
 
TDC2016SP - Become a jedi with PHP streams
TDC2016SP - Become a jedi with PHP streamsTDC2016SP - Become a jedi with PHP streams
TDC2016SP - Become a jedi with PHP streamstdc-globalcode
 
Talk Unix Shell Script
Talk Unix Shell ScriptTalk Unix Shell Script
Talk Unix Shell ScriptDr.Ravi
 
Popstat1 sh
Popstat1 shPopstat1 sh
Popstat1 shBen Pope
 
Unix And Shell Scripting
Unix And Shell ScriptingUnix And Shell Scripting
Unix And Shell ScriptingJaibeer Malik
 
Unix Basics
Unix BasicsUnix Basics
Unix BasicsDr.Ravi
 
De 0 a 100 con Bash Shell Scripting y AWK
De 0 a 100 con Bash Shell Scripting y AWKDe 0 a 100 con Bash Shell Scripting y AWK
De 0 a 100 con Bash Shell Scripting y AWKAdolfo Sanz De Diego
 
Shell programming 1.ppt
Shell programming  1.pptShell programming  1.ppt
Shell programming 1.pptKalkey
 

La actualidad más candente (20)

Rc - The Plan 9 Shell
Rc - The Plan 9 ShellRc - The Plan 9 Shell
Rc - The Plan 9 Shell
 
Unix shell scripting basics
Unix shell scripting basicsUnix shell scripting basics
Unix shell scripting basics
 
Unix lab manual
Unix lab manualUnix lab manual
Unix lab manual
 
Introduction to Bash Scripting, Zyxware Technologies, CSI Students Convention...
Introduction to Bash Scripting, Zyxware Technologies, CSI Students Convention...Introduction to Bash Scripting, Zyxware Technologies, CSI Students Convention...
Introduction to Bash Scripting, Zyxware Technologies, CSI Students Convention...
 
Neoito — *NIX kungfu for web devs
Neoito — *NIX kungfu for web devsNeoito — *NIX kungfu for web devs
Neoito — *NIX kungfu for web devs
 
Unix Shell Scripting Basics
Unix Shell Scripting BasicsUnix Shell Scripting Basics
Unix Shell Scripting Basics
 
Unix And C
Unix And CUnix And C
Unix And C
 
Shell Scripting
Shell ScriptingShell Scripting
Shell Scripting
 
Scripting ppt
Scripting pptScripting ppt
Scripting ppt
 
Unix shell scripting
Unix shell scriptingUnix shell scripting
Unix shell scripting
 
Shell实现的windows回收站功能的脚本
Shell实现的windows回收站功能的脚本Shell实现的windows回收站功能的脚本
Shell实现的windows回收站功能的脚本
 
TDC2016SP - Become a jedi with PHP streams
TDC2016SP - Become a jedi with PHP streamsTDC2016SP - Become a jedi with PHP streams
TDC2016SP - Become a jedi with PHP streams
 
Talk Unix Shell Script
Talk Unix Shell ScriptTalk Unix Shell Script
Talk Unix Shell Script
 
Popstat1 sh
Popstat1 shPopstat1 sh
Popstat1 sh
 
Chap06
Chap06Chap06
Chap06
 
Unix And Shell Scripting
Unix And Shell ScriptingUnix And Shell Scripting
Unix And Shell Scripting
 
Unix Basics
Unix BasicsUnix Basics
Unix Basics
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
 
De 0 a 100 con Bash Shell Scripting y AWK
De 0 a 100 con Bash Shell Scripting y AWKDe 0 a 100 con Bash Shell Scripting y AWK
De 0 a 100 con Bash Shell Scripting y AWK
 
Shell programming 1.ppt
Shell programming  1.pptShell programming  1.ppt
Shell programming 1.ppt
 

Destacado

adele someone like you lyrics
adele someone like you lyricsadele someone like you lyrics
adele someone like you lyricsmp3download
 
Mesa: "Las vacunas y los trasplantes ¿son servicios básicos de salud o un luj...
Mesa: "Las vacunas y los trasplantes ¿son servicios básicos de salud o un luj...Mesa: "Las vacunas y los trasplantes ¿son servicios básicos de salud o un luj...
Mesa: "Las vacunas y los trasplantes ¿son servicios básicos de salud o un luj...PHARMACOSERÍAS
 
JOSE AVILA - Utilidad del Big Data en predicción de riesgos
JOSE AVILA - Utilidad del Big Data en predicción de riesgosJOSE AVILA - Utilidad del Big Data en predicción de riesgos
JOSE AVILA - Utilidad del Big Data en predicción de riesgosCOM SALUD
 
JULIO MAYOL - ¿Es necesario monitorizar todo?
JULIO MAYOL - ¿Es necesario monitorizar todo?JULIO MAYOL - ¿Es necesario monitorizar todo?
JULIO MAYOL - ¿Es necesario monitorizar todo?COM SALUD
 
Atlantica XXII se presenta en Cangas de Onis (2009) con Xuán Cándano y Fernan...
Atlantica XXII se presenta en Cangas de Onis (2009) con Xuán Cándano y Fernan...Atlantica XXII se presenta en Cangas de Onis (2009) con Xuán Cándano y Fernan...
Atlantica XXII se presenta en Cangas de Onis (2009) con Xuán Cándano y Fernan...PHARMACOSERÍAS
 
"La Salud un manantial de risas"
"La Salud un manantial de risas""La Salud un manantial de risas"
"La Salud un manantial de risas"PHARMACOSERÍAS
 

Destacado (6)

adele someone like you lyrics
adele someone like you lyricsadele someone like you lyrics
adele someone like you lyrics
 
Mesa: "Las vacunas y los trasplantes ¿son servicios básicos de salud o un luj...
Mesa: "Las vacunas y los trasplantes ¿son servicios básicos de salud o un luj...Mesa: "Las vacunas y los trasplantes ¿son servicios básicos de salud o un luj...
Mesa: "Las vacunas y los trasplantes ¿son servicios básicos de salud o un luj...
 
JOSE AVILA - Utilidad del Big Data en predicción de riesgos
JOSE AVILA - Utilidad del Big Data en predicción de riesgosJOSE AVILA - Utilidad del Big Data en predicción de riesgos
JOSE AVILA - Utilidad del Big Data en predicción de riesgos
 
JULIO MAYOL - ¿Es necesario monitorizar todo?
JULIO MAYOL - ¿Es necesario monitorizar todo?JULIO MAYOL - ¿Es necesario monitorizar todo?
JULIO MAYOL - ¿Es necesario monitorizar todo?
 
Atlantica XXII se presenta en Cangas de Onis (2009) con Xuán Cándano y Fernan...
Atlantica XXII se presenta en Cangas de Onis (2009) con Xuán Cándano y Fernan...Atlantica XXII se presenta en Cangas de Onis (2009) con Xuán Cándano y Fernan...
Atlantica XXII se presenta en Cangas de Onis (2009) con Xuán Cándano y Fernan...
 
"La Salud un manantial de risas"
"La Salud un manantial de risas""La Salud un manantial de risas"
"La Salud un manantial de risas"
 

Similar a Scripting 101

390aLecture05_12sp.ppt
390aLecture05_12sp.ppt390aLecture05_12sp.ppt
390aLecture05_12sp.pptmugeshmsd5
 
Unleash your inner console cowboy
Unleash your inner console cowboyUnleash your inner console cowboy
Unleash your inner console cowboyKenneth Geisshirt
 
Bash shell
Bash shellBash shell
Bash shellxylas121
 
34-shell-programming.ppt
34-shell-programming.ppt34-shell-programming.ppt
34-shell-programming.pptKiranMantri
 
2-introduction_to_shell_scripting
2-introduction_to_shell_scripting2-introduction_to_shell_scripting
2-introduction_to_shell_scriptingerbipulkumar
 
Unit 11 configuring the bash shell – shell script
Unit 11 configuring the bash shell – shell scriptUnit 11 configuring the bash shell – shell script
Unit 11 configuring the bash shell – shell scriptroot_fibo
 
Raspberry pi Part 25
Raspberry pi Part 25Raspberry pi Part 25
Raspberry pi Part 25Techvilla
 
UNIX - Class3 - Programming Constructs
UNIX - Class3 - Programming ConstructsUNIX - Class3 - Programming Constructs
UNIX - Class3 - Programming ConstructsNihar Ranjan Paital
 
Best training-in-mumbai-shell scripting
Best training-in-mumbai-shell scriptingBest training-in-mumbai-shell scripting
Best training-in-mumbai-shell scriptingvibrantuser
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell ScriptingRaghu nath
 
Linux Shell Scripting
Linux Shell ScriptingLinux Shell Scripting
Linux Shell ScriptingRaghu nath
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell ScriptingRaghu nath
 
Best training-in-mumbai-shell scripting
Best training-in-mumbai-shell scriptingBest training-in-mumbai-shell scripting
Best training-in-mumbai-shell scriptingvibrantuser
 

Similar a Scripting 101 (20)

390aLecture05_12sp.ppt
390aLecture05_12sp.ppt390aLecture05_12sp.ppt
390aLecture05_12sp.ppt
 
What is a shell script
What is a shell scriptWhat is a shell script
What is a shell script
 
Unleash your inner console cowboy
Unleash your inner console cowboyUnleash your inner console cowboy
Unleash your inner console cowboy
 
First steps in C-Shell
First steps in C-ShellFirst steps in C-Shell
First steps in C-Shell
 
Bash shell
Bash shellBash shell
Bash shell
 
34-shell-programming.ppt
34-shell-programming.ppt34-shell-programming.ppt
34-shell-programming.ppt
 
2-introduction_to_shell_scripting
2-introduction_to_shell_scripting2-introduction_to_shell_scripting
2-introduction_to_shell_scripting
 
Unit 11 configuring the bash shell – shell script
Unit 11 configuring the bash shell – shell scriptUnit 11 configuring the bash shell – shell script
Unit 11 configuring the bash shell – shell script
 
Raspberry pi Part 25
Raspberry pi Part 25Raspberry pi Part 25
Raspberry pi Part 25
 
UNIX - Class3 - Programming Constructs
UNIX - Class3 - Programming ConstructsUNIX - Class3 - Programming Constructs
UNIX - Class3 - Programming Constructs
 
Best training-in-mumbai-shell scripting
Best training-in-mumbai-shell scriptingBest training-in-mumbai-shell scripting
Best training-in-mumbai-shell scripting
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell Scripting
 
Linux Shell Scripting
Linux Shell ScriptingLinux Shell Scripting
Linux Shell Scripting
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell Scripting
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
 
Bash
BashBash
Bash
 
Shell programming
Shell programmingShell programming
Shell programming
 
Scripting ppt
Scripting pptScripting ppt
Scripting ppt
 
Best training-in-mumbai-shell scripting
Best training-in-mumbai-shell scriptingBest training-in-mumbai-shell scripting
Best training-in-mumbai-shell scripting
 

Último

Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
Kuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorialKuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorialJoão Esperancinha
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Accelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with PlatformlessAccelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with PlatformlessWSO2
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sectoritnewsafrica
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkPixlogix Infotech
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...panagenda
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesManik S Magar
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...Nikki Chapple
 
All These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFAll These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFMichael Gough
 
A Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxA Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxAna-Maria Mihalceanu
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 

Último (20)

Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 
Kuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorialKuma Meshes Part I - The basics - A tutorial
Kuma Meshes Part I - The basics - A tutorial
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Accelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with PlatformlessAccelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with Platformless
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App Framework
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
 
All These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFAll These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDF
 
A Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxA Glance At The Java Performance Toolbox
A Glance At The Java Performance Toolbox
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 

Scripting 101

  • 2. My First Sony ^H^H^H hellscript #!/bin/bash echo “Hello World!” $ sh script.sh  Hello World
  • 3. Output redirection There are 3 file descriptors: Examples: stdin, stdout and stderr. 1. ls -l > ls-l.txt Basically you can: 2. grep da * 2> grep-errors.txt  redirect stdout to a file 3. grep da * 1>&2  redirect stderr to a file 4. grep * 2>&1  redirect stdout to a stderr 5. rm -f $(find / -name core) &> /dev/null  redirect stderr to a stdout  redirect stderr and stdout to a file  redirect stderr and stdout to stdout  redirect stderr and stdout to stderr 1 'represents' stdout and 2 stderr.
  • 4. Pipes Pipes can redirect output from one command to another Example: $ cat /etc/passwd | grep „whoami‟
  • 5. Variables STR=“Hello World!” OF=“/var/my-backup-$(date +%Y%m%d).tgz” #!/bin/bash STR=“Hello World!” echo $STR #!/bin/bash OF=“/var/my-backup-$(date +%Y%m%d).tgz” tar -cZf $OF /home/me/
  • 6. Local variables #!/bin/bash HELLO=Hello function hello { local HELLO=World echo $HELLO } echo $HELLO hello echo $HELLO
  • 7. Conditions if [expression]; Examples: then code if 'expression' is true. #!/bin/bash if [ "foo" = "foo" ]; then fi echo “expression evaluated as true” fi #!/bin/bash if … then T1="foo" else T2="bar" if [ "$T1" = "$T2" ]; then elseif echo “expression evaluated as true” else echo “expression evaluated as false” fi
  • 8. Loops 3 kinds of loops Examples: #!/bin/bash  for loop for i in `seq 1 10`; do echo $i  while loop Done  until loop #!/bin/bash COUNTER=0 while [ $COUNTER -lt 10 ]; do echo “The counter is “ $COUNTER let COUNTER=COUNTER+1 done
  • 9. Assignment: Write a linux shell script to automagically create 1000 user accounts. Make sure their default password is “Hello123” (hint: you cannot set the pasword with the –p option….)
  • 10. Useful files and commands nano, joe, vi (editors) /etc/passwd useradd passwd rm -rf