LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Enterprise (https://www.linuxquestions.org/questions/linux-enterprise-47/)
-   -   cpu, mem, ps output to file script (https://www.linuxquestions.org/questions/linux-enterprise-47/cpu-mem-ps-output-to-file-script-481659/)

beeblequix 09-08-2006 02:19 PM

cpu, mem, ps output to file script
 
howdy folks,

I wrote a small script that takes the output from several normal linux commands and writes them to a unique filename.

What do you think?

#!/bin/bash
# simple script to output various stats into unique file log
# Lord Beeblequix 09/08/2006
# yes, the name is inspired by Counterstrike

uniquedate=`date +%m%d%Y%H%M`
statfile="$HOME/stats_${uniquedate}.log"

# *********************************
# snapshot of cpu cycles using top
# *********************************
echo "Running 2x iterations of top"
top -b -n2 -C > $statfile
echo

# *********************************
# snapshot of all running processes
# *********************************
echo "ps in BSD format."
ps -aux >> $statfile
echo

# *********************************
# snapshot of memory usage
# *********************************
echo "Memory stats in MB from free -m"
free -m >> $statfile
echo
echo "Now, go get a bearclaw."

nilleso 09-08-2006 02:44 PM

__________________________________________

nilleso 09-08-2006 02:45 PM

I think it's super :D

Why don`t ya add some disk info like:
Code:

echo "----- Top 5 File Systems by Percentage "
echo
df -k | awk '{print $5,$6 }' | grep -v capacity | \
sort -r -n -t 2 | head -5
echo
echo "----- Top 5 File Systems by Least Kilobytes free"
echo
df -k | awk '{print $4,"kb    ",$6 }' | grep -vi mounted | \
grep -v fd|grep -v mnttab|grep -v proc | sort -n -t 2 | head -5
echo
hostnm=`hostname`
dfbinary="/bin/df -kl"
disksum=`$dfbinary | grep dev | awk '{t += $2; u += $3} \
        END { printf("%d MB, %d MB used",t/1024,u/1024) }'`
echo "Diskspace available and used for $hostnm"
echo $hostnm $disksum

cheers:)

beeblequix 09-08-2006 03:08 PM

good idea. thanks.


All times are GMT -5. The time now is 04:20 PM.