Automating Your Daily Tasks with Scripting

Понравилась презентация – покажи это...

Слайд 0

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

Слайд 1

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

Слайд 2

Only Basic Concept

Слайд 3

Who am I Adler Hsieh Software Engineer at OneAD Ruby, JavaScript, PHP Github: adlerhsieh Twitter: @adler_hsieh Blog: http://motion-express.com

Слайд 4

What is Scripting

Слайд 5

Let’s make it simple

Слайд 6

Слайд 7


Слайд 8

Let’s make it a little useful

Слайд 9

How do I get my local ip address?

Слайд 10

> ifconfig

Слайд 11

What is scripting Your local ip address

Слайд 12

What is scripting

Слайд 13

What is scripting Basically… Small programs solving Small problems

Слайд 14

Plus… Saves time Easy to write Easy to manage

Слайд 15

And… Show off

Слайд 16

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

Слайд 17

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

Слайд 18

Cleaning Old Files

Слайд 19

Cleaning Old Files

Слайд 20

Cleaning Old Files Use it with Cron

Слайд 21

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

Слайд 22

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

Слайд 23

Shutdown Server

Слайд 24

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

Слайд 25

Importing MySQL database with .sql > ssh username@ > mysqldump –u username –p db_name > db.sql > exit > scp username@ db.sql > mysql –u username –p db_name < db.sql

Слайд 26

Importing MySQL database with .sql

Слайд 27

Cases Scripts are task-specific Find patterns in your tasks

Слайд 28

Managing Scripts

Слайд 29

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

Слайд 30

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

Слайд 31


Слайд 32

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

Слайд 33

Managing Scripts

Слайд 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)

Слайд 35


Слайд 36

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

Слайд 37

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

Слайд 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

Слайд 39

That’s it!

Слайд 40

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

Слайд 41

Make your own scripts!

Слайд 42

Thank you! Slides are available on my Twitter @adler_hsieh