Wednesday, July 21, 2021

File System size monitoring with shell script

 Schedule this with crontab to run periodically.

#!/bin/sh

#Shell script to monitor the disk space

DBA_EMAIL="email@email.com"
ALERT_THRESHOLD=75
DATE=`date '+%a %b %e %I:%M %p' `
SERVER=`hostname`
df -Pkh | grep -v Filesystem | grep -v tmpfs | grep -v cdrom | grep -v run| awk '{ print $5 " " $6 }' |
while read output;
do
USED_PERCENTAGE=`(echo $output | awk '{ print $1}' | cut -d'%' -f1 )`
PARTITION=`(echo $output | awk '{ print $2 }' )`
if [ $USED_PERCENTAGE -ge $ALERT_THRESHOLD ]; then
echo "Kindly check file-system  \"$PARTITION ($USED_PERCENTAGE %)\" full on $SERVER on $DATE" |
mail -s "Production ALERT_THRESHOLD:- Disk Space Warning \"$PARTITION ($USED_PERCENTAGE %)\" full on $SERVER " $DBA_EMAIL
fi
done

***

Wednesday, July 14, 2021

DSBulk Operation failed with Java heap size

 Example: Operation LOAD_20200714-055402-943439 failed unexpectedly: Java heap space

Increase the Java heap allocation for DSBulk by

export DSBULK_JAVA_OPTS="$DSBULK_JAVA_OPTS -Xmx16G"


Reference: https://docs.datastax.com/en/dsbulk/doc/dsbulk/install/dsbulkInstall.html#Post-installrequirementsandrecommendations

***

Wednesday, July 7, 2021

Install software in Linux with shell scripting

 Below are the examples of installing 'vim' and 'wget' with shell script

vim installation:

Shell script to install software in Linux.
#!/bin/bash
vim --version 1>/dev/null 2>&1
if [[ $? -eq 0 ]]
then
	echo "VIM is already installed"
else
	sudo yum install vim -yum
fi

wget installation:

wget --version 1>/dev/null 2>&1
if [[ $? -eq 0 ]]
then
	echo "WGET is already installed"
else
	sudo yum install wget -yum
fi

***

Thursday, July 1, 2021

To remove or delete files in Linux when there are more

When there are too many files to delete in a Linux folder, its hard to delete as "rm" won't work directly.

Below is the error message, we get.

$ rm -rf "*.csv"
-bash: /usr/bin/rm: Argument list too long

Resolution:
$ find . -name '*.csv' | xargs rm -v4

This will remove all files which have ".csv" as extension and give verbose output of what it is doing while removing.

***

Datastax OpsCenter alerts action codes

 Below is the list of action codes of Datastax Opscenter for reference:

    COMPACTION = 0
    CLEANUP = 1
    REPAIR = 2
    FLUSH = 3
    DRAIN = 4
    DECOMMISSION = 5
    MOVE = 6
    BOOTSTRAP = 7
    STREAMING = 8
    MESSAGES_DROPPED = 9
    GARBAGE_COLLECTION = 10
    CASSANDRA_EXCEPTION = 11
    SNAPSHOT = 12
    NODE_DOWN = 13
    NODE_UP = 14
    NODE_LEFT = 15
    NODE_JOIN = 16
    NODE_MOVE = 17
    OPSC_UP = 18
    OPSC_DOWN = 19
    GC = 20
    REBALANCE = 21
    ALERT = 22
    BACKUP = 23
    CLEAR_SNAPSHOT = 24
    MISC = 25
    NODE_STARTED = 26
    NODE_STOPPED = 27
    NODE_RESTARTED = 28
    PROVISION_CLUSTER = 29
    ROLLING_RESTART = 30
    REMOVE_TOKEN = 31
    ASSASSINATE = 32
    SNAPSHOT_RESTORE = 33
    SET_CONF = 34
    SET_DSE_TYPE = 35
    REPAIR_SERVICE = 36
    BEST_PRACTICE = 37
    CREATE_USER = 38
    UPDATE_USER = 39
    DELETE_USER = 40
    CREATE_ROLE = 41
    UPDATE_ROLE = 42
    DELETE_ROLE = 43
    FAILOVER_DISABLED = 44
    KMIP_ERROR = 46
    TRACE_QUERY = 47
    ALERT_FAILURE = 48
    SYNC_SNAPSHOT = 49

***

Auditing file changes in Linux

Enable the audit log for directory /var/log/cassandra on a Cassandra node

Add below rule for the directory to audit, here we are search for deleted files under /var/log/cassandra directory.

sudo vi /etc/audit/rules.d/audit.rules

-a always,exit -F dir=/var/log/cassandra -S unlink -S unlinkat -S rename -S renameat -S rmdir -k delete_var

sudo service auditd restart

Verify rules: sudo auditctl -l

Verify: sudo ausearch -k delete_var

***