Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Automating Your Daily Tasks with
Scripting
Adler Hsieh
RubyConf Taiwan
2015-9-11
Agenda
• What is Scripting
• Why Scripting
• Several Cases
• Script Management
• Q & A
Only Basic Concept
Who am I
• Adler Hsieh
• Software Engineer at OneAD
• Ruby, JavaScript, PHP
Github: adlerhsieh
Twitter: @adler_hsieh
Blog:...
What is Scripting
Let’s make it simple
Um…
Let’s make it a little useful
How do I get my local ip address?
> ifconfig
What is scripting
192.168.1.149
Your local ip address
What is scripting
What is scripting
Basically…
Small programs
solving
Small problems
Plus…
• Saves time
• Easy to write
• Easy to manage
And…
Show off
Cases
• Cleaning old files
• Shutdown local server
• MySQL Database import from .sql
Cleaning Old Files
Scenario
• All downloaded files are in one directory
• Directory becomes very large
Cleaning Old Files
Cleaning Old Files
Cleaning Old Files
Use it with Cron
Shutdown Server
Scenario
• Local server crashes
• I cannot shut down my rails server with ctrl + c
Shutdown Server
> lsof –i:3000
> kill -9 PID
Shutdown Server
Importing MySQL database with .sql
Scenario
• When there is bug
• Importing production DB to local DB
Importing MySQL database with .sql
> ssh username@100.100.100.100
> mysqldump –u username –p db_name > db.sql
> exit
> scp...
Importing MySQL database with .sql
Cases
• Scripts are task-specific
• Find patterns in your tasks
Managing Scripts
Managing Scripts
If you do not manage scripts…
• Scripts everywhere
• You have to remember file locations
Managing Scripts
Purpose
• All scripts at a glance
• Write once, run everywhere
Rake
Managing Scripts
• Rake
– Managing all rake tasks in ~/.rake folder
task_a.rake
task_b.rake
– Prefixing ‘rake’ command
– D...
Managing Scripts
Managing Scripts
• Managing tasks like in Rails
– restart.rake
– import.rake
– local_ip.rake
– clean.rake
Thus, run `rake`...
Executables
Managing Scripts
• Make scripts executables
– Separate scripts by commands
• The bad part
– Too many commands
– Conflictin...
Managing Scripts
> chmod 755 hello.rb
> mv hello.rb hello
> ./hello
Managing Scripts
• Change the following line in your ‘.bashrc’:
export PATH=“/user/bin:/usr/local/bin”
• To:
export PATH=“...
That’s it!
Recap
• Scripts are small programs solving small
problems
• Scripts are case-specific
• Automation saves energy & time
• M...
Make your own scripts!
Thank you!
Slides are available on my Twitter
@adler_hsieh
Automating Your Daily Tasks with Scripting - RubyConf 2015 Taiwan
Upcoming SlideShare
Loading in …5
×

Automating Your Daily Tasks with Scripting - RubyConf 2015 Taiwan

6,069 views

Published on

This talk aims to go through basic scripting skills in Ruby. Participants will have a better understanding in managing their daily tasks with scripting. For example, we can setup automated scripts to delete old files on a daily basis instead of doing it manually. These can be done with Bash, Perl and many other scripting languages, but among of which Ruby is better known for its readability. It is easier to write, maintain, and reuse. It saves some time on system management and allows us to put more focus on the projects.

Published in: Software, Engineering
  • Nice !! Download 100 % Free Ebooks, PPts, Study Notes, Novels, etc @ https://www.ThesisScientist.com
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Hello! Get Your Professional Job-Winning Resume Here - Check our website! https://vk.cc/818RFv
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Automating Your Daily Tasks with Scripting - RubyConf 2015 Taiwan

  1. 1. Automating Your Daily Tasks with Scripting Adler Hsieh RubyConf Taiwan 2015-9-11
  2. 2. Agenda • What is Scripting • Why Scripting • Several Cases • Script Management • Q & A
  3. 3. Only Basic Concept
  4. 4. Who am I • Adler Hsieh • Software Engineer at OneAD • Ruby, JavaScript, PHP Github: adlerhsieh Twitter: @adler_hsieh Blog: http://motion-express.com
  5. 5. What is Scripting
  6. 6. Let’s make it simple
  7. 7. Um…
  8. 8. Let’s make it a little useful
  9. 9. How do I get my local ip address?
  10. 10. > ifconfig
  11. 11. What is scripting 192.168.1.149 Your local ip address
  12. 12. What is scripting
  13. 13. What is scripting Basically… Small programs solving Small problems
  14. 14. Plus… • Saves time • Easy to write • Easy to manage
  15. 15. And… Show off
  16. 16. Cases • Cleaning old files • Shutdown local server • MySQL Database import from .sql
  17. 17. Cleaning Old Files Scenario • All downloaded files are in one directory • Directory becomes very large
  18. 18. Cleaning Old Files
  19. 19. Cleaning Old Files
  20. 20. Cleaning Old Files Use it with Cron
  21. 21. Shutdown Server Scenario • Local server crashes • I cannot shut down my rails server with ctrl + c
  22. 22. Shutdown Server > lsof –i:3000 > kill -9 PID
  23. 23. Shutdown Server
  24. 24. Importing MySQL database with .sql Scenario • When there is bug • Importing production DB to local DB
  25. 25. Importing MySQL database with .sql > ssh username@100.100.100.100 > mysqldump –u username –p db_name > db.sql > exit > scp username@100.100.100.100:db.sql db.sql > mysql –u username –p db_name < db.sql
  26. 26. Importing MySQL database with .sql
  27. 27. Cases • Scripts are task-specific • Find patterns in your tasks
  28. 28. Managing Scripts
  29. 29. Managing Scripts If you do not manage scripts… • Scripts everywhere • You have to remember file locations
  30. 30. Managing Scripts Purpose • All scripts at a glance • Write once, run everywhere
  31. 31. Rake
  32. 32. Managing Scripts • Rake – Managing all rake tasks in ~/.rake folder task_a.rake task_b.rake – Prefixing ‘rake’ command – Description support
  33. 33. Managing Scripts
  34. 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. 35. Executables
  36. 36. Managing Scripts • Make scripts executables – Separate scripts by commands • The bad part – Too many commands – Conflicting with existing commands
  37. 37. Managing Scripts > chmod 755 hello.rb > mv hello.rb hello > ./hello
  38. 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. 39. That’s it!
  40. 40. Recap • Scripts are small programs solving small problems • Scripts are case-specific • Automation saves energy & time • Managing scripts with rake
  41. 41. Make your own scripts!
  42. 42. Thank you! Slides are available on my Twitter @adler_hsieh

×