DEV Community

loading...

Looking for scripting language

mcsneaky profile image McSneaky ・1 min read

Hi!

My first post / question in here so all pointers regarding to creating posts are welcome too.

I've been on the lookout for good language to learn for scripting and automating things. Mostly setting up servers, automating some helpdesk tasks (might include dealing with Excel), generating pdf files, moving files and folders across servers etc.

Requirements are:

  • Compiles to single file binary for easy share for non tech savvy people
  • Easy cross platform building because not everyone is on Linux (sadly)
  • Be productive, ain't nobody got no time to write some automation script for 2 months

Can someone point at some language / framework to use and learn with little bit more explanation than: "Python, it's best for everything"

Discussion

pic
Editor guide
Collapse
vonheikemen profile image
Heiker

Have a look a Nim. The syntax looks a lot like python, it can produce binaries for windows, linux, BSD and macOS (or at least that what they say). It is a compiled language that actually has C and javascript (and maybe others) as a target.

Collapse
mcsneaky profile image
McSneaky Author

I think I've heard of Nim once or twice, but that's about it.
Their homepage promises everything that I need / want. Not sure if it lives up to it tho.
Definetly will test it out 😋

Collapse
benbot profile image
Benjamin Botwin

Everything you listed (other than the need for a single binary) is pretty much why people use python.

Python is easy to write, easy to read, and runs the same on Windows, OSX, and Linux.

Ansible is a great python tool for provisioning servers.

For directory manipulation tasks and messing with excel sheets there's a ton of very mature, very well documented libraries in python-land.

There's even a cookbook for a lot of the work it sounds like you want to do!
Take a look at automatetheboringstuff.com/

But if you NEED a single binary, you should use go. It's not as simple as python, but it's not much harder. Though provisioning servers with go is, IMO, nowhere near as easy as it is with a tool like ansible

Collapse
ahferroin7 profile image
Austin S. Hemmelgarn

The single binary thing actually is covered for Python, it's just that almost nobody uses it because it's a huge amount of effort for what honestly is very little benefit (new enough Python can handle modules packed into ZIP files, which gets you the same 'copy this file and then run this command' functionality). Check out cx_freeze for the most used option.

Collapse
mcsneaky profile image
McSneaky Author

Yea, everyone seems to be using Python for all scripting. Need for single binary would just make it easier to send it to some non-it work mates over Slack / Discord etc so they can get some simple automation things done with it too. (Like converting Excel to PDF and hurling it to server over FTP automatically or something similar)

Definetly will look closer into Python

Collapse
mcsneaky profile image
McSneaky Author

Rust: it seems to compile cross platform quite well, it's really-really fast, it results in single binary, but learning curve is quite long (heard it can take years to be productive in it), is it worthwhile to learn and will it really take years?

C: Since it used to be my main language years ago I looked into that too, but it kills productivity lil bit too much. Maybe I should just brush up my C skills and stick with that?

Golang: This GO_PATH thing drove me crazy, I'd like to keep my code where I want it to be, like: ~/Projects/Some-Project/migrator etc. Not have all Golang stuff in one place ~/go/ JS code in other place etc. Also heard it's cross compiling is really bad compared to Rust

C# / .NET core 3: Got cross compiling and everything working quite well, but single binary is quite big (about 30mb for simple hello-world).

Python: Requires some additional tooling to get it into single binary + it bundles runtime into it like C# and makes bundle size big

JavaScript: Same as Python

Maybe there is some other language that I have not looked at all? From those mentioned Rust, Golang and C# seemd to be something to go for

Collapse
ahferroin7 profile image
Austin S. Hemmelgarn

I don't think you're going to find a decent option that doesn't bundle the whole runtime into the binary. The problem is that you need that if you want it to be truly independent of the host system, because otherwise you have to depend on whatever the target systems happen to have installed. Keep in mind though that that's a (mostly) static overhead. The bigger your tool, the less that matters.

You might also want to look into Python's support for packages/scripts bundled as ZIP files. If you can ensure a consistent Python version and all the libraries being installed on each target system, you can bundle all the files for a script into a ZIP file, name the main one __main__.py and put it at the root of the ZIP file, and then just invoke the ZIP file like a Python script. Supported by both 2.7 and recent 3.x versions. Relevant documentation is here. Obviously this won't work for double-clicking on a script from the GUI, but given that you're talking about automation you should be able to bundle the ZIP file into a script itself that just works (either as part of a shell archive for UNIX-like systems, or an executable for Windows using a small C stub program that should never need to change).

Collapse
mcsneaky profile image
McSneaky Author

Aah, that seems to be quite interesting, didn't know you can package stuff like this. Not a Python dev and this PIP package management has always been pain imo. Will look into it :) Thanks!

Collapse
nickholmesde profile image
Nick Holmes

I'm a fan of PowerShell. Here's what they say about themselves:

PowerShell Core is a cross-platform (Windows, Linux, and macOS) automation and configuration tool/framework that works well with your existing tools and is optimized for dealing with structured data (e.g. JSON, CSV, XML, etc.), REST APIs, and object models. It includes a command-line shell, an associated scripting language and a framework for processing cmdlets.

For the activities you mention, it is indeed very powerful. It meets all your requirements. I never actually compiled it to binary myself, as a combination of code signing and the package management address my needs well. PowerShell can also do Desired State Configuration, and you can use it with Ansible (or alone).

Collapse
mcsneaky profile image
McSneaky Author

Hmm, never thought about using powershell. I'll give it a try and see how well I can get it work cross platform.
Thnx for sharing another idea! 😋

Collapse
swiknaba profile image
Lud

Non tech savvy people means, the scripting language either can be compiled to an executable, or the language has to be available on the OS by default.

Or can you tell people, oh, it's a simple script, but you have to install and compile a new language on your OS?!

If it's really simple tasks: how about bash (i.e. you will send a zip + a .sh file)?

You can also use JavaScript, and then use electron to build a tiny app that even comes with a GUI. Ruby is similarly to Python a very mature language if it comes to libraries that can handle everything you need.

You can also put installing, unzipping and running your script in a bash script, that people can simply execute. Ansible is cool, but keep it simple and don't throw too many frameworks and tools into it, else you're gonna spend more time reading all the docs than coding your script.

Lastly, you can also just run it on a server, e.g. put it on a AWS lambda, or digital ocean droplet, and send your friends a link.

Collapse
mcsneaky profile image
McSneaky Author

Or can you tell people, oh, it's a simple script, but you have to install and compile a new language on your OS?!

Can't really go and ask accountant to install Ruby or PHP on their PC :|

If it's really simple tasks: how about bash (i.e. you will send a zip + a .sh file)?

For simpler personal things I've just used bash scripts but problem with it is that I can't share them to Windows users (not sure about Mac)

I think I won't dig into Ansible, at least it seems too much overkill for now.

Haven't ever touched Ruby. If it comes to use Ruby vs Python I'd most likely go with Python

Electron is decent idea too, could build whole toolset for company on top of that with some GUI not just some simple automation scripts..

Collapse
tinydevops profile image
Jonathan Hall

Scripting languages by definition, are not compiled. So you need to make a choice: Do you want a scripting language, or do you want something that compiles to a single binary? You can't have both.

Collapse
mkimont profile image
Matt Kimek

Node, python, php, bash, rust, go, bash, anything what have access to cli. I think the main question is 'how to secure my code base if I will send it somewhere else'? It doesn't need to be binary as you can setup all of those scripts to be executable.

Collapse
mcsneaky profile image
McSneaky Author

Including while runtime feels quite hackish. But like others have mentioned already this seems to be only decent way to get true cross platform support..

Collapse
juancarlospaco profile image
Juan Carlos

Try nim-lang.org
Easy cross platform single file binary. Deploy is just scp the binary.
Usually needs less code than Python3 to do stuff so is very productive.

Collapse
mcsneaky profile image
McSneaky Author

Been playing litte bit with Nim in past few days. Still a lot to learn and understand but general feeling for it is quite good.

Will try to make some real script today / tomorrow and see how it behaves in cross platform env. 😋