Some Commands helpful in Bash Shell Scripts

# cat /etc/crontab (To read/print any file) # cat –n /etc/crontab (To print files with line number) # cat /etc/crontab /etc/passwd (To print multiple files together) # tac /etc/crontab (To print exact opposite output from cat command) # wc /etc/crontab (To print line, word, character count of file) # wc -l /etc/crontab (To print line […]

Basic Operators in Shell Scripting

Logical Operator or Boolean Operator: && -a {Logical AND}: Execute the command when both conditions are true || -o {Logical OR}: Any of one condition will work. ! ! {Not equal to}: Negates the result of the condition. Note: If you will use “-a, -o, !” you need to use [ ] in condition while […]

Quotes in Bash Shell

Quotes are very crucial in Bash Shell Scripting. These are used to define and delimit strings in shell or Shell scripts. It can disable the special treatment of a special character. It is also very helpful to prevent reserved words. You can use them to run commands in shell, Processing variables in shell, etc.There are […]

A simple python script to install a rpm package in linux

Below is the simple program to install a package named “vsftpd” in linux OS. You need to import “os” module for that. #!/usr/bin/python3.6 import os try: os.system(‘dnf install vsftpd’) except: exit("Failed to install package")

Bash Script to append “host and ip entries” in remote server “/etc/hosts” file

We can use below script to add host and ip entries in /etc/hosts file. $ cat append.sh #!/bin/bash ## Append hostname and IP in /etc/hosts file hostname=$1 ip=$2 /usr/bin/sshpass -p ‘password’ ssh user@$1 "echo password | sudo -S sh -c ‘echo "$2 $1 $1.example.com" >> /etc/hosts’" $ sh append.sh test-server 192.168.1.100 It will make entry […]