Solved

Shell Script with e-mail...

Posted on 2000-03-08
7
197 Views
Last Modified: 2011-09-20
I'm new to shell scripting, so please bear with me.  All that I want to do is cat a file that is known to either contain OK or FAIL, and if FAIL read a line from another file (grep for DEAD on that), and then (still if FAIL) take this second file's line and e-mail it.

I must assume that this would be "fairly" straightforward to someone who knows shell scripting.  Thanks!
0
Comment
Question by:Nietzsche
  • 4
  • 2
7 Comments
 
LVL 3

Expert Comment

by:jyu_88
ID: 2598997
assume file1 and file2, in a regular unix, linux, enviromenta

----cut--------cut----------
# /bin/sh

# backtick here, not single quote
status=`cat file1`

if [ "EMPTY$status" = "EMPTY" ]
then
    echo "nothing in file1????"
    exit 1
fi

if [ ${status} = "FAIL" ]
then
  grep "DEAD" file2 | mail -s "line from file2 when FAIL in file1" 2>/dev/null
fi
exit 0
------cut---cut-----
0
 

Author Comment

by:Nietzsche
ID: 2601919
When I run this (named runthis), I get the following:

../runthis:[EMPTYcat file1: command not found

../runthis:[cat: command not found

Any suggestions?
0
 

Author Comment

by:Nietzsche
ID: 2601926
..that was with no whitespace between the brackets and their contents ... if I put a space there, then I get
../runthis: [: too many arguments.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Accepted Solution

by:
jyu_88 earned 75 total points
ID: 2605444
# backtick here, not single quote
status=`cat file1`

are you sure you have backtick not single quote there?   FYI, backtick is the one sharing the same key with ~.

I've run the exact program on my Linux box without problem. So, I don't expect problem. Ruh, sorry, the first line should read like
#! /bin/sh
instead of
# /bin/sh
0
 
LVL 5

Expert Comment

by:ecw
ID: 2618647
grep -q FAIL file1 && grep DEAD file2 | mail -s "DEAD in file2" nietzsche
0
 

Author Comment

by:Nietzsche
ID: 2620690
Adjusted points from 50 to 75
0
 

Author Comment

by:Nietzsche
ID: 2620691
EXCELLENT!  As you said before, the "`" is indeed a backtick.  It's running beautifully - I'm using it to cat out /dev/rd/current_status and report back to me if any RAID drive shows up as "DEAD" - like: /dev/sda2  DEAD
Thanks for your help and patience!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Shell script for mvn build 2 78
Issues with Ports in Linux (Hyper-V Guest) 2 107
Openwrt vnstat 9 222
How to run a Linux Command from a different other than Root in Linux 5 116
Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question