Sponsored Content
Top Forums Shell Programming and Scripting Notify as soon as an error is encountered in a script Post 302984236 by Don Cragun on Saturday 22nd of October 2016 11:17:46 PM
Old 10-23-2016
Quote:
Originally Posted by mbak
Hi,

The script below works okay and emails me the log in the end once the script completes but what I'm trying to do is to also notify me via an email as soon as the script encounters any error whatsoever.


Code:
cat test.list
hdisk0         00a6351a2c832da1                    rootvg          active
hdisk1         00a6351a2c832f66                    rootvg          active
hdisk2         00a6351a2c833311                    optvg           active
hdisk3         00a6351a2c8334a5                    optvg           active
hdisk4         00a6351a2cbf3049                    optvg           active
##########################################
cat NEWDISK.lst
rootvg hdisk6 hdisk0
rootvg hdisk7 hdisk1
optvg  hdisk8 hdisk2
optvg  hdisk9 hdisk3
optvg  hdisk10 hdisk4

Code:
cat replacepv.sh
#!/bin/ksh
cat test.list | while read DISK1 PVID VG
 do
  if grep $DISK1 NEWDISK.list | read  VG DISK2
   then
        echo "Replace DISK $DISK1 to $DISK2........" | tee -a LOG.OUT
        sudo  replacepv $DISK1 $DISK2  | tee -a ERR.OUT
     fi
 done
echo "" | tee -a LOG.OUT
echo "" | tee -a ERR.OUT

mail -s "Disk replaced" user@abc.com< LOG.OUT

Thanks,
mbak
Please be more explicit about what errors you want to cause to send an additional email.

Is it an error that you are invoking replacepv with three operands while the man page only specifies what happen when two operands are given? For example, when you read the 1st line from test.list (setting DISK1 to hdisk0), you will be running the command:
Code:
        sudo  replacepv hdisk0 hdisk6 hdisk0  | tee -a ERR.OUT

Is that an error? Does the above replacepv command complete successfully? Does it print any diagnostic messages? Does it write anything into ERR.OUT?

Is it an error when your grep command matches two or more lines and you only process one of those lines? For example, when you read the 2nd line from test.list, the command:
Code:
        grep hdisk1 NEWDISK.list

will match the following lines from NEWDISK.list:
Code:
rootvg hdisk7 hdisk1
optvg  hdisk10 hdisk4

but you only read the 1st matched line and run the command:
Code:
        sudo  replacepv hdisk1 hdisk7 hdisk1

ignoring the 2nd line and not running the command:
Code:
        sudo  replacepv hdisk1 hdisk10 hdisk4

Is that an error? Or, is it an error that the above grep command matched hdisk10 on the 2nd line when it should not match hdisk10 when I assume you only wanted exact matches for the word hdisk1?

Or, did you just want to mail any lines appended to ERR.OUT (even though ERR.OUT does not contain any diagnostic messages that might have been written to explain what errors had been detected)?
 

10 More Discussions You Might Find Interesting

1. UNIX Benchmarks

Encountered error!

I used this on an AIX machine and encountered the following error. $ ls -l total 600 -rwxrwxrwx 1 e26936 dba 1491 Feb 07 1992 MANIFEST -rwxrwxrwx 1 e26936 dba 8148 Apr 05 1992 Makefile -rwxrwxrwx 1 e26936 dba 4852 Sep 06 2003 README -rwxrwxrwx... (0 Replies)
Discussion started by: puspendu
0 Replies

2. Shell Programming and Scripting

How the first script should notify in case there is no response from second

Hi Experts, I am trying to write a ksh script that it should notify in case there is no response from the other script. I mean to say that I got a.sh and b.sh the execution of b.sh depends on a.sh, so if there is no response from a.sh, b.sh should notify me about the same. Thanks in Advance (4 Replies)
Discussion started by: rajusa10
4 Replies

3. Shell Programming and Scripting

Using mail command to notify the status of script

Can someone please help me with this script, I'm trying to create system backup on AIX, for this I want to first mount the filesystem if it is not mounted, then create the backup and unmount the filesystem but I'm having problem while using the mail command to notify the status of filesystem... (9 Replies)
Discussion started by: mbak
9 Replies

4. Shell Programming and Scripting

How to write a shell script to notify when certain texts appear in a file?

I have a server and occasionally the file mysqld.log would show something like /usr/libexec/mysqld: Disk is full writing './example_com_-_wordpress/wp_statpress.MYD' (Errcode: 122). Waiting for someone to free space... Retry in 60 secs How do I write a simple shell script to check mysqld.log... (1 Reply)
Discussion started by: acider
1 Replies

5. Shell Programming and Scripting

notify-send does not notify real time

Hi, I am having a little trouble getting notify-send to work the way I would like it to. I am using ubuntu - karmic koala 2.6.31-19-generic #56-Ubuntu SMP So here's the problem run the following commands one after the other. notify-send -i info -t 100000 -- "Hi" "world" & notify-send -i... (3 Replies)
Discussion started by: linuxpenguin
3 Replies

6. AIX

Error encountered in creating a filesystem

Hi experts, Need help on the below error please. I am creating Filesystem and it fails with the below errors :( Command: failed stdout: yes stderr: no Before command completion, additional instructions may appear below. 0518-506 odmget: Cannot open object class PdAt ... (10 Replies)
Discussion started by: EngnrRG
10 Replies

7. Shell Programming and Scripting

Bash script to notify when ever any files are changed

Hi the following script let sthe user know whenevr any file is changed inserted or deleted in file system. but i am getting following error while running bash script ## LINUX SYSTEM FILE ARCHIVE NOTIFY ## if ; then echo "Usage '$0 folder waitseconds' " ; exit 1; fi if ; then echo "Folder... (1 Reply)
Discussion started by: programmingzeal
1 Replies

8. Shell Programming and Scripting

awk - continue when encountered division error

Hello, How can I add a logic to awk to tell it to print 0 when encountering a division by zero attempted? Below is the code. Everything in the code works fine except the piece that I want to calculate read/write IO size. I take the kbr / rs and kbw / ws. There are times when the iostat data... (5 Replies)
Discussion started by: tommyd
5 Replies

9. Shell Programming and Scripting

Shell script to notify of service down

Hi All I am trying to write a shell script that will notify via email if a particular service is down. What I have so far is a script in cron like his: #!/bin/sh cd /usr/jdk/instances/jdk1.6.0/bin/sparcv9 jps -m And the output of the above is 81529 Jps 52988 TaskControllerService... (5 Replies)
Discussion started by: fretagi
5 Replies

10. UNIX for Advanced & Expert Users

Problem with shell script while spaces encountered in directory names

Hi, I am having issues with the jar -tf command when I put in the shell script. The command runs fine from the command line as shown below. # jar -tf "./VirtualBox Dropped Files/2016-04-17T20:58:49.129139000Z/hive-exec-0.8.1.jar" But when I put in a shell script(shown below) and the... (10 Replies)
Discussion started by: vinoo128
10 Replies
All times are GMT -4. The time now is 05:16 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy