Shell script to unmonitor the mounts in exception file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script to unmonitor the mounts in exception file
# 1  
Old 01-25-2012
Java Shell script to unmonitor the mounts in exception file

I am trying to write a shell script for monitoring the file system mount.
command I am using will retrieve a output as shown below.
/dev/fsv29 2% /apps/rj/pgl/bslSys
I also need to add exception mounts in a file and I would like script to ignore the mount which I specify.
If I add the following entry in exception file /apps/rj/pgl/bslrys, this should be ignored from my alert and should not print the used space.
Please help with some ideas.

Thanks,
Chandra

Last edited by methyl; 01-26-2012 at 05:25 PM.. Reason: please use code tags
# 2  
Old 01-26-2012
Code:
df -k | awk '{print $1 "        " $5 "       " $6}' | sed '/$1.*/d'

where $1 will be the input input given to that script or the file-name

Last edited by Franklin52; 01-26-2012 at 10:19 AM.. Reason: Please use code tags for code and data samples, thank you
# 3  
Old 01-26-2012
Thank you for your reply. I will be trying around this. It will be really helpful if you can provide me with a snippet where comparing monitoring mounts and exception file mounts.

Thanks,
Chandra

---------- Post updated at 01:21 PM ---------- Previous update was at 01:06 PM ----------

While I was trying to write the code for this,
I have executed,
df -k | tail +2 | egrep -v '/dev/cd[0-9]|/proc'\ | awk '{print $1, $4, $7}' | wc -l and output is 85. After adding the exception file in the sed command, still it shows 85.

Code:
ExceptionFile=/home/apps/Chandra/Exception.txt
MountOut=/home/apps/Chandra/out.txt
df -k | tail +2 | egrep -v '/dev/cd[0-9]|/proc'\ | awk '{print $1, $4, $7}'| sed '/$ExceptionFile.*/d' >> $MountOut

Please help me... Thank you in advance.

Last edited by methyl; 01-26-2012 at 05:28 PM.. Reason: please use code tags
# 4  
Old 01-26-2012
Code:
egrep -v '/dev/cd[0-9]|/proc'\

In this remove the \ you have... Not sure why is it being used...

And the execption file that you have pasted here, are you sure that this is a mount point?
/home/apps/Chandra/Exception.txt. I have never seen a txt file as a mount point. :/

Try giving the mount point that you have given in the 1st example as exception and then give it a try.

Last edited by methyl; 01-26-2012 at 05:28 PM..
# 5  
Old 01-26-2012
Hi,

Thank you for your prompt response. I am trying to put the /apps/PSA/OSAProd
the mount in exception file [ Some text file] and parse that exception mount the command listed above in the while loop.
Code:
#!/bin/ksh
ExceptionFile=/home/apps/Chandra/Exception.txt
MountOut=/home/apps/Chandra/out.txt
while read FSexception
do 

df -k |awk '{print $1, $4, $7}'| sed '/$ExceptionFile.*/d' >> Mount.out

done < $ExceptionFile

......

When parsing I am getting a error saying cannot be parsed. Please help.

Thanks,
Chandra

Last edited by methyl; 01-26-2012 at 05:29 PM.. Reason: please use code tags
# 6  
Old 01-26-2012
Quote:
df -k |awk '{print $1, $4, $7}'| sed '/$ExceptionFile.*/d' >> Mount.out
Okay, without testing or looking too closely at the script a some points arise:

1) In Shell code any $ variable between single quote characters is not expanded. The "sed" command never saw the value of $ExceptionFile (but see item 5 below).
2) When dealing with a variable containing a solidus character "/" a solidus is a very bad choice of character for the delimiter in "sed". The delimiter is easily changed.
3) It would really help to see the output from df -k on your system. There is much variety in the output from this command across unix and Linux systems.
4) If you get an error message, please post the exact error message verbatim.
5) Surely the variable in this script is $FSexception not $ExceptionFile.

Let's try "X" as the delimiter in "sed" and change single quotes to double quotes. Not tested beause I know nothing about what Operating System you have or what Shell this is. Hopefuly your "sed" command is correct (I avoid "sed" wherever possible).
Code:
df -k |awk '{print $1, $4, $7}'| sed "X${FSexception}.*Xd" >> Mount.out


Personally when I write disc space monitoring scripts I make a positive list in a file of the mountpoints and the upper percentage limit. I seed the initial values once from the current position and make my script tell me when things change in a timely manner. The art of writing this sort of script is to never alert more than once a day for a 1% change, but to continue to alert daily .

Last edited by methyl; 01-26-2012 at 06:47 PM.. Reason: typos, layout, errors, clarification, more typos, correct variable name, more, nearly finished, omg that will do, more typos
# 7  
Old 01-26-2012
Hi Methyl,

Thank you for your prompt response. I will play with the sed and let you know the outcome. This one really looks like a complicated one.
I liked the idea that is posted at the bottom and hopefully I can go with. If possible could you shed us with some raw skeleton code that would be really helpful.

Thanks,
Chandra
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need exception handle for this script

Hi This is script to move log files from one location to other which is working fine. I need to add exception handling in this new to scripting. Please help #!/bin/ksh DB=QACCABOP dumppath='/udb/udbpa032/dump_data/offshore/Tran_logs' msg='/udb/udbpa032/utilities/DBAscripts/msg/msg.out'... (4 Replies)
Discussion started by: Mathew_paul
4 Replies

2. Shell Programming and Scripting

Compare 2 files using third file as an exception

Hi All, Is it possible to compare 2 files using the contents of a third file as a guide using a bash script? I have 2 files I want t compare (1 and 2 below) the difference between the two is the first line (a) I want my script to ignore this difference if the difference is stored in file... (5 Replies)
Discussion started by: nwalsh88
5 Replies

3. Shell Programming and Scripting

Monitor logs for exception and if exception come then sent an email

Hi Folks, please advise , I have logs generated on unix machine at location /ops/opt/aaa/bvg.log , now sometimes there come exception in these logs also, so I want to write such a script such that it should continuously monitor these logs and whenever any exception comes that is it try to find... (3 Replies)
Discussion started by: tuntun27272727
3 Replies

4. Shell Programming and Scripting

How to capture the cause of the exception using unix shell?

Hi all, Can u pls guide me in the following requirement, Am capturing the exceptions and the cause of that exception from a log file. i cud capture the exceptions by simple grep ie., with the following command cat logfile | grep "Exceptions" But i couldn't able to capture the cause... (8 Replies)
Discussion started by: vidhyaS
8 Replies

5. Programming

How to get the correct exception file/line.

The below code throws error in the line number 32 where the function is defined. But How to find the line where the function is called. That is I want to throw the error at the line number 43 (as here the function is called). The code is: #include <iostream> #include <string>... (9 Replies)
Discussion started by: SamRoj
9 Replies

6. UNIX for Dummies Questions & Answers

/ file system mounts as read only

I have a Netra T1 server running Solaris 8, It was installed by jump start, it does not have a cdrom drive. Recetly it crashed so I rebooted it from >LOM poweron and it came to run level 3, all file systems listed in /etc/vfstab are mounted, but /dev and / root are not writeable though in... (3 Replies)
Discussion started by: Tirmazi
3 Replies

7. Shell Programming and Scripting

Catch a PL/SQL exception in ksh file

Hi all Im trying to call a PL SQl block from a ksh file like this : sqlplus -s $DB_USERID/$DB_PASSWD@$DB_NAME<<eof whenever SQLERROR exit 1 var varError VARCHAR2(200); exec ODAS_BATCH_JOBS_RETRIEVE.retrieve_user_info(:varError); eof If there is a error then varError will return a... (1 Reply)
Discussion started by: Sam123
1 Replies

8. UNIX for Dummies Questions & Answers

getting help on finding exception in running log file

Hi all, I am trying to write a script for an application server log file where i want to put this script as a cron tab entry and it will check the server log file last 1000/500 line for every fifteen minute. i am using the script like this. count=`tail -n 1000 Trace.log | grep -c... (1 Reply)
Discussion started by: senthilkumar_ak
1 Replies

9. Shell Programming and Scripting

Exception-handling in Shell programs

Hi all, I am writing a set of scripts and some of these are nested within others. I want to be able to execute a single high-level script at the command-line, which in turn may invoke other scripts as required, and when a failure occurs in any of the nested scripts, I want to be able to track... (2 Replies)
Discussion started by: chaitu_inmage
2 Replies

10. UNIX Desktop Questions & Answers

file attributes and exception

hi, I want to know the date the file was created or modified. I can do this using ls, ll -ltr etc... I want to do this in a function (so If the file date is older then a week I can report it), is there a way? another thing... In sql function, I can catch exceptions, is there a way to do this... (1 Reply)
Discussion started by: krem
1 Replies
Login or Register to Ask a Question