Script to clean largest filesystem

Script to find and clean /var/log

In all the production or development environment there might be some need to analyse the filesystem and clear log files or remove unlinked files on a server. In such case you can use this script as per your requirement. Small modification in this can also help you to clean the large  ..

How do I find filesystem usage on multiple server

Find disk usage on multiple servers

How do I find filesystem usage on multiple server? Find disk usage on multiple servers # awk '{print $2,$3}' monitoring_alerts | tr -d '}' > dfinput Using output field separator OFS # awk 'BEGIN{OFS=":";} {print $2,$3;}' monitoring_alerts | tr -d '}' > dfinput In the above you can see we have  ..

List cron of all users on a server

Print all existing cron jobs

How to find all cron jobs running on the server? In a daily check we normally check what are existing cron jobs set and running on a server. It is always better to have a look and monitor existing cron jobs on the server. How to list all cron jobs of all  ..

How to calculate modulo in shell script

How to use mod operator in shell script

When I was writing a shell script I was having a situation where I want to use mod operator. while using mod orerator you must be very careful, it functions as below on different shell. If you are using sh shell then use expression as below #!/bin/sh if [ `expr $n  ..

Find two string are not empty

Compare two variables are not empty

While writing shell script, we might be willing to check the argument passed by us it a valid string or not. In order to check the valid string usinf "and" logical operatior we can use below method to check the variables are non empty. #!/bin/bash echo "Enter FirstName" read first echo "Enter Second Name" read  ..

Malware analysis on linux server

Find affected websites on webserver

How to do malware analysis on linux server? How to find virus infected files in linux server? # grep POST /var/log/messages | awk '{ print $7 }' | sort | uniq | while read postfile; do hitcount=$(grep -c ${postfile} /var/log/messages); echo -e "$postfile $hitcount"; done The above script will help  ..

Search string and add in file

Add data in the file

The below script helps you to search a string and add it in to the file, if the string is not found in it. Here in the below script we search for a ipaddress is found on the server or not, it the Ip address is found then the script  ..

Check hardware error hpacucli hpasmcli

Shell script using hpacucli and hpasmcli

How to check hp hardware failure? How to test the hardware is failed or its working? First create a fille called check-hardware-error, after creating the file, copy the below script in to the file and again create one more file called diskwitherror. This script helps you to find the hardware errors  ..

How to find smart array failed disk

HP Array Configuration Utility CLI - hpacucli

The hpacucli utility which is used to add, delete, identify and repair logical and physical disks on the Smart array. Here we have used the hpacucli utility to identify the failure of the disk. #!/bin/bash pd=`hpacucli controller all show config | awk '$10 ~ "Fail" || $11 ~ "Fail"  ..

Replace newline tab space previous line

Move a line with tabe space to previous line

Lets consider a file a called replace-newline.txt. Here our requirement is to move the line to a previous line and get the output to the device number. when the device number is printed in the next line we are unable to list or see the device number. And hence we  ..

Check the response of multiple server

Netcat - Test servers response time

Below is a simple script to test multiple servers responce. Here we are testing whether the port 22 is open or not. for a in $(seq -f "mylin%04g" 411 1 414) do nc -zvw 2 $a 22 done Output: nc: connect to mylin0411 port 22 (tcp) timed out: Operation now in progress nc: connect to mylin412  ..

How to find the length of a string

Basic string manipulation

Shell scripting, basic sting manipulation, how to find the length of a string # ${#my_string} The above will print the length of the sting variable Now lets see a example how to calculate the length of a string? Example: # vi #! /bin/bash str_Length="Welcome to the w3calculator"   ..

String manipulation cut last 10 character

Cut first or Last ten characters

How to cut first and last x characters of each line from a file? Before strating lets assume that we have a file course.txt, In this file we have alphabets and numeric digits. Lets have our goal set to extarct or parse the alphabets and numbers in to different variables. This  ..

Create multiple user same as in another server

Bash script to crete user with password

How to create multiple users same as in another server? Sometime you might get a requirement to creare users same as in another server. At thet time you can use the below script to create users same as in another server. For creating such list you have to copy the specified  ..

How to fetch user details form etc passwd file

Get user details in argument or variable

Many of my friends have asked me how to fetch the user details in each variable or field? They have said its required to use according to their different use. Some had said it was necessary when the need to user name and user details of their server. And other  ..

1 2 3 Next

Tech Bluff