Linux Troubleshooting – fsck on boot

/dev/xvda1: UNEXPECTED INCONSISTENCY; RUN fsck MANUALLY.
     (i.e, without -a or -p options)
Checking drive /dev/xvda1: 51% (stage 1/5, 157/214)
fsck died wih exit status 4
                                                    [fail]
* An automatic file system check (fsck) of the root filesystem failed.
A manual fsck must be performed, then the system restarted.
The fsck should be performed in maintenance mode with the root filesystem mounted in read-only mode.
* The root filesystem is currently mounted in read-only mode.
A maintenance shell will now be started.
After performing system maintenance, press CONTROL-D
to terminate the maintenance shell and restart the system.
Give root password for maintenance 
(or type Control-D to continue):_

In this case /dev/sda2 is my root partition and since it was mounted even in maintenance mode,
attempting to run fsck on it would output:

fsck.ext4 /dev/xvda1
e2fsck 1.42.7 (21-Jan-2013)
/dev/xvda1 is mounted.
e2fsck: Cannot continue, aborting.

Advertisements

Simple Bash scripts

Find Disk Space

#!/bin/bash

USAGE=$(df -PTh|egrep -iw "ext4|ext3|xfs|gfs|gfs2|btrfs"|sort -k6n | tail -n 1 | awk '{print $6}'| sed 's/%//')

case $USAGE in
8*)
echo "Disk Space Critical"
;;
9*)
echo "Disk Space Warning"
;;
*)
echo "Disk Space fine"
;;
esac

Find CPU LOAD

#!/bin/bash

#load=`cat /proc/loadavg | awk '{print $3}'`
#echo $load
load=$(cat /proc/loadavg | awk '{print $3}')
echo $load
if (( $(echo "$load < 10" | bc -l ) ))
then
echo "less load"
fi

Find the hostname and date in same line (two linux command in same line)

for s in server1.abc.com ; do ssh -l root ${s} "echo -en \"\$(hostname -f)\t\" ; date"; done

Script to get filename list from a file

#!/bin/bash
file=”richard_morgan.txt”
while IFS= read -r line
do
cp “/home/users/user1/.maildir/$line” /home/users/user2/.maildir/.JPM/cur/
done <“$file”

Script to get old date from current date

#!/bin/bash

TYPE="DATABASE"
 DAYS="7"

#GET CURRENT DATE
 CURRENTDATE="$(date +%Y%m%d )"
 OLDDATE="$(date "+%Y%m%d" -d "$DAYS days ago")"
 echo $OLDDATE

Script to check a process is running

METHOD 1

#!/bin/bash
 ps -ef | grep [A]LServiceDue | cut -f 1 > /opt/scripts/check_AL_ServiceDue.log
 FileRead="$(wc -l < /opt/ezhil_scripts/check_AL_ServiceDue.log)"
if [ $FileRead -eq 0 ]
then
echo "count is 0 ====> ALServiceDueAlert not running"

# Start DataAsServiceJob
 /bin/java -Dhttps.proxyHost=10.1.1.1 -Dhttps.proxySet=true -Dhttps.proxyPort=3128 -Xms512m -Xmx2g -jar /opt/SNAPSHOT.jar &
 else [ $FileRead -gt 0 ]
 echo "Program Running Successfully"
 fi

METHOD 2

#!/bin/bash
 ps -ef | grep java | grep alusrdev |grep gcuat | grep web-0.0.1-SNAPSHOT.jar
 if [ $? -eq 0 ]; then
 ps -ef | grep java | grep alusrdev |grep gcuat | grep web-0.0.1-SNAPSHOT.jar | awk '{print $2}'| xargs kill -9
 else
 echo No existing process
 fi