summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgrothedev <grothedev@gmail.com>2024-06-17 13:26:56 -0500
committergrothedev <grothedev@gmail.com>2024-06-17 13:43:08 -0500
commit702ad77194129290cfd4d2b45fcf15f862a84750 (patch)
tree4872f00743dca0a66bd01485204f67758c225d77
parent5a6bec76248cdc6400cc6c7fdf5fcebf84ff57c4 (diff)
better and faster finding most recently modified files recursively. also a process monitoring script i used to keep track of when vscode-server started acting up
-rwxr-xr-xmovetextfiles.sh18
-rwxr-xr-xprocinfo.sh1
-rwxr-xr-xprocwatch.sh34
-rwxr-xr-xrecentlymodifiedfilesrec.sh36
4 files changed, 89 insertions, 0 deletions
diff --git a/movetextfiles.sh b/movetextfiles.sh
new file mode 100755
index 0000000..132fe14
--- /dev/null
+++ b/movetextfiles.sh
@@ -0,0 +1,18 @@
+#!/bin/bash
+
+if [[ -z $1 ]]; then
+ echo "in what folder do you want to search for text files to move into a subfolder?"
+ exit 0
+fi
+
+dst='./textfiles/'
+if [[ ${2} ]]; then
+ dst=${2}
+fi
+
+#check that mime type is text. if so, move to 'text' folder
+for f in `find ${1} -maxdepth 1 -type f`; do
+ if [[ `file -i ${f} | grep 'text/'` ]]; then
+ mv ${f} ${dst}
+ fi
+done
diff --git a/procinfo.sh b/procinfo.sh
new file mode 100755
index 0000000..7766c9f
--- /dev/null
+++ b/procinfo.sh
@@ -0,0 +1 @@
+ps -eo command,pcpu,pmem,rss --sort=-pmem
diff --git a/procwatch.sh b/procwatch.sh
new file mode 100755
index 0000000..0088b3f
--- /dev/null
+++ b/procwatch.sh
@@ -0,0 +1,34 @@
+#!/bin/bash
+
+# Set the logging configuration
+log_file="process_monitor.log"
+
+# Set the CPU and memory usage thresholds
+cpu_threshold=50 # Percentage
+mem_threshold=500 # Megabytes
+
+while true; do
+ # Get the list of running processes
+ processes=$(ps -eo pid,pcpu,rss,comm --sort=-pcpu | grep -v "^ PID")
+# echo $processes
+
+ # Loop through the processes
+ while read -r process_info; do
+ echo "PROCESS! "${process_info}
+ echo ""
+ # Extract the process information
+ pid=$(echo "$process_info" | awk '{print $1}')
+ name=$(echo "$process_info" | awk '{print $4}')
+ cpu_percent=$(echo "$process_info" | awk '{print $2}')
+ mem_usage=$(echo "$process_info" | awk '{print $3}')
+ mem_usage=$((mem_usage / 1024)) # Convert to Megabytes
+
+ # Check if the process exceeds the CPU or memory usage threshold
+ if (( $(echo "$cpu_percent > $cpu_threshold" | bc -l) )) || (( mem_usage > mem_threshold )); then
+ echo "$(date) - Process '$name' (PID: $pid) has exceeded the threshold: CPU usage: ${cpu_percent}%, Memory usage: ${mem_usage} MB" # >> "$log_file"
+ fi
+ done <<< "$processes"
+
+ # Wait for 5 seconds before checking again
+ sleep 5
+done
diff --git a/recentlymodifiedfilesrec.sh b/recentlymodifiedfilesrec.sh
new file mode 100755
index 0000000..2ba7f80
--- /dev/null
+++ b/recentlymodifiedfilesrec.sh
@@ -0,0 +1,36 @@
+#!/bin/bash
+#this is a faster implementation than the other script (mostrecentrecursively.sh)
+
+d='.'
+declare -a exclude #array of files to exclude from results
+
+if [[ $1 ]]; then
+ d=$1
+ shift
+fi
+
+while [[ $1 ]]; do
+ exclude+=(${1})
+ shift
+done
+
+#set up the exclusion options for the find command
+find_cmd_excl=""
+for s in ${exclude[@]}; do
+ find_cmd_excl+=" -not -wholename \"*${s}*\""
+done
+find_cmd="find ${d} -type f ${find_cmd_excl} -printf '%T@ %p\n' | sort -n | tail -n 10 | cut -f2- -d' '"
+echo $find_cmd
+ts=`date +%s_%N`
+eval $find_cmd
+te=`date +%s_%N`
+
+tss=`echo ${ts} | cut -d'_' -f 1`
+tsn=`echo ${ts} | cut -d'_' -f 2`
+tes=`echo ${te} | cut -d'_' -f 1`
+ten=`echo ${te} | cut -d'_' -f 2`
+echo "${tss}, ${tsn}, ${tes}, ${ten}"
+tst=$((tss*1000000000 + tsn))
+tet=$((tes*1000000000 + ten))
+dur=$((tet-tst))
+echo "duration: ${dur} ns"