LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-01-2019, 06:31 PM   #1
halfpower
Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 212

Rep: Reputation: 30
Post Deployment Automation: Python or Bash?


I'm trying to automate deployment tasks for remote Linux servers. I could do this with either Python or Bash. Python is modern, powerful, and easy to code with. In comparison, Bash is a clunky syntactic outlier lacking common language features. Perhaps it was never even intended for complex programming routines. However, there's no way to avoid using Bash. If I use Python, I'm using it to execute Bash commands. As a programming pattern, I dislike this. It's the notorious "impedance mismatch" just with Bash instead of SQL. Do you have opinions on this matter?
 
Old 09-01-2019, 07:12 PM   #2
Skaperen
Senior Member
 
Registered: May 2009
Location: WV, USA
Distribution: Xubuntu, Slackware, Amazon Linux
Posts: 1,903
Blog Entries: 21

Rep: Reputation: 125Reputation: 125
i have written many big complex bash scripts. my goal is to re-write them into python3. but i plan to leave the very simple scripts in bash.

IMHO, what made bash better than other shell script versions is better done in python3 these days. i am even working on re-writing many of my C programs into python3.

but bash won't go away. it will have some uses. it will still be my interactive shell. i also do some very long commands, sometimes. gotta know bash well for some of those. my longest command, once, was about 440 characters long.
 
Old 09-01-2019, 10:34 PM   #3
Turbocapitalist
Senior Member
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 4,112
Blog Entries: 3

Rep: Reputation: 2003Reputation: 2003Reputation: 2003Reputation: 2003Reputation: 2003Reputation: 2003Reputation: 2003Reputation: 2003Reputation: 2003Reputation: 2003Reputation: 2003
In cases like the one you describe, bash is probably the right choice. No need to complicate things with Python, even if it might be popular in other contexts.
 
Old 09-02-2019, 01:02 AM   #4
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 12,307
Blog Entries: 9

Rep: Reputation: 3309Reputation: 3309Reputation: 3309Reputation: 3309Reputation: 3309Reputation: 3309Reputation: 3309Reputation: 3309Reputation: 3309Reputation: 3309Reputation: 3309
Quote:
Originally Posted by halfpower View Post
I'm trying to automate deployment tasks for remote Linux servers. I could do this with either Python or Bash. Python is modern, powerful, and easy to code with. In comparison, Bash is a clunky syntactic outlier lacking common language features. Perhaps it was never even intended for complex programming routines.
It was, however, intended to deal with the underlying filesystem.
Sorry to hear you're not familiar with it, or shell scripting in general.
Quote:
However, there's no way to avoid using Bash. If I use Python, I'm using it to execute Bash commands. As a programming pattern, I dislike this. It's the notorious "impedance mismatch" just with Bash instead of SQL.
Maybe try the other way round:
Write a bash script that contains python snippets for the more complex stuff?
 
Old 09-02-2019, 01:43 AM   #5
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 3,844

Rep: Reputation: 1320Reputation: 1320Reputation: 1320Reputation: 1320Reputation: 1320Reputation: 1320Reputation: 1320Reputation: 1320Reputation: 1320Reputation: 1320
Off: In the past 30 years, it was Perl.
 
Old 09-02-2019, 04:04 AM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,719

Rep: Reputation: 3034Reputation: 3034Reputation: 3034Reputation: 3034Reputation: 3034Reputation: 3034Reputation: 3034Reputation: 3034Reputation: 3034Reputation: 3034Reputation: 3034
This sounds more like a rant than a question

The beauty of the shebang is that whichever interpreter you choose to use is up to you. If python is your jam then use that.

Like other posters here, I have written many bash scripts from several lines to thousands of lines long as the need arose. Why you may ask? Because I am very proficient with
bash and find it a doodle to knock something up in it.

The above being said, I do write in awk and ruby as well, so horses for courses and all that
 
Old 09-02-2019, 04:26 AM   #7
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Slack, Debian, Mint, Puppy, Raspbian
Posts: 3,462

Rep: Reputation: 218Reputation: 218Reputation: 218
Or you could perhaps use a tool designed for this and save a lot of messing about.
like pssh or dsh
 
Old 09-02-2019, 10:03 AM   #8
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (Chicago area)
Distribution: CentOS, MacOS, [Open]SuSE, Raspian, Red Hat, Slackware, Solaris, Tru64
Posts: 1,478

Rep: Reputation: 154Reputation: 154
Quote:
Originally Posted by halfpower View Post
In comparison, Bash is a clunky syntactic outlier lacking common language features. Perhaps it was never even intended for complex programming routines.
Perhaps. But it has been used for some complex tasks. (See attached image. This was back in Nov. '92)
Attached Thumbnails
Click image for larger version

Name:	UNIX_Accounting.jpg
Views:	22
Size:	112.3 KB
ID:	31278  
 
1 members found this post helpful.
Old 09-02-2019, 11:04 AM   #9
halfpower
Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 212

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by ondoho View Post
It was, however, intended to deal with the underlying filesystem.
Sorry to hear you're not familiar with it, or shell scripting in general.
I realize I'm not a Bash expert and this makes things more difficult for me. Having a different syntactic lineage than that of C++, Python, JavaScript, Java, C#, etc makes it more challenging. Still, there are a lot of things (e.g. referring to variables and copying arrays) that are much easier in Python and JavaScript.


Quote:
Originally Posted by ondoho View Post
It was, however, intended to deal with the underlying filesystem.
Maybe try the other way round:
Write a bash script that contains python snippets for the more complex stuff?
An interesting idea. Although I was thinking that the complexity is likely to be more with the architecture of the program/framework.
 
Old 09-02-2019, 11:20 AM   #10
halfpower
Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 212

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by bigearsbilly View Post
Or you could perhaps use a tool designed for this and save a lot of messing about.
like pssh or dsh
These look like useful tools. However, my goal with this is to never run a command on the remote machine itself. In other words, everything (configurations, instructions, queries, etc) is done locally and then deployed.
 
Old 09-02-2019, 04:28 PM   #11
boughtonp
Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 32

Rep: Reputation: 1
I write Bash scripts because it's ubiquitous, (also I've not yet taught myself Python).

Like every language, there are some tasks it makes nice and easy, some tasks which it turns into an interesting challenge, but also a large number of times when its quirks are infuriating.

When I get stuck, the two main resources I check are:
Simon Sheppard's SS64 reference: https://ss64.com/bash/
The FAQ on Greg's wiki: https://mywiki.wooledge.org/BashFAQ

Those usually provide an answer, or at least a nudge in the right direction.
 
Old 09-04-2019, 04:30 PM   #12
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 9,094

Rep: Reputation: 3931Reputation: 3931Reputation: 3931Reputation: 3931Reputation: 3931Reputation: 3931Reputation: 3931Reputation: 3931Reputation: 3931Reputation: 3931Reputation: 3931
Quote:
Originally Posted by bigearsbilly View Post
Or you could perhaps use a tool designed for this and save a lot of messing about.
like pssh or dsh
Or, you know, ansible, puppet, chef, saltstack, and those things.
 
Old 09-05-2019, 12:58 AM   #13
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 1,179

Rep: Reputation: 533Reputation: 533Reputation: 533Reputation: 533Reputation: 533Reputation: 533
How compatible is python 3 with python 2? One day you will be confronted with python 4 versus python 3.
 
2 members found this post helpful.
Old 09-05-2019, 07:21 PM   #14
YesItsMe
Member
 
Registered: Oct 2014
Distribution: Gentoo
Posts: 557

Rep: Reputation: 210Reputation: 210Reputation: 210
Quote:
Originally Posted by MadeInGermany View Post
How compatible is python 3 with python 2?
Not at all.

For sophisticated automation which does not require any specialized software (which needs to be supported on all involved operating systems), you basically have two rationally good options:
  1. Write standard shell scripts.
    Those are not the same thing as "bash scripts". The bash, not necessarily identical to your system's shell, can be configured to work as a superset of the POSIX shell, but bash scripts are not automatically portable. Remember that (e.g.) the ksh does not support bashisms. Always consider that you might want to use a system with a different shell one day.
    I, personally, found the Schily Bourne Shell to be a superb POSIX-compatible scripting shell.
  2. Write portable scripts in a platform-independent language.
    I usually use Perl (for text processing) or Common Lisp (for more complex tasks). I played a bit with Python 2 and 3, but the schism between both languages is a huge disadvantage. You'll never know if your scripts will still work in a decade if your language of choice is a moving target. (This is also why I try to use as little Go as possible.)
 
3 members found this post helpful.
Old 09-10-2019, 05:15 PM   #15
boughtonp
Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 32

Rep: Reputation: 1
Quote:
Originally Posted by YesItsMe View Post
The bash, not necessarily identical to your system's shell, can be configured to work as a superset of the POSIX shell, but bash scripts are not automatically portable.
Are there any systems where #!/bin/bash (as opposed to #!/bin/sh) will execute a shell that is not Bash-compatible?
 
  


Reply

Tags
automation, bash, deploy, python


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: OpenStack automation with cloud deployment tools LXer Syndicated Linux News 0 09-12-2014 12:14 PM
[SOLVED] redhat deployment with Altiris HP Rapid Deployment Tool lievendp Linux - Server 2 08-03-2011 03:11 AM
LXer: Python Python Python (aka Python 3) LXer Syndicated Linux News 0 08-05-2009 08:30 PM
deployment/scripting/automation kevinyeandel Linux - Server 3 02-09-2009 12:51 AM
Kickstart automation deployment help bbmak Linux - Enterprise 5 02-20-2007 02:06 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:15 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration