Sponsored Content
Top Forums Shell Programming and Scripting Running external programs inside an if then else Post 302551985 by mrplow2k69 on Thursday 1st of September 2011 09:45:35 AM
Old 09-01-2011
Running external programs inside an if then else

Good morning,

First time poster. be gentle! Smilie

I do not know coding all that well but I can hack the hell out of example scripts! I just cant wrap my brain around this one.

Im trying to run two grep statements in the first IF statement and doing an AND between them. Something is going wrong.... Heres a sample of what I would like to do and what I have tried:

Code:
#!/bin/bash

if grep --quiet "WORD-IN-FILE" FILE-TO-CHECK && grep --quiet "WORD-IN-FILE" FILE-TO-CHECK; then

        echo both conditions are found
fi

Ultimately, im going out to a status web page, bringing down the index.html with WGET, AWKing the hell out of it then SEDing the hell out of the AWKs results and posting them to a new file. Then, I am running this file (above script) against that new file created by the previous script (which i have written already and it works well). The two GREP statements will look inside that new file created and find conditions and if those conditions are met, email me the results. I DO NOT want more than one email unless the status of the original index.html changes, then send me an email that it has changed.

Short Form: If status page shows abnormal status AND an email has not been sent yet, send an email alerting to the abnormal status and quit. Then (when the file is run again, every 15 minutes) if the status is STILL abnormal, know that you already sent an email and quit. If later checking results in NORMAL status, send an email alerting the status change and quit. Then (when the file is run every 15 minutes) is the status is still normal, know that you already sent an email and quit.

I have already written all the other programs (first prog to get status page and all the send email progs). I just need this one that figure out if an email has been sent. I have been playing around with creating a file and changing the 1 to a 0 and checking that and quitting when an email was sent but it got way too confusing!! Smilie

Thanks!!! I will be monitoring this forum all day to add any info that you would need to help me out writing this script.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

running preinstalled programs

Im using the knoppix version of linux, which is booting straight off the cd, and it shows my c drive (partiton) that has all my programs i have installed in my xp operating system. Im wondering if theres a way i can play my games like lotr return of the king, or jedi academy, in knoppox. it shows... (2 Replies)
Discussion started by: jestra
2 Replies

2. UNIX for Dummies Questions & Answers

installing/running programs.

Hey folks, i'm a total newbie at linux (only installed it yesterday) so don't be mad at me for querying this. I downloaded firefox, and unpacked the library files and binaries into /usr/lib/firefox. Now, am I correct in thinking that to run it, I need to enter the 'sh /usr/lib/firefox' command into... (4 Replies)
Discussion started by: shep
4 Replies

3. Shell Programming and Scripting

Finding The Number Of Programs That A Given User Running On A TERMINAL

How To Find The Number Of Programs That A User Running ON A GIVEN TERMINAL (4 Replies)
Discussion started by: venkata.ganesh
4 Replies

4. UNIX for Advanced & Expert Users

running X-11 programs as root

Hello, I would like to run gedit as root while logged into my regular user account. When I try to launch gedit from the command line as super user, I get this message: Gtk-WARNING **: cannot open display: Any suggestions or word arounds? It would make my life a lot simpler to edit files... (8 Replies)
Discussion started by: Allasso
8 Replies

5. UNIX for Advanced & Expert Users

calling external values inside awk command

I have a code as follows awk ' BEGIN{FS=OFS=","} { n=split($3,a1,"~") split($4,a2,"~") split($5,a3,"~") for(i=1;i<=n;i++) { print $1,$2,a1,a2,a3,date } }' file In the above code I need to add current date(date). How is this possible to call an date or a exported value... (13 Replies)
Discussion started by: tkbharani
13 Replies

6. Shell Programming and Scripting

Running external script

I do have one script which needs to be run hourly and should generates a report using an "appadmin" user. But script locates in my home directory. Whenerver i executes this script from my home directory /home/jg55555 it prompts me for the password, which is not required since im assinging the... (6 Replies)
Discussion started by: raghunsi
6 Replies

7. Shell Programming and Scripting

Running programs in perl

I am trying to run a program called GMT using perl. Cannot make to run. I have tried using exec("date"); as a test but when I use exec($try); nothing happens. #!/usr/bin/perl print "$#ARGV\n"; if ($#ARGV != 3) { print "usage: jcdplot.perl\n"; exit; } $h = $ARGV;... (1 Reply)
Discussion started by: kristinu
1 Replies

8. Shell Programming and Scripting

Running programs

I have installed a software called GMT, then writing a script that call the new programs ./example02.sh but I am getting ./example02.sh: line 20: gmtset: command not found I have done ./configure make make install (0 Replies)
Discussion started by: kristinu
0 Replies

9. Programming

Running programs from a Python script

Any idea how I can run a program from a phyton script? For example, in csh I will do $tpath/tsimplex base=$fbase data=$fdata restore=$frestore \ nxp=$nx nzp=$nz param=$param intp=$intp nlay=$nlay \ varp=$varp sigma0=$sigma maxiter=$maxiter tol=$tol \ ... (2 Replies)
Discussion started by: kristinu
2 Replies

10. Shell Programming and Scripting

Interpretation of $variables inside programs run from a script

Hi, I am running a shell script that executes a program. Inside this program, variables are also referenced using a dollar symbol, eg. $a, $thething, and the shell script is misinterpreting them as variables relevant to the shell script rather than relevant to the program run from inside the... (2 Replies)
Discussion started by: TheBigH
2 Replies
PIDOF(8)						Linux System Administrator's Manual						  PIDOF(8)

NAME
pidof -- find the process ID of a running program. SYNOPSIS
pidof [-s] [-x] [-o omitpid] [-o omitpid..] program [program..] DESCRIPTION
Pidof finds the process id's (pids) of the named programs. It prints those id's on the standard output. This program is on some systems used in run-level change scripts, especially when the system has a System-V like rc structure. In that case these scripts are located in /etc/rc?.d, where ? is the runlevel. If the system has a start-stop-daemon (8) program that should be used instead. OPTIONS
-s Single shot - this instructs the program to only return one pid. -x Scripts too - this causes the program to also return process id's of shells running the named scripts. -o Tells pidof to omit processes with that process id. The special pid %PPID can be used to name the parent process of the pidof pro- gram, in other words the calling shell or shell script. NOTES
pidof is simply a (symbolic) link to the killall5 program, which should also be located in /sbin. When pidof is invoked with a full pathname to the program it should find the pid of, it is reasonably safe. Otherwise it is possible that it returns pids of running programs that happen to have the same name as the program you're after but are actually other programs. SEE ALSO
shutdown(8), init(8), halt(8), reboot(8) AUTHOR
Miquel van Smoorenburg, miquels@cistron.nl 01 Sep 1998 PIDOF(8)
All times are GMT -4. The time now is 05:26 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy