Python 3 for System Administrators: The Plot!
Tags: linux, python, bash, learning
Published: 2020-04-26 19:25:27

#### :notebook: Shell or Python? Should I replace my Shell scripts with Python?
```It’s debatable!```

That’s what `Nick`, who has been a mentor for `Ajay`, added. 

It certainly depends, whether you work in Sysadmin, Cloud operations, DevOps, or SRE. But that love for Shell would always be there. We all started with it and it’s the glue! 

**Ajay**: But isn’t Shell scripts slow? In addition, it lacks data structure and gets highly complex with long scripts. 

**Nick**: Maybe, but that’s not the point :smile: There are day-to-day tasks that can be performed in both, say checking application ports, starting/stopping the server, checking the resources consumption/load, backing up your database and exporting it to object storage.

:snake: `Python` is clean, it feels like writing pseudocode. In other words, it’s easier to write and maintain, provides better error handling, can perform OOP (object-oriented programming), and the best part is argument parsing and modules. 

:shell: `Shell` is something that we all have started with, hence I describe it with words “omnipresence” or “has ubiquity”. Quick filtering or command chaining with Pipe ("|") and CLI utilities like sed, awk, grep, etc.


![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/8e9muvqd4v7kj8kcc4yt.jpg)

**Ajay**: Awesome, let me give it a shot; it would certainly help to add new skills to my knowledge bank, at the very least. 

Hence, `Ajay`- who has been a sysadmin all the while writing scripts in shell, just wants to try Python and see how he can make use of both to add more efficiency to his day-to-day work.

So, this is `Ajay’s` review on Linux academy’s course for Python which he found out while browsing the internet and it simply said: “Learn or start only with modules and structure that would be useful for you as Sysadmin and not the whole Python at once!”

_Ajay_ can be any person who has spent a good time with shell, and not specially sysadmin. So this is for anyone who just wants to add an element to fun to work and has been wanting to learn Python for a long time!

The entire story/review can be found with the following link, it was a bit long to add here!

Review: https://sachcode.com/tech/linux-academy-review-system-administrators-python/
Acloudguru:  https://acloudguru.com/
```
Note: This is in no way a connection or recommendation from me to try only Linux Academy; I just loved the course and this was an honest review. 
```

It contains the use-case on who this course is for, my experience on the operations side, and some key takeaways. Each section’s outcome(s), and the overall links to codes, as well as entire Python projects-repos on GitHub that came out as learning.

Some of the fun exercise(s) and key outcomes- snip!
```js{}
Project:
We have many database servers that we manage, and we want to create a 
single tool that we can use to easily back up the databases to either 
AWS S3 or locally. We would like to be able to:

> Specify the database URL to backup.
> Specify a “driver” (local or s3)
> Specify the backup “destination”. This will be a file path for local 
and a bucket name for s3.
> Depending on the “driver”, create a local backup of the database or 
upload the backup to an S3 bucket.
```

https://github.com/linuxacademy/content-python-for-sys-admins/tree/master/pgbackup

```
Usage:
..............
Pass in a full database URL, the storage driver, and destination.
S3 Example w/ bucket name:
$ pgbackup postgres://bob@example.com:5432/db_one --driver s3 backups

Local Example w/ local path:
$ pgbackup postgres://bob@example.com:5432/db_one --driver local \
/var/local/db_one/backups/dump.sql
```

:pen: https://sachcode.com/