Skip to main content

Posts

Python Programming

Recent posts

Shell Script with command line arguments

How to pass values on commandline in shell script : ============== #!/bin/bash for i in $@ do     echo $i     s=$i     if [ "$s" -lt "3" ]     then     echo "$s"         fi    done ============== Output : # sh t2.sh 4 5 6 4 5 6 Output : # sh t2.sh 1 2 3 4 1 1 is less than 3 2 2 is less than 3 3 4

Shell script with functions

Shell Script with Function: You can define a function and the commands/code in it. Then you can call that function at last line which will execute all commands mention in that block for you. f1() { var="Welcome to the geekstuff" echo ${#var} } f1 Output : ./test.sh 24

Shell Scripts for daily system admin use

Shell Script is nothing but sequence of commands that are stored in a single file (same like a text file) . The shell is the operating system's command interpreter and the set of commands you use to communicate with the system. A shell script is usually created for command sequences for which a user has a repeated need. The shell script extension is ".sh". You need to save the file as filename.sh and give it 755 permission for execute. The simple term for writing the shell  script is collect all those task you need to perform in sequence and execute those line by line. For example if you want to kill the CPU consuming processes or some other type of processes then you should use below shell script. =======  #!/bin/bash #Purpose: To kill the running process (backup or cpu consuming ) and record those processes in file upto certain size. #Author: Mahesh Kale #Date/Time: 06-06-2018 2:00 ps=($(ps -auxf | grep processname | awk '{print $2}'

Ansible PlayBooks

Ansible playbooks are a way to send commands to remote computers in a scripted way. Instead of using Ansible commands individually to remotely configure computers from the command line, you can configure entire complex environments by passing a script to one or more systems. Ansible playbooks are written in the YAML data serialization format. If you don't know what a data serialization format is, think of it as a way to translate a programmatic data structure (lists, arrays, dictionaries, etc) into a format that can be easily stored to disk. The file can then be used to recreate the structure at a later point. JSON is another popular data serialization format, but YAML is much easier to read. Each playbook contains one or more plays, which map hosts to a certain function. Ansible does this through something called tasks, which are basically module calls. https://docs.ansible.com/ansible/devel/user_guide/playbooks.html Playbook example : You should write the code in file

Ansible Ad-hoc commands

Ad-hoc commands in Ansible allow you to execute simple tasks at the command line against one or all of your hosts. Syntax:- ansible <hosts> [-m <module_name>] -a <"arguments"> -u <username> [--become] The list of all modules here: https://docs.ansible.com/ansible/latest/modules/list_of_all_modules.html The ping module: Try to connect to host, verify a usable python and return pong on success root@:/etc/ansible# ansible all -m ping ip address | SUCCESS => {     "changed": false,     "ping": "pong" }   root@:/etc/ansible# ansible all -i ./hosts -m ping root@:/etc/ansible# ansible webservers -m ping