Knowledge Base

Takeaway Sheet: The Basics of Launching Scripts

Glossary

SSH — a technology that makes it possible to manage operating systems on virtual machines securely.

Practice

1# Connecting to the virtual machine from the command line
2
3ssh -i <path_to_private_key> ubuntu@<public_dns>

1# The minimal Python script code
2
3#!/usr/bin/python
4
5if __name__ == "__main__":
6 # Code

1# Getting command line arguments
2
3arguments = sys.argv
4
5# Input parameters' format
6
7unixOptions = "s:e:" # parameters in UNIX format
8gnuOptions = ["start=", "end="] # parameters in GNU format
9
10# Check whether input parameters match the format
11# indicated in unixOptions and gnuOptions
12try:
13 arguments, values = getopt.getopt(argumentList, unixOptions, gnuOptions)
14except getopt.error as err:
15 print (str(err))
16 sys.exit(2) # Stop execution if input parameters are incorrect
17
18# Read the values from the string with input parameters
19
20start = ''
21end = ''
22for currentArgument, currentValue in arguments:
23 if currentArgument in ("-s", "--start"):
24 start = currentValue
25 elif currentArgument in ("-e", "--end"):
26 end = currentValue

1# Launching a Python script containing parameters
2
3python params_test.py --start='start' --end='end'

1# Transmitting a file to a virtual machine
2
3scp -i <path_to_private_key> <path_to_a_local_file> ubuntu@<public_dns>:

1# Calling cron schedule editor
2
3crontab -e
Send Feedback
close
  • Bug
  • Improvement
  • Feature
Send Feedback
,