February Scripting Workshop

introduction to scripting workshop n.w
1 / 74
Embed
Share

Join George Garrett and the HPC Support Team for an Introduction to Scripting Workshop on February 23, 2016. Learn about scripting, shell scripts, and why they are essential. Discover valuable resources for Linux scripting and access instructions for both Windows and Mac users.

  • Workshop
  • Scripting
  • Linux
  • Shell Script
  • Tutorial

Uploaded on | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. Introduction to Scripting Workshop February 23, 2016

  2. Introduction George Garrett & The HPC Support Team Research Computing Services CUIT

  3. Introduction Please Leave Feedback

  4. Introduction Slides will be sent out afterwards.

  5. Introduction What is a script?

  6. Introduction What is a shell script?

  7. Introduction What is a shell script? A file with shell commands.

  8. Introduction Why use scripts?

  9. Scripting Resources How Linux Works by Brian Ward Available as an E-book from Columbia University Libraries and at Safari Books Online

  10. Scripting Resources Shell and Scripting Tutorial http://linuxcommand.org/

  11. Scripting Resources Advanced Bash-Scripting Guide http://tldp.org/LDP/abs/html/

  12. Cunix System: cunix.columbia.edu User: Your UNI

  13. Access Windows Instructions 1. Search for putty on Columbia home page 2. Select first result 3. Follow link to Putty download page 4. Download putty.exe 5. Run putty.exe

  14. Access Mac Instructions 1. Run terminal

  15. Access Mac (Terminal) $ ssh UNI@cunix.columbia.edu Windows (Putty) Host Name: cunix.columbia.edu

  16. Access Does everyone have access?

  17. Quick Review shell $ pwd cd . ls user interface to the system standard prompt symbol print working (current directory) change directory current directory list directory contents

  18. Quick Review cat sort grep echo hi sleep 5 man print a file sort the lines of a file print lines matching a pattern print hi wait 5 seconds command manual

  19. Workshop Setup $ mkdir workshop $ cd workshop $ cp /tmp/workshop/* .

  20. Command Line Example Word Count from Data Science at the Command Line - Jeroen Janssens

  21. Lets Download Some Data Gutenberg Project: http://www.gutenberg.org Which famous novel should we use? Download plain text version using curl $ curl [URL] > novel.txt Trim header and footer, leaving only main text

  22. Pipes $ cat alice.txt | grep rabbit Pipes connect output from one command to the input of another command

  23. Pipes $ cat alice.txt | grep rabbit | sort You can keep on combining commands with more pipes.

  24. Pipes $ cat alice.txt | grep rabbit | tr r w tr translate characters

  25. wcount $ cat wcount cat alice.txt | tr

  26. wcount $ wcount

  27. wcount $ wcount -bash: wcount: command not found

  28. wcount $ ./wcount

  29. wcount $ ./wcount -bash:./wcount:Permission denied

  30. wcount $ ls l wcount

  31. wcount $ ls l wcount -rw-rw---- [ snip ]

  32. wcount $ ls l wcount -rw-rw---- $ chmod +x wcount [ snip ]

  33. wcount $ ls l wcount -rw-rw---- $ chmod +x wcount $ ls l wcount -rwxrwx--x [ snip ] [ snip ]

  34. wcount $ ./wcount Should work this time.

  35. file Determine type of file. $ file wcount

  36. file Determine type of file. $ file wcount wcount: ASCII text

  37. wcount Choose an editor nano Recommended default vi emacs

  38. nano Nano commands are on back of cheat sheet. ^ means hold down control

  39. Edit wcount $ nano wcount

  40. #! Add #! to first line #!/bin/sh cat alice.txt | tr

  41. #! $ ./wcount Still works.

  42. #! Some #! first lines you might see #!/bin/sh #!/bin/bash #!/usr/bin/perl #!/usr/bin/python

  43. file Has the file type changed? $ file wcount wcount: POSIX shell script text executable

  44. Variables $ file=alice.txt $ echo $file alice.txt

  45. Variables 1. Add file=alice.txt to wcount. 2. Replace cat alice.txt with cat and the variable.

  46. Variables #!/bin/sh file=alice.txt cat $file | tr

  47. Variables You could put $file in double quotes. Why put quotes around $file? cat $file | tr

  48. Command Line Parameters We re going to change wcount so any file can be specified from the command line. $ ./wcount moby.txt

  49. Command Line Parameters Change wcount so any file can be specified from the command line. $ ./wcount moby.txt $1

  50. Command Line Parameters 1. Create a new file named param 2. Put the #! directive on the first line 3. On next line type: echo $1 4. Save and make executable 5. Run it

Related


More Related Content