Search Results for: awk

25+ Awesome Linux/Unix command chaining examples

Command chaining is a concept to execute two or more commands in one execution to increase. productivity Reduce system resource usage (In some cases) Short and sweet codes. These are supported by almost every shell we know. Today we will learn how to use different command chaining operators available for us in an easy way. Command chaining operators & --Sends process background (so we can run multiple process parallel) ; --Run multiple commands in one run, sequentially. --To type larger command in multiple lines && --Logical AND operator || --Logical OR operator ! -NOT operator ( Thanks for mgd@interbaun.com...

Read More

Linux shell script to monitor CPU usage and send an e-mail

This is a small shell script to monitor CPU usage. IF the cpu usage is more than 75% then send an e-mail to respective teams. #!/bin/bash #Author: Surendra Kumar Anne #Purpose: To monitor the CPU usage #Date:2012-04-13 SUBJECT="WARNING CPU USAGE HIGH" TO=yourteam@companiesemailcom MESSAGE=/tmp/messages echo "#######################" > $MESSAGE echo "CPU statistics as follows.." >> $MESSAGE mpstat >> $MESSAGE echo "#######################" >> $MESSAGE CPU_USAGE=$(top -b -n1 | awk '/^Cpu/ {print $2}' | cut -d. -f1) [ $CPU_USAGE -gt 75 ] && mail -s "$SUBJECT" "$TO" < $MESSAGE   Once the above script is written and given execute permissions keep this script in crontab which runs for every 1min or 5mins. 0-59 * * * *  bash...

Read More

Learn SED with examples

This is our second post on SED, which is a Stream EDitor. Please find our Previous post on SED. You can find our other posts on RegExp basics and extended. Line number operator ( , and = switch) We can search in a file according to line numbers. Example13: Suppose I want to search in only 3rd line and then replace the term in that line alone. sed ‘3 s/Surendra/bca/’ tem.txt Example14:Search from 1st line to 4th line and replace that term. sed ‘1,4 s/Surendra/bca/’ tem.txt Example15:Search for a term from 3rd line to 5th line and replace it only between these lines. sed ‘3,5 s/Surendra/bca/’ tem.txt Example16:Search for a term from 2nd line to the end of the file and replace it with a term. sed ‘2,$ s/Surendra/bca/’ tem.txt Example17:How about combining two-line in to a single line. The below script will use N option which try to merge two, two lines in to single line and it will keep newline character in the combine line. sed ‘N’ tem.txt The output will not differ to the input file. If you want to really see the difference you have to use search and replace for n to some space or tab(t) sed ‘N;s/n/ /’ tem.txt Output: surendra audi kumar nudi mouni surendra baby dudy Note:The above command is not used much of the time and I used this example...

Read More

Over 16,000 readers, Get fresh content from “The Linux juggernaut”

Email Subscribe

ABOUT ME..!

My photo
My name is Surendra Kumar Anne. I hail from Vijayawada which is cultural capital of south Indian state of Andhra Pradesh. I am a Linux evangelist who believes in Hard work, A down to earth person, Likes to share knowledge with others, Loves dogs, Likes photography. At present I work at Bank of America as Sr. Analyst Systems and Administration. You can contact me at surendra (@) linuxnix dot com.