SHARE
TWEET

sujet shellscripting

a guest Jan 21st, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Module : B-SHL-400
  2. Repository name : SHL_$YEAR_shell ($YEAR=2017 for 2017/2018)
  3. Repository rights : ramassage-tek
  4. Language : /bin/sh or /bin/bash
  5. Group Size : 1-2
  6. Authorized binary : /!\ See end of this file ! /!\
  7. Yammer Group : PSH $PROMO
  8.  
  9. -------------------------------------------------------------------------------
  10. Warning : for all scripts, error messages must be send on stderr output, and
  11. program exit with error code 1 when error
  12. -------------------------------------------------------------------------------
  13.  
  14. -------------------------------------------------------------------------------
  15. Update 23/01/2018 - 10:35
  16. Before update :
  17.   ./bdsh -f file.json insert user id=4,firstname=Robert John,lastname=WILLIAMS
  18. After update :
  19.   ./bdsh -f file.json insert user id=4,firstname=Robert\ John,lastname=WILLIAMS
  20. -------------------------------------------------------------------------------
  21.  
  22.  
  23. Subject:
  24.   Write a shell script that allows you to manage a database in a json file.
  25.   You must create table, insert-update-remove data, run query, ...
  26.          
  27. Database File:
  28.   The database file can be specified in 3 ways, in order of priority:
  29.     as argument in command line : -f file
  30.     in environment : BDSH_File=
  31.     in a configuration file : .bdshrc
  32.    
  33. Program must display error when :
  34.     Syntax error in command line (bad arguments, ...)
  35.     Database already exist when create database
  36.     Can't create database (disc full, ...)
  37.     Table already exist when create table
  38.     Table not found when select, insert, ...
  39.     Fields not found when select, insert, ...
  40.     Select on empty database
  41.     ...
  42.    
  43. Syntax:
  44. $> ./bdsh
  45. Usage: ./bdsh [OPTION]... [COMMAND] [REQUEST]
  46. OPTION:
  47.   -h                display usage
  48.   -f FILE           json database file
  49.   -j                json formated output for select command
  50.  
  51. COMMAND and REQUEST:
  52.     create      create database
  53.             Exemple:
  54.                 ./bdsh -f file.json create database
  55.                 ./bdsh -f file.json create table user id,firstname,lastname
  56.                 ./bdsh -f file.json create table age id,age
  57.  
  58.     insert      insert data in database
  59.             Exemple:
  60.                 ./bdsh -f file.json insert user id=1,firstname=John,lastname=SMITH
  61.                 ./bdsh -f file.json insert user id=4,firstname=Robert\ John,lastname=WILLIAMS
  62.                 ./bdsh -f file.json insert user id=2,firstname=Lisa,lastname=SIMPSON
  63.                 ./bdsh -f file.json insert user id=10,lastname=SMITH
  64.                 ./bdsh -f file.json insert user firstname=Laura,lastname=SMITH
  65.                 ./bdsh -f file.json insert user id=9
  66.                 ./bdsh -f file.json insert age id=1,age=42
  67.  
  68.     describe      describe table structure
  69.             Exemple:
  70.                 ./bdsh -f file.json describe user
  71.                 id
  72.                 firstname
  73.                 lastname
  74.  
  75.     select      display data from database
  76.             Exemple:
  77.                 ./bdsh -f file.json select user firstname,lastname
  78.                 firstname    | lastname
  79.                 -------------------------
  80.                 John         | SMITH
  81.                 Robert John  | WILLIAMS
  82.                 Lisa         | SIMPSON
  83.                              | SMITH
  84.                 Laura        | SMITH
  85.                              |
  86.                 ./bdsh -f file.json select user lastname,firstname order
  87.                 lastname  | firstname
  88.                 -------------------------
  89.                           |
  90.                 SIMPSON   | Lisa
  91.                 SMITH     |
  92.                 SMITH     | John
  93.                 SMITH     | Laura
  94.                 WILLIAMS  | Robert John
  95.  
  96. File Format :
  97.     Database file is a json file correctly formated.
  98.     Json file must contain 2 arrays for a table :
  99.         desc_$table : array with field list of table
  100.         data_$table : array with list : field:value
  101.         see sample.json in subject directory
  102.  
  103. Shell:
  104.     Shell must be /bin/sh or /bin/bash (#shebang)
  105.  
  106. -------------------------------------------------------------------------------
  107.  
  108. Authorized binary :
  109.   * expr
  110.   * wc
  111.   * head
  112.   * tail
  113.   * cat
  114.   * sort
  115.   * grep
  116.   * sed
  117.   * cut
  118.   * tr
  119.   * touch
  120.  
  121.  -------------------------------------------------------------------------------
  122.  
  123. Bonus :
  124.         Add many query, join, where, ...
  125.        
  126.         Exemple:
  127.  
  128.                 ./bdsh -f file.json select user,age age,firstname,lastname join id where age=42
  129.                 age  | firstname  | lastname
  130.                 ------------------------------
  131.                 42   | John       | SMITH
  132.                
  133.                 ./bdsh -f file.json update user firstname=Marry where firstname=John
  134.                 ./bdsh -f file.json update user lastname=DAVIS,firstname=Marge where id=9
  135.                
  136.                 ./bdsh -f file.json delete user where lastname=SMITH
  137.                 3 row(s) deleted
  138.                
  139.                 ./bdsh -f file.json select user firstname,id where lastname=SMITH
  140.                 firstname  | id
  141.                 -----------------
  142.                 John       | 1
  143.                            | 10
  144.                 Laura      |
  145.                
  146.                 ./bdsh -f file.json select user firstname, lastname where lastname=SMITH order
  147.                 firstname  | lastname  
  148.                 -----------------------
  149.                            | SMITH
  150.                 John       | SMITH
  151.                 Laura      | SMITH
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top