SlideShare une entreprise Scribd logo
1  sur  10
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

Contenu connexe

Tendances

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
 

Tendances (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
 

En vedette

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
 

En vedette (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"
 

Similaire à 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
 

Similaire à 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
 

Dernier

Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 

Dernier (20)

Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 

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