-1

I've defined the variables here to shorten the logic a little. The wget works fine (downloads the correct file) and grepping for tar.gz works in the wget.log

The issue is the match to another file!

Basically, if it's on a blacklist I want it to skip!

var1=https://somewebsite.com/directory
line1=directory

sudo wget -O wget.log https://somewebsite.com/$line1/releases

if grep -q "tar.gz" wget.log | "$var1" -ne grep -q 
"https://somewebsite.com/$line1" banned; then
    echo "Good Job!"
else
    echo "Skip!"
fi
jww
  • 97,681
  • 90
  • 411
  • 885
J V
  • 3
  • 3
  • Which shell exactly are you using? `sh` usually refers to a POSIX-compatible shell, but `bash` is often the default shell on Linux systems. I personally prefer `fish`. Anyhow, all of them differ in syntax, even if just slightly. Further, none of that really depends on the OS underneath, so the `linux` tag you applied is wrong. – Ulrich Eckhardt May 30 '18 at 21:45
  • What is `"$var1" -ne grep -q` supposed to mean, and why are you piping the output of the first `grep` to it? – Barmar May 30 '18 at 21:48
  • `grep -q` doesn't produce any output, so it makes no sense to pipe its output to another command. – Barmar May 30 '18 at 21:49
  • Can you include samples of the `wget.log` and `banned` files? It would be much easier to diagnose and prescribe a solution if your question included an [MCVE](https://stackoverflow.com/help/mcve). – ghoti May 30 '18 at 21:56
  • wget.log will be just a big dump of info, searched to see if it contains any tar.gz files, the second file "banned" is just a file containing full links that should not be checked against again. Also sorry about incorrect tags :) Still learning definitions on where to put things. – J V May 30 '18 at 22:24
  • [How do bash's logical operators work?](https://stackoverflow.com/q/4763460/608639), [Precedence of the shell logical operators &&, ||](https://unix.stackexchange.com/q/88850/56041), [Unix Boolean Operators ( &&, -a, ||, -o )](https://stackoverflow.com/q/20449680/608639), [How to do a logical OR operation in Shell Scripting](https://stackoverflow.com/q/4111475/608639), etc. – jww May 31 '18 at 01:21

1 Answers1

0

Use && to test if both of the grep commands succeed

if grep -q -F 'tar.gz' wget.log && grep -q -F -x "$variable" banned
then
    echo "Skip!"
else
    echo "Good Job!"
fi

I've used the -F option to grep because none of the strings we're searching for are regular expressions, they're fixed strings. And I used -x in the second grep to match the whole line in the blacklist.

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • So this syntax works, but the purpose of the tar.gz is just a generalized search, not used as a full variable match, however, the second grep (against banned) is indeed an exact string match to another file. – J V May 30 '18 at 22:22
  • That's why I didn't use `-x` on the first `grep`. – Barmar May 30 '18 at 22:26
  • I think I'm a little rusty on conditional if/then. So tar file should be the first check in the if/then, then there needs to be another check in banned. echoing tarfile gives me gibberish right now(which is expected cause it's only meant to match if it finds tar.gz in the dump) but if I grep against banned, the format is going to be different I think. So I'm thinking it should be IF tar.gz matched in file AND $var1 NOT found in banned, THEN echo good job else, banned, fail fi? That is the syntax I'm having issues constructing :) Thank you for any advice – J V May 30 '18 at 22:36
  • Why are you even doing the `wget` if the site is banned? – Barmar May 30 '18 at 23:02
  • I think I understand what you want now, I've updated the answer. – Barmar May 30 '18 at 23:03
  • Yeah that looks like it! Let me test :) I was getting "too many arguments" with this! if grep -q "tar.gz" wget.log | [ "$var1" != grep -F -x "$var1" banned ]; then – J V May 30 '18 at 23:13
  • I still don't understand why you have a pipe there. If you mean *or* it should be `||`. – Barmar May 30 '18 at 23:15
  • Your solution fixed it. Thank you for the proper way to handle double expression with variable :) – J V May 30 '18 at 23:20