Sponsored Content
Top Forums Shell Programming and Scripting Running external programs inside an if then else Post 302552049 by mrplow2k69 on Thursday 1st of September 2011 01:26:55 PM
Old 09-01-2011
This is my entire code that is the latest revision before coming here for help:

Code:

#!/bin/bash
NOW=$(date)
GRP1=$(grep --quiet "Outtage" newfile)
GRP2=$(grep --quiet "0" outage.txt)

if [[ $GRP1 == 0 && $GRP2 == 0 ]]; then

        echo MyFax Outage on $NOW >> myfaxoutage.txt
        echo 1 > outage.txt
        ./senddownemail.sh
fi


if grep --quiet "Outtage" newfile; then

        echo MyFax Outage on $NOW >> myfaxoutage.txt
fi

#if grep --quiet "Normal" newfile | grep --quiet "1" outage.txt; then
#
#       echo MyFax Normal Status on $NOW >> myfaxoutage.txt
#       echo 0 > outage.txt
#       ./sendupemail.sh
#
#else

if grep --quiet "Normal" newfile; then

        echo MyFax Normal Status on $NOW >> myfaxoutage.txt
        echo 0 > outage.txt
        ./sendupemail.sh
fi

Legend:

myfaxoutage.txt - file that stores the reporting for later use
outage.txt = file that contains the 1 or 0 that tells the file if an email has been sent.
newfile - file that is created in the first step (the actual status page that WGET grabs and then gets AWKed and SEDed)

Let me know if you want me to post the code to any other files.

Thanks!! Smilie

---------- Post updated at 01:19 PM ---------- Previous update was at 12:34 PM ----------

This is my current file with the changes said above:

Code:
#!/bin/bash
NOW=$(date)
mGrep1=$(grep -c "Outtage" newfile)
mGrep2=$(grep -c "0" outage.txt)
mGrep3=$(grep -c "1" outage.txt)
mGrep4=$(grep -c "Normal" newfile)

if [[ "${mGrep1}" != "0" && "${mGrep2}" != "0" ]]; then

        echo MyFax Outage on $NOW >> myfaxoutage.txt
        echo 1 > outage.txt
        ./senddownemail.sh
else
        echo MyFax Outage on $NOW >> myfaxoutage.txt
fi

#if grep --quiet "Normal" newfile | grep --quiet "1" outage.txt; then
#
#       echo MyFax Normal Status on $NOW >> myfaxoutage.txt
#       echo 0 > outage.txt
#       ./sendupemail.sh
#
#else

if [[ "${mGrep3}" != "0" && "${mGrep4}" != "0" ]]; then

        echo MyFax Normal Status on $NOW >> myfaxoutage.txt
        echo 0 > outage.txt
        ./sendupemail.sh
else
        echo MyFax Normal Status on $NOW >> myfaxoutage.txt
fi

Now, the file runs BUT it puts that the status is normal AND there is an outage in the reporting file (myfaxoutage.txt). the outage.txt has a ZERO in it to start.

---------- Post updated at 01:26 PM ---------- Previous update was at 01:19 PM ----------

Asi look more into the file, its putting both echo statements in because neither the AND statements are true so it defaults to both the ELSEs..... hmmm. I could put 4 if statements in and that would be the end of it but i know there is a more efficient way. Ill put those 4 in to get it working (need it working) and hopefully we can figure this out.
 

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
NPM-RUN-SCRIPT(1)                                                                                                                NPM-RUN-SCRIPT(1)

NAME
npm-run-script - Run arbitrary package scripts SYNOPSIS
npm run-script <command> [--silent] [-- <args>...] alias: npm run DESCRIPTION
This runs an arbitrary command from a package's "scripts" object. If no "command" is provided, it will list the available scripts. run[-script] is used by the test, start, restart, and stop commands, but can be called directly, as well. When the scripts in the package are printed out, they're separated into lifecycle (test, start, restart) and directly-run scripts. As of ` https://blog.npmjs.org/post/98131109725/npm-2-0-0, you can use custom arguments when executing scripts. The special option -- is used by getopt https://goo.gl/KxMmtG to delimit the end of the options. npm will pass all the arguments after the -- directly to your script: npm run test -- --grep="pattern" The arguments will only be passed to the script specified after npm run and not to any pre or post script. The env script is a special built-in command that can be used to list environment variables that will be available to the script at run- time. If an "env" command is defined in your package, it will take precedence over the built-in. In addition to the shell's pre-existing PATH, npm run adds node_modules/.bin to the PATH provided to scripts. Any binaries provided by locally-installed dependencies can be used without the node_modules/.bin prefix. For example, if there is a devDependency on tap in your package, you should write: "scripts": {"test": "tap test/*.js"} instead of "scripts": {"test": "node_modules/.bin/tap test/*.js"} to run your tests. The actual shell your script is run within is platform dependent. By default, on Unix-like systems it is the /bin/sh command, on Windows it is the cmd.exe. The actual shell referred to by /bin/sh also depends on the system. As of ` https://github.com/npm/npm/releases/tag/v5.1.0 you can customize the shell with the script-shell configuration. Scripts are run from the root of the module, regardless of what your current working directory is when you call npm run. If you want your script to use different behavior based on what subdirectory you're in, you can use the INIT_CWD environment variable, which holds the full path you were in when you ran npm run. npm run sets the NODE environment variable to the node executable with which npm is executed. Also, if the --scripts-prepend-node-path is passed, the directory within which node resides is added to the PATH. If --scripts-prepend-node-path=auto is passed (which has been the default in npm v3), this is only performed when that node executable is not found in the PATH. If you try to run a script without having a node_modules directory and it fails, you will be given a warning to run npm install, just in case you've forgotten. You can use the --silent flag to prevent showing npm ERR! output on error. You can use the --if-present flag to avoid exiting with a non-zero exit code when the script is undefined. This lets you run potentially undefined scripts without breaking the execution chain. SEE ALSO
o npm help 7 scripts o npm help test o npm help start o npm help restart o npm help stop o npm help 7 config January 2019 NPM-RUN-SCRIPT(1)
All times are GMT -4. The time now is 09:24 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy