Why this category?
Now-a-days we do not have much time to spend for repeated works. We all are busy with learning new things. And we required some automation tools to reduce the work load and save the time. Python is a good and simple language for this purpose. Bookmark the Index page and read more about Python.
If you are a system administrator, it is likely that you have encountered Perl, Bash, or some other scripting language. You may have even used one or more yourself. There are a lot of websites available on internet to study Python. Most of them have a lot of things to read and study.
Here in Crybit.com, going to introduce Python along with Linux command line tools & examples which will be helpful for Linux SysAdmins. You can directly integrate Python with your Shell, LOL!!
I also try to compare Python with Bash.
Okay lets start with “Hello World!” scripts..
Here, the command line tool we used to compute the script is “ipython.” By using “ipython” you can simply test your Python scripts before executing it on your production server.
How to install ipython on CentOS?
The installation is simple. You can simply install it using YUM. Please see the snippet pasted below:
yum install ipython
Now you can use the command “ipython” to enter into the interface.
See the example pasted below:
ipython
Here we go!
First we are going o print the string “Hello World!” as we are thinking this is the first code in programming!! LOL 😛
To print something in Python, you can use “print” option in your code:
To execute in your Shell as .py script, please do the following steps:
Step 1 : SSH to server.
Step 2 : Create a file with extension “.py”
Step 3 : Make sure the file has executable permission.
chmod +x filename.py
Step 4 : Add the following code into it.
#!/usr/bin/python
print "Hello World!"
Step 5 : Execute the file.
python filename.py
As you all know, we use the command “echo” instead of print.
That’s it!
The article is very interesting and effective, really explains everything in detail.Thanks you and good luck