Change the naming convention of the output file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Change the naming convention of the output file
# 1  
Old 04-11-2016
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.
Code:
[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 :

Code:
 [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 :

Code:
[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

Code:
[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


Last edited by RudiC; 04-11-2016 at 04:13 AM.. Reason: Corrected position of code tags.
# 2  
Old 04-12-2016
I am confused, you said below is the script scheduled in cron for nmon:-
Code:
[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:-
Code:
[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

# 3  
Old 04-15-2016
output file naming convention has to be changed

Hi

Sorry to confuse you. My Bad.

Below is the script scheduled in cron for nmon:
Code:
[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 ?
# 4  
Old 04-15-2016
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).
# 5  
Old 04-15-2016
Hi

Thanks for your reply.

I can't open the file using # cat /usr/bin/nmon_x86 in putty.

Below is the output I get when I try to cat the file :

Code:
PuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTY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YPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTYPuTTY

However when i type as nmon_x86 under /usr/bin I get the below output :
Code:
[root@gb02fpi040arcr7 bin]# pwd
/usr/bin
[root@gb02fpi040arcr7 bin]# nmon_x86

Code:
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

# 6  
Old 04-15-2016
It is a binary file, I don't think you can change the output file naming.

As per nmon command manual:-
Code:
-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

# 7  
Old 04-18-2016
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Naming output files based on variable parameters and input filenames

Hello, I have a series of files in sub-directories that I want to loop through, process and name according to the input filename and the various parameters I'm using to process the files. I have a number of each, for example file names like AG005574, AG004788, AG003854 and parameter values like... (2 Replies)
Discussion started by: bdeads
2 Replies

2. Red Hat

File System Naming Convention

Hi, I am installing a new RHEL 5 application server containing JBOSS along with other specific 3rd party applications. I know that this usually gets installed in /opt but I was thinking of installing these on a new separtate lv / file system instead. i.e. /<my_new_FS_name> rather than... (6 Replies)
Discussion started by: Duffs22
6 Replies

3. UNIX for Dummies Questions & Answers

Check file name against convention

I need this script to check if the first 3 letters of the file name are capital. find . -type f -name *001.dpx -exec find {} ! -name ???_???_???_v??.??????.dpx \; >> ./Bad_FileNames.txt Currently it finds the first frame of the sequence and tests that against the naming convention. It works... (6 Replies)
Discussion started by: scribling
6 Replies

4. Fedora

Basic question regarding rpm naming convention.

Hi Guys, Where would i find the list of distribution codes. For example. samba-32bit-3.4.2 -1.1.3.1.x8664.rpm In above rpm file it is indicated that its release is 1.1.3.1 . The rpm is meant to be run for opensuse. Where would i get the linking of release number and distribution. ... (2 Replies)
Discussion started by: pinga123
2 Replies

5. Shell Programming and Scripting

Concatenate files to one file with naming convention

Hi , i have below files in wrk folder. file names are 1102090001.CLT 1102090003.CLT 1102100019.CLT 1102100020.CLT the above files are concatenate to one file but that concatenate file name must be same naming convention. (date +%y%m%d)and 0001 count. example : concatenate file... (9 Replies)
Discussion started by: krbala1985
9 Replies

6. Hardware

Motherboards naming convention

For the selection of motherboards, is there any naming convention in the type numbers? There is usually a brand name and sometimes a version name, but more essential details like form factor, SATA speed and maximum amount of RAM is never given. Is there a reason for that? Is there any background... (2 Replies)
Discussion started by: figaro
2 Replies

7. Shell Programming and Scripting

Naming convention script

OK, so a quick background: I am a sys admin for a 1:1 deployment in academia with Macbooks, totaling around 6,000. Macbooks get shifted around from building to building and go to and from the repair center if hardware repair is needed. Often, some machines will get moved from one building to... (8 Replies)
Discussion started by: tlarkin
8 Replies

8. Shell Programming and Scripting

Change file output format

I have a file which has following contents usmtnz-dinfsi19 62 61 18400 18800 99.7 usmtnz-dinfsi19 62 61 18400 18800 99.7 i want the o/p to be like date (7 Replies)
Discussion started by: fugitive
7 Replies

9. Emergency UNIX and Linux Support

Read file and change a 0 to a 1 in output

<key>ExcludeSimpleHostnames</key> <integer>0</integer> <key>FTPPassive</key> Need simple command that will change the 0 to a 1 in this file when I grep it, but only for this integer key directly after the ExcludeSimpleHostnames key. I got this output code... (8 Replies)
Discussion started by: glev2005
8 Replies

10. UNIX Desktop Questions & Answers

Naming convention for Libraries..

Hi All, I need to know standard naming convention for Unix libraries (including all flavours of unix)..As I have gone through some sites and found out The UNIX convention for naming of libraries is lib<name>.so.<major>.<minor>.<revision> so is it statndard . also does it change... (0 Replies)
Discussion started by: rkshukla14
0 Replies
Login or Register to Ask a Question