Notice: Undefined index: searchOption in /home/vivekvermani/public_html/UnixCommand/searchUnixCommandsScripts.php on line 140
Unix Commands/Scripts
Share

Search Unix Commands/Scripts


  Help us in improving the repository. Add new commands/scripts through 'Submit Commands/Scripts ' link.





Unix Commands/Scripts - 46 Commands/Scripts found

 Sample 1. Finding any of the multiple texts strings in file

egrep 'Error|Exception|Debug' logfile.txt

   Like      Feedback     egrep   grep log  grep


 Sample 2. Tail log to see only lines containing an error / exception in last 5000 lines

tail -5000 /opt/WebSphere6/AppServer/profiles/Viva/logs/VivaWebClusterMemberPsc9800/SystemOut.log | grep -i "FileNotFoundException"

   Like      Feedback     tail  tail logs  check logs for errors  grep  grep -i  grep ignore case


 Sample 3. Maven Clean install without executing tests

mvn clean install -DskipTests

   Like      Feedback     maven  maven clean install  maven install  maven install without test  maven build


 Sample 4. Do a maven clean install without tests and only display Error lines

mvn clean install -DskipTests | grep "ERROR"

   Like      Feedback     maven  maven install  maven build  maven clean install


Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner
 Sample 5. Get lines containing any of the multiple errors / exceptions in running logs

tail -f /opt/WebSphere/AppServer/profiles/application/logs/SystemOut.log | egrep "(WSWS3713E|WSWS3734W|WSVR0605W|javax.net.ssl.SSLHandshakeException|ThreadMonitor)"

   Like      Feedback     grep  grep logs  tail  tail -f  egrep


 Sample 6. find occurences of a particular error in last n days

find /opt/WebSphere/AppServer/profiles/application/logs/ -iname "SystemOut*" -mtime -7 -exec zgrep "FileNotFoundException" {} ; >> logAnalysis.txt

   Like      Feedback     find  zgrep  -iname  0mtime  >>


 Sample 7. Finding relevant word and excluding irrelevant word

grep xception logfile.txt | grep -v ERROR

   Like      Feedback     grep   grep log  grep -v


 Sample 8. Count a particular word ( error ) in a file

grep -c "Error" logfile.txt

   Like      Feedback     grep   grep log  grep -c


 Sample 9. Finding text within .gz (zipped) file without unzipping them

zgrep -i Error *.gz

   Like      Feedback     grep  zgrep  zgrep -i  grep within zipped file


Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner
 Sample 10. Display the file names that matches the given pattern

grep -l ERROR *.log

   Like      Feedback     grep


 Sample 11. Get Error Snippets in running logs

tail -f /opt/WebSphere/AppServer/profiles/application/logs/SystemOut.log | sed -n '/ERROR/,/EST/p'

   Like      Feedback     grep  grep logs  tail  tail -f  sed  sed -n


 Sample 12. count number of error / exception occurences in a file.

sed -n '/ERROR/,/EST/p' /opt/WebSphere/AppServer/profiles/application/logs/SystemOut.log | grep "LogicBlockSetupException" | wc -l

   Like      Feedback     sed  grep  word count  wc  wc -l


 Sample 13. Report the file size of all files bigger than 2 mb and older than 30 days

find . -type f -size +4096 -atime +30 -exec du -sk '{}' ;

   Like      Feedback     find   du   -exec  find files


 Sample 14. Shell Script for Log4j Log Analysis and exception reporting

#!/bin/ksh

EMAIL_SUBJECT="Exceptions-Log"
EMAIL_TO="xyz@yahoo.com"
`grep "xception" Out.log >> /home/xyz/test1`
`cat /home/xyz/test1 | sed -n 's/.* ([^ ]*xception[^ ]*) .*/1/p' | awk '!x[$0]++' >> /home/xyz/test2`

`rm test3`

while read line
do
lineNum=`sed -n "/$line/,/EST/{=;q;}" Out.log`
let bl=$lineNum-5
let el=$lineNum+15
echo "*************************************************
$line
**************************************************

" >> test3
`sed -n "$bl,$el p" Out.log >> test3`
echo "


" >> test3
done < "/home/xyz/test2"

`cat test3 | /bin/mail -s $EMAIL_SUBJECT $EMAIL_TO`

   Like      Feedback     script  exception reporting script  log4j analysis script  awk


Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner
 Sample 15. Log Monitoring Shell Script - email upon errors

#!/bin/ksh
# Set the config variables

# *************************************************Configuration********************************************************
logFileName="Out.log"
errorList="WSWS3713E|WSWS3734W|WSVR0605W|javax.net.ssl.SSLHandshakeException|ThreadMonitor"
EMAIL_SUBJECT="Application ERROR"
EMAIL_TO="viva@viva.com"
# **********************************************************************************************************************

logFilepath=""

# Set the Log File path

if [ `hostname` = cpc2600 ]
then
logFilePath="/opt/WebSphere6/AppServer/profiles/applicationcpc2600/logs/"
elif [ `hostname` = cpc2601 ]
then
logFilePath="/opt/WebSphere6/AppServer/profiles/applicationcpc2600/logs "
elif [ `hostname` = psc2800 ]
then
logFilePath="/opt/WebSphere6/AppServer/profiles/applicationpsc2800/logs "
elif [ `hostname` = psc2801 ]
then
logFilePath="/opt/WebSphere6/AppServer/profiles/applicationpsc2801/logs "
fi

if [ ! -s $logFilePath/$logFileName ]; then echo "ERROR- Log File Not Found , Please set the config properly"
exit
fi

# Get the first 30 characters of the first line linestart=$(awk 'NR>1{exit} ;1' $logFilePath/$logFileName | cut -c1-30)

lineend=""

# Never ending loop that will parse the Out.log file every 5 sec

while true ; do

# get the last line of file , till which we need to parse the log in this iteration lineend=$(awk 'END{print}'
$logFilePath/$logFileName | cut -c1-30)

# if log file not found , Do nothing and wait for the next iteration if [ ! -s $logFilePath/$logFileName ];
then echo "Log File Not Found .. Waiting for the next iteration ..."
fi

# error checking , in case we dont find the linestart , parse the whole file grep "$linestart"
$logFilePath/$logFileName if [ $? != 0 ] then
echo "cat $logFilePath/$logFileName | egrep $errorList | /usr/sbin/sendmail -s $EMAIL_SUBJECT $EMAIL_TO"
cat $logFilePath/$logFileName | egrep "$errorList" | /usr/sbin/sendmail -s $EMAIL_SUBJECT $EMAIL_TO

else

#parse the log file from linestart to lineend for errors

echo 'awk "/$linestart/,/$lineend/" $logFilePath/$logFileName | egrep "$errorList" | /usr/sbin/sendmail -s $EMAIL_SUBJECT $EMAIL_TO'

awk "/$linestart/,/$lineend/" $logFilePath/$logFileName | egrep "$errorList" | /usr/sbin/sendmail -s $EMAIL_SUBJECT $EMAIL_TO #set the last line as the first line for next iteration linestart=$lineend fi

#set the last line as the first line for next iteration linestart=$lineend

sleep 5

done

   Like      Feedback     script  shell script to report errors in logs


 Sample 16. Shell Scripts for Automating System Monitoring Task

#!/bin/ksh

errorSnippet=''

# ********************************************************Configuration***************************************************************
homeBench='90'
VivaBench='90'
rootBench='90'
appHomeBench='90'
idleBench='95'
logsOldBench='15'
memUsageBench='2500'
avgLoadBench='5'
EMAIL_SUBJECT="Server Health Check Report for $(hostname)"
EMAIL_TO="test@test.com"
# ************************************************************************************************************************************

dfHome=`df | sed -n '/ /home$/s/.* ([0-9][0-9]*)%.*/1/p'`
dfViva=`df | sed -n '/ /apphome/Viva$/s/.* ([0-9][0-9]*)%.*/1/p'`
dfRoot=`df | sed -n '/ /$/s/.* ([0-9][0-9]*)%.*/1/p'`
dfApphome=`df | sed -n '/ /apphome$/s/.* ([0-9][0-9]*)%.*/1/p'`
dfLogsOld=`df | sed -n '/ /localvg-logsOld$/s/.* ([0-9][0-9]*)%.*/1/p'`
memUsage=`sar -q 1 | tail -1 | awk '{ print "" $3}' | sed 's/%//g'`
avgLoad=`uptime | awk -F "$FTEXT" '{ print $2 }' | cut -d, -f3`
iostatIdle=`iostat | awk '{print $5}' | awk 'NR==4' | cut -d '.' -f1`

if [[ $dfHome -gt $homeBench ]] then
errorSnippet="Disk Usage for /home exceedeed the benchmark, Its $dfHome now";
fi
if [[ $dfViva -gt $VivaBench ]] then
errorSnippet="$errorSnippet
Disk Usage for /apphome/Viva exceedeed the benchmark, Its $dfViva now";
fi
if [[ $dfRoot -gt $rootBench ]] then
errorSnippet="$errorSnippet
Disk Usage for /(root) exceedeed the benchmark, Its $dfRoot now";
fi
if [[ $dfRoot -gt $rootBench ]] then
errorSnippet="$errorSnippet
Disk Usage for /(root) exceedeed the benchmark, Its $dfRoot now";
fi
if [[ $dfApphome -gt $appHomeBench ]] then
errorSnippet="$errorSnippet
Disk Usage for /apphome exceedeed the benchmark, Its $dfApphome now";
fi
if [[ $dfLogsOld -gt $logsOldBench ]] then
errorSnippet="$errorSnippet
Disk Usage for logs old exceedeed the benchmark, Its $dfLogsOld now";
fi
if [[ $iostatIdle -gt $idleBench ]] then
errorSnippet="$errorSnippet
Iostat idle exceedeed the benchmark, Its $iostatIdle now";
fi
if [[ $memUsage -gt $memUsageBench ]] then
errorSnippet="$errorSnippet
Memory Usage exceedeed the benchmark, Its $memUsage now";
fi
if [[ $avgLoad -gt $avgLoadBench ]] then
errorSnippet="$errorSnippet
15 minute Average Load exceedeed the benchmark, Its $avgLoad now";
fi

print $errorSnippet
if [ "$errorSnippet" != "" ]; then
`echo errorSnippet | /bin/mail -s $EMAIL_SUBJECT $EMAIL_TO`
fi

   Like      Feedback     script to automate monitoring task  df  sed  sar  tail  awk  iostat  shell script if block  print  /bin/mail


 Sample 17. Shell Script to continuously monitor the state(up/down) of application and send email if its down

while true ; do
curl websiteaddress.com | grep -q "Down for Maintenance"
if [ $? -eq 0 ] ; then
echo "Website is Down" | mail -s "Website is down for maintenance" email@address.com
; fi
sleep 20
done

   Like      Feedback     script to monitor logs  curl  sleep  while loop  if block


 Sample 18. Grant most liberal permissions on the file or directory for all ( self , group and others )

chmod 777 file_name

   Like      Feedback     chmod  change permission   change permission on file  grant most liberal permission  grant most lenient permissions


 Sample 19. Check the Dependency Tree of a maven project

mvn dependency:tree

   Like      Feedback     maven  maven dependency  maven dependency tree


Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner
 Sample 20. Get the Maven Dependency Tree of a project in a separate file

mvn dependency:tree >> file.txt

   Like      Feedback     maven  maven dependency  maven dependency tree


 Sample 21. Get fields matching a particular string using awk

awk '/xception/ { print $1 }' source.txt >> destination.txt

   Like      Feedback     awk


 Sample 22. Print last field using awk

awk { print $NF }

   Like      Feedback     awk


 Sample 23. Count words in a File

grep "Text" file.txt | wc -l

   Like      Feedback     count words in a file  grep  wc  word count


 Sample 24. Get all Errors in a log file for last n days in a seperate error file

find /LogFilesfolder/ -iname "SystemOut*" -mtime -7 -exec zgrep "| ERROR |" {} ; >> logReport.txt

   Like      Feedback     find  -iname  -mtime  zgrep  find errors in log file


Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner
 Sample 25. How to display hidden files in unix
Ashish Singh
ashishde89@gmail.com
ls -a

   Like      Feedback     display hidden files   listing all files   ls


 Sample 26. Get Maven Dependency using command line get

mvn dependency:get -Dartifact=org.springframework:spring-context:5.0.0.BUILD-SNAPSHOT

i.e

mvn dependency:get -Dartifact=<group Id>:<artifact Id>:<version>

   Like      Feedback     Get Maven Dependency using command line get


 Sample 27. Run Jetty server through command line using maven

mvn jetty:run

   Like      Feedback     run jetty


 Sample 28. To see which POM contains missing transitive dependency

run mvn -X

   Like      Feedback     maven  check missing transitive dependency


 Sample 29. Check JAVA_HOME value

echo $JAVA_HOME

   Like      Feedback     JAVA_HOME


Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner
 Sample 30. Set JAVA_HOME

export JAVA_HOME=

   Like      Feedback     JAVA_HOME


 Sample 31. Switch Java version in Ubuntu

sudo update-alternatives --config java

   Like      Feedback     switch java version   sudo update-alternatives


 Sample 32. To know the version of Maven

mvn --version

   Like      Feedback     maven  maven version


 Sample 33. Default Location of Maven Repository

~/m2./repository

   Like      Feedback     maven


 Sample 34. Command to create new project based on archtype

mvn archetype:generate

   Like      Feedback     maven


Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner
 Sample 35. Build Maven project offline

mvn o package

   Like      Feedback     maven


 Sample 36. Command to package maven project

mvn --package

   Like      Feedback     maven


 Sample 37. Get few lines before and after a particular dependency within mvn depedency tree ( 3 lines before and 1 line after )

mvn dependency:tree | grep -B 3 -A 1 log4j-slf4j

   Like      Feedback     


 Sample 38. Count number of lines in a file

wc -l 

   Like      Feedback     


 Sample 39. Recursively create directories

mkdir -p /home/newParentDir/newDir

   Like      Feedback     


Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner
 Sample 40. How to check if Ubuntu i386 or amd64

Run 'lscpu' and check Architecture:

   Like      Feedback     ubuntu i386 or amd64


 Sample 41. Find text within files of a directory recursively

grep -R "<text>"

   Like      Feedback     


 Sample 42. Network information on ubuntu

ifconfig -a

   Like      Feedback     


 Sample 43. Create a new Kafka topic

kafka-topics --zookeeper <host:port> --create --topic <topic_name> --partitions <number_of_partitions> --replication-factor <replication_factor>

Example -

kafka-topics --zookeeper <localhost:80> --create --topic newTopic --partitions 5 --replication-factor 1

   Like      Feedback     


 Sample 44. Clone a repository / checkout project in Git

git clone <repository_url>

   Like      Feedback     


Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner
 Sample 45. Start Zookeeper

Go to Kafka home directory and execute

bin/zookeeper-server-start.sh config/zookeeper.properties

   Like      Feedback     


 Sample 46. Start the Kafka Server

Go to kafka home directory and execute

bin/kafka-server-start.sh config/server.properties

   Like      Feedback     



Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner



comments powered by Disqus