DEV Community

wolfiton
wolfiton

Posted on

What is the best scripting language for secure automation and speed?(python, ruby, rust)

Hi everyone,

I have the following question after reading some posts and some previous knowledge:

What is the best scripting language for secure automation and speed on Linux and in general for DEV-OPS?(python, ruby, rust)

Thanks in advance to all the participants to this discussion

Top comments (14)

Collapse
 
bittnkr profile image
bittnkr • Edited

To me, maybe because my familiarity with, the best scripting language for automation is JavaScript/Node.

Initially working with exec/spawn can be a little challenging, but once you mastered them, it's very powerful.

Collapse
 
wolfiton profile image
wolfiton

Interesting point, but as I recall JavaScript is not multi-threaded. So I don't think it has speed compared to rust and python.

Collapse
 
avalander profile image
Avalander

As @bittnkr said, you can spawn multiple processes easily with child_process, if you want to run parallel computations.

Collapse
 
bittnkr profile image
bittnkr • Edited

In system automation I think the performance of the hosting language is negligible.

For example, if you need to zip a directory, the speed that really matters is tool you are calling (zip, gzip, 7zip, ...).

If you need to parallelize tasks, in Node you can just spawn another process or use worker threads.

Collapse
 
tobiassn profile image
Tobias SN

Python doesn’t really have multithreading either. Well it technically does, but you can only use one at a time by default.

Collapse
 
mfinotti profile image
Marco Finotti

Python has huge performance, in my opinion it is like PHP and it hasn't an high level of security.

Ruby it is very secure and reactive but it hasn't high performance.

I don't have an opinion on Rust.

In my opinion, in this cases you need to keeping in mind advantages and disadvantages of each of them. For my experience i prefer Python.

Collapse
 
wolfiton profile image
wolfiton

Thanks, @marco for sharing your experience regarding Python.

After some digging and reading, I think that Python has some advantages because it has tutorials and all the knowledge you gain can be transferred to other languages.

Collapse
 
vonheikemen profile image
Heiker • Edited

Take a look at Nim. It can compile to C so speed should not be a problem.

Collapse
 
wolfiton profile image
wolfiton • Edited

Heard about Nim it's trying to be the successor of python right?

Thanks for reminding me of it.

I wonder if Elixir can be used for this as well. (thinking mood)

Found this looks interesting and promising thoughtbot.com/blog/is-elixir-a-sc...

Collapse
 
vonheikemen profile image
Heiker

The syntax does look a lot like python but they take ideas from other languages as well. The fact that is type-safe and can generate self-contained binaries is certainly an advantage they have over python.

Thread Thread
 
wolfiton profile image
wolfiton

Interesting, I will have to test it, I like what you are saying about it.

Collapse
 
wolfiton profile image
wolfiton

It seems that I will have to take into consideration node for my list of scripting languages.

Thanks @bittnkr @avalander @tobiassn

Collapse
 
bittnkr profile image
bittnkr • Edited

Searching my repositories, I found an example where I used node for automation. I think it can serve as a seed for you.

It uses 7zip to create a separated file for each sub-directory.

Useful for when you have one directory with logs for each day or month and want a single zip file per day.

It launches a process for each core of you processor as needed.

You need 7zip installed in your computer. (in linux, sudo apt install p7zip-full)

Save it as zipsubs, mark it as executable chmod +x zipsubs

zipsubs . .git node_modules will zip all subdirs of current dir ignoring .git and node_modules.

It has no dependencies.

#!/usr/bin/env node
const { exec } = require('child_process')
  , fs = require('fs')
  , path = require('path')
  , rootDir = process.argv[2]
  , ignore = process.argv.slice(3)
  , cpuCount = require('os').cpus().length / 2 // no hiper threading

if (!rootDir) {
  console.log('zipsubs: 7zip all subdirs of a directory.\n example of use: zipsubs . [ignore list] ')
  process.exit()
}

let dirs = subDirs(path.resolve(rootDir)).filter(d => ignore.indexOf(d) == -1)
  , running = 0

zipNext()

function zipNext() { // launch a process for each core, as needed
  let dir = dirs.shift()
  if (dir) {
    running++
    zipDir(dir, () => { running--; zipNext() })
    if (running < cpuCount) zipNext()
  }
}

function zipDir(dir, callback) {
  let cmd = `7z a ./${dir}.7z ${path.join(rootDir, dir)}/* -r`
  console.log(cmd)
  exec(cmd, callback)
}

function subDirs(dir) {
  let res = []
  fs.readdirSync(dir).forEach(f => {
    if (fs.statSync(path.join(dir, f)).isDirectory()) res.push(f)
  })
  return res
}
Collapse
 
wolfiton profile image
wolfiton

Thanks for sharing and explaining where you use it, really appreciate it.