Change the naming convention of the output file

Hi

Currently we have nmon running on our Red hat Linux server.
The ouput file is now coming with the naming convention as "servername_160321_0010.nmon".

The output file naming convention has to be changed as "nmon_servername_daily_2016.03.21_00.00.00"

How can we do it ? Any suggestions please ?

Below is the nmon script scheduled in cron.

[root@servername nmonlog]# crontab -l | grep -i nmon
10 00 * * * /usr/bin/nmon_x86 -ft -s 60 -c 1440 -m /vol/nmonlog > /dev/null 2>&1

Below is the location where the output files are saved :

 [root@servername nmonlog]# pwd
/vol/nmonlog

[root@servername nmonlog]# ls -ltr | grep -i nmon
-rw-r--r-- 1 root root 3820143 Mar 11 00:09 servername_160310_0010.nmon

---------- Post updated at 02:15 AM ---------- Previous update was at 02:08 AM ----------

Below is the script info :

[root@servername nmonlog]# crontab -l | grep -i /vol/nmonlog/Unix_Stat
0,5,10,15,20,25,30,35,40,45,50,55 * * * * /vol/nmonlog/Unix_Statistics.sh >/dev/null 2>&1 #CPU,Memory & Filesystem Monitoring

[root@servername nmonlog]# cat /vol/nmonlog/Unix_Statistics.sh
#! /bin/bash

# Include the Email Ids here
email=abcde@hotmail.com

# Capacity Monitor : Set the thersholds here
cpu_thres=80
swap_thres=60
mem_thres=87
fs_thers=86

# Enter the file system name here to exclude from FS Capacity Monitoring
# Example : fs_exclude="tmp|usr|oracle"
fs_exclude="nfs|tmpfs|cifs"

# Monitoring script output
cpu_op="/vol/cpumonitor"
swap_op="/vol/swapmonitor"
mem_op="/vol/memmonitor"
fs_mon="/vol/fsmonitor"

# *********************************CPU Monitoring script************************************
cpu_usage=$(top -b -n 1  | awk -F'[:,]' '/^Cpu/{sub("\\..*","",$2); print $2}')
if [  $cpu_usage -ge $cpu_thres ]
then
echo -e "<html>" > $cpu_op
echo -e "<body> <pre>" >> $cpu_op
echo -e "<font face=\"Trebuchet MS\" >" >> $cpu_op
echo -e " ********* CPU Utilization on" `hostname` "is above thershold **********" >> $cpu_op
echo -e "\n" >> $cpu_op
echo -e " Current CPU Utilization : $cpu_usage%" >> $cpu_op
echo -e " ***********************************" >> $cpu_op
echo " Here are the top 10 Processes " >> $cpu_op
echo -e " ***********************************" >> $cpu_op
echo -e " </font>" >> $cpu_op
echo -e "\n" >> $cpu_op
echo -e "%CPU COMMAND           PID EUSER \n" >> $cpu_op
ps axo pcpu,comm,pid,euser | sort -nr | grep -v "%" | head -n 10 >> $cpu_op
echo -e "\n" >> $cpu_op
echo -e " <font face=\"Trebuchet MS\" > Note : Please involve respective team.</font>" >> $cpu_op
echo -e "</pre></body>"  >> $cpu_op
mail -s "$(echo -e "ERROR - CPU Utilization on" `hostname` "is above thershold\nContent-Type: text/html")" $email < $cpu_op
fi

# *********************************SWAP Monitoring script************************************
swap_usage=$(free|awk '/^Swap/ {printf "%4.0f\n",$3/$2*100}')
function swap_func(){
SUM=0
OVERALL=0
for DIR in `find /proc/ -maxdepth 1 -type d | egrep "^/proc/[0-9]"` ; do
PID=`echo $DIR | cut -d / -f 3`
PROGNAME=`ps -p $PID -o comm --no-headers`
for SWAP in `grep Swap $DIR/smaps 2>/dev/null| awk '{ print $2 }'`
do
let SUM=$SUM+$SWAP
done
echo "PID=$PID - Swap used: $SUM - ($PROGNAME )"
let OVERALL=$OVERALL+$SUM
SUM=0
done
}
if [ $swap_usage -ge $swap_thres ]
then
echo -e "<html>" > $swap_op
echo -e "<body> <pre>" >> $swap_op
echo -e "<font face=\"Trebuchet MS\" >" >> $swap_op
echo -e " ********* Swap Utilization on" `hostname` "is above thershold **********" >> $swap_op
echo -e "\n" >> $swap_op
echo -e " Current SWAP Utilization : $swap_usage%" >> $swap_op
echo -e " ***********************************" >> $swap_op
echo " Here are the top 10 Processes " >> $swap_op
echo -e " ***********************************" >> $swap_op
echo -e " </font>" >> $swap_op
echo -e "\n" >> $swap_op
swap_func | sort -n -k 10 | head  >>  $swap_op
echo -e "\n" >> $swap_op
echo -e " <font face=\"Trebuchet MS\" > Note : Please involve respective team. </font>" >> $swap_op
echo -e "</pre></body>"  >> $swap_op
mail -s "$(echo -e "ERROR - SWAP Utilization on" `hostname` "is above thershold\nContent-Type: text/html")" $email < $swap_op
fi

# *********************************Memory Monitoring script************************************
mem_total=`cat /proc/meminfo | grep MemTotal: | awk '{print $2}'`
mem_used=`cat /proc/meminfo | grep Active: | awk '{print $2}'`
mem_usage=$[$mem_used * 100 / $mem_total]
if [  $mem_usage -ge $mem_thres ]
then
echo -e "<html>" > $mem_op
echo -e "<body> <pre>" >> $mem_op
echo -e "<font face=\"Trebuchet MS\" >" >> $mem_op
echo -e " ********* Memory Utilization on" `hostname` "is above thershold **********" >> $mem_op
echo -e "\n" >> $mem_op
echo -e " Current Memory Utilization : $mem_usage%" >> $mem_op
echo -e " ***********************************" >> $mem_op
echo " Here are the top 10 Processes " >> $mem_op
echo -e " ***********************************" >> $mem_op
echo -e " </font>" >> $mem_op
echo -e "\n" >> $mem_op
echo -e "%MEM COMMAND           PID EUSER \n" >> $mem_op
ps axo pmem,comm,pid,euser | sort -nr | grep -v "%" | head -n 10 >>  $mem_op
echo -e "\n" >> $mem_op
echo -e " <font face=\"Trebuchet MS\" > Note : Please involve respective team. </font>" >> $mem_op
echo -e "</pre></body>"  >> $mem_op
mail -s "$(echo -e "ERROR - Memory Utilization on" `hostname` "is above thershold\nContent-Type: text/html")" $email < $mem_op
fi

# *********************************FS Capacity monitoring script************************************
fs_func() {
echo -e "<html>" > $fs_mon
echo -e "<body> <pre>" >> $fs_mon
echo -e "<font face=\"Trebuchet MS\" >" >> $fs_mon
echo -e " ********* File System Utilization on" `hostname` "is above thershold **********" >> $fs_mon
echo -e "\n" >> $fs_mon
echo -e " File System $fs Utilization : $fs_usage%" >> $fs_mon
echo -e " *******************************" >> $fs_mon
echo " Here are the Large Files " >> $fs_mon
echo -e " *******************************" >> $fs_mon
echo -e "\n" >> $fs_mon
echo -e "Size : Owner : File Name " >> $fs_mon
find $fs -xdev -size +10000000c -exec ls -lh {} \; | awk '{ print $5 " :" $3 " : "$9 }' | sort -nr | head >>  $fs_mon
echo -e "\n" >> $fs_mon
echo -e " Note : Please involve respective team and take necessary action" >> $fs_mon
echo -e "</pre></body>"  >> $fs_mon
mail -s "$(echo -e "ERROR - File System $fs Utilization on" `hostname` "is above thershold\nContent-Type: text/html")" $email < $fs_mon
sleep 5
}
for fs in ` mount | egrep -v "proc|devpts|sysfs|${fs_exclude}" | awk '{print $3}'`
do
df -h $fs | tail -1 | awk '{print $4}' | grep -i "%" > /dev/null
if [ $? -eq 0 ]
then
fs_usage=`df -h $fs | tail -1 | awk '{print $4}' | grep -i "%"  | sed '$s/.$//'`
        if [ $fs_usage -gt $fs_thers ]
        then
        fs_func
        fi
else
fs_usage=`df -h $fs | tail -1 | awk '{print $5}' | grep -i "%"  | sed '$s/.$//'`
        if [ $fs_usage -gt $fs_thers ]
        then
        fs_func
        fi
fi
done

I am confused, you said below is the script scheduled in cron for nmon:-

[root@servername nmonlog]# crontab -l | grep -i nmon
10 00 * * * /usr/bin/nmon_x86 -ft -s 60 -c 1440 -m /vol/nmonlog > /dev/null 2>&1

But then you posted the code for another script which seems to be not related:-

[root@servername nmonlog]# crontab -l | grep -i /vol/nmonlog/Unix_Stat
0,5,10,15,20,25,30,35,40,45,50,55 * * * * /vol/nmonlog/Unix_Statistics.sh >/dev/null 2>&1 #CPU,Memory & Filesystem Monitoring

Hi

Sorry to confuse you. My Bad.

Below is the script scheduled in cron for nmon:

[root@servername nmonlog]# crontab -l | grep -i nmon
10 00 * * * /usr/bin/nmon_x86 -ft -s 60 -c 1440 -m /vol/nmonlog > /dev/null 2>&1

Please ignore the script named /vol/nmonlog/Unix_Statistics.sh.

The ouput file is now coming with the naming convention as "servername_160321_0010.nmon".

The output file naming convention has to be changed as "nmon_servername_daily_2016.03.21_00.00.00"

How can we do it ? Any suggestions please ?

You might try showing us the source for /usr/bin/nmon_x86 (which presumably creates and names the file whose name you want to change) instead of showing us the source for /vol/nmonlog/Unix_Statistics.sh (which seems to have absolutely nothing to do with this thread).

Hi

Thanks for your reply.

I can't open the file using # cat /usr/bin/nm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uTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTY

However when i type as nmon_x86 under /usr/bin I get the below output :

[root@gb02fpi040arcr7 bin]# pwd
/usr/bin
[root@gb02fpi040arcr7 bin]# nmon_x86
lnmonq14iqqqqqqqqqqqqqqqqqqqqqHostname=gb02fpi040arcRefresh= 2secs qqq08:31.38qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk
x                                                                                                                                                                      x
x  ------------------------------       For help type H or ...                                                                                                         x
x  #    #  #    #   ####   #    #        nmon -?  - hint                                                                                                               x
x  ##   #  ##  ##  #    #  ##   #        nmon -h  - full                                                                                                               x
x  # #  #  # ## #  #    #  # #  #                                                                                                                                      x
x  #  # #  #    #  #    #  #  # #       To start the same way every time                                                                                               x
x  #   ##  #    #  #    #  #   ##        set the NMON ksh variable                                                                                                     x
x  #    #  #    #   ####   #    #                                                                                                                                      x
x  ------------------------------                                                                                                                                      x
x                                                                                                                                                                      x
x  x86 GenuineIntel Intel(R) Xeon(R) CPU E7- 4870  @ 2.40GHz                                                                                                           x
x  x86 MHz=2393.982 bogomips=4787.96                                                                                                                                   x
x  x86 ProcessorChips=0 PhyscalCores=0                                                                                                                                 x
x  x86 Hyperthreads  =0 VirtualCPUs =8                                                                                                                                 x
x                                                                                                                                                                      x
x  Use these keys to toggle statistics on/off:                                                                                                                         x
x     c = CPU        l = CPU Long-term   - = Faster screen updates                                                                                                     x
x     m = Memory     j = Filesystems     + = Slower screen updates                                                                                                     x
x     d = Disks      n = Network         V = Virtual Memory                                                                                                            x
x     r = Resource   N = NFS             v = Verbose hints                                                                                                             x
x     k = kernel     t = Top-processes   . = only busy disks/procs                                                                                                     x
x     h = more options                   q = Quit                                                                                                                      x
xqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqx

It is a binary file, I don't think you can change the output file naming.

As per nmon command manual:-

-f	Specifies that the output is in spreadsheet format. By default, the command takes 288 snapshots of system data 
with an interval of 300 seconds between each snapshot. The name of the output file is in the format of hostname_YYMMDD_HHMM.nmon

Hi Yoda

Thanks for the reply.
So the file comes as hostname_YYMMDD_HHMM.nmon.
After the file is generated and completed for a particular day, can we rename the file from "hostname_YYMMDD_HHMM.nmon" to "nmon_servername_daily_2016.03.21_00.00.00".
Say for example if the data is collected for March 21st, I believe when the day March 21st ends at 23:59 nmon creates a new file for March 22nd. So after the data collection started for March 22nd a script has to be put to rename the file for March 21st. Is there an option to schedule this on crontab so that the file gets renamed automatically everyday.

Do you see a chance to schedule an adaption of this at midnight?

Hi RudiC

Thanks for your reply.

If I want to run the cronjob at 12:15 everyday, will the below do the work for me :

15 12 * * * /bin/mv /vol/nmonlog/servername_160416_0010.nmon /vol/nmonlog/nmon_servername_daily_2016.04.16_00.00.00

But how to make sure that the renaming of the file happens everyday ?

Did you consider and understand the proposal in post#8?

Above will work exactly ONCE unless /vol/nmonlog/servername_160416_0010.nmon is recreated regularly.

Hi RudiC

Thanks for your reply.

To be frank I did not understand the proposal in post#8 since I'm just trained in AIX and new to scripts.

In the below crontab you can see that the sourcefile is of the format like servername_YYDDMM_00**.nmon

Also the destination file is of the format nmon_servername_daily_YYYY.MM.DD_00.00.00

15 12 * * * /bin/mv /vol/nmonlog/servername_160417_0010.nmon /vol/nmonlog/nmon_servername_daily_2016.04.17_00.00.00

I'm not sure how I can use the proposal in post#8 to this issue because I'm not aware of what is [0-9]* and FN.

Can you please advise me.