Automating Your Daily Tasks with Scripting

The Presentation inside:

Slide 0

Automating Your Daily Tasks with Scripting Adler Hsieh RubyConf Taiwan 2015-9-11

Slide 1

Agenda What is Scripting Why Scripting Several Cases Script Management Q & A

Slide 2

Only Basic Concept

Slide 3

Who am I Adler Hsieh Software Engineer at OneAD Ruby, JavaScript, PHP Github: adlerhsieh Twitter: @adler_hsieh Blog:

Slide 4

What is Scripting

Slide 5

Let’s make it simple

Slide 6

Slide 7


Slide 8

Let’s make it a little useful

Slide 9

How do I get my local ip address?

Slide 10

> ifconfig

Slide 11

What is scripting Your local ip address

Slide 12

What is scripting

Slide 13

What is scripting Basically… Small programs solving Small problems

Slide 14

Plus… Saves time Easy to write Easy to manage

Slide 15

And… Show off

Slide 16

Cases Cleaning old files Shutdown local server MySQL Database import from .sql

Slide 17

Cleaning Old Files Scenario All downloaded files are in one directory Directory becomes very large

Slide 18

Cleaning Old Files

Slide 19

Cleaning Old Files

Slide 20

Cleaning Old Files Use it with Cron

Slide 21

Shutdown Server Scenario Local server crashes I cannot shut down my rails server with ctrl + c

Slide 22

Shutdown Server > lsof –i:3000 > kill -9 PID

Slide 23

Shutdown Server

Slide 24

Importing MySQL database with .sql Scenario When there is bug Importing production DB to local DB

Slide 25

Importing MySQL database with .sql > ssh [email protected] > mysqldump –u username –p db_name > db.sql > exit > scp [email protected]:db.sql db.sql > mysql –u username –p db_name < db.sql

Slide 26

Importing MySQL database with .sql

Slide 27

Cases Scripts are task-specific Find patterns in your tasks

Slide 28

Managing Scripts

Slide 29

Managing Scripts If you do not manage scripts… Scripts everywhere You have to remember file locations

Slide 30

Managing Scripts Purpose All scripts at a glance Write once, run everywhere

Slide 31


Slide 32

Managing Scripts Rake Managing all rake tasks in ~/.rake folder task_a.rake task_b.rake Prefixing ‘rake’ command Description support

Slide 33

Managing Scripts

Slide 34

Managing Scripts Managing tasks like in Rails restart.rake import.rake local_ip.rake clean.rake Thus, run `rake` command from anywhere (add –g option if necessary)

Slide 35


Slide 36

Managing Scripts Make scripts executables Separate scripts by commands The bad part Too many commands Conflicting with existing commands

Slide 37

Managing Scripts > chmod 755 hello.rb > mv hello.rb hello > ./hello

Slide 38

Managing Scripts Change the following line in your ‘.bashrc’: export PATH=“/user/bin:/usr/local/bin” To: export PATH=“/user/bin:/usr/local/bin:/scripts” And you can do: > hello

Slide 39

That’s it!

Slide 40

Recap Scripts are small programs solving small problems Scripts are case-specific Automation saves energy & time Managing scripts with rake

Slide 41

Make your own scripts!

Slide 42

Thank you! Slides are available on my Twitter @adler_hsieh