0

i have this script in nmap but he dont do what i need i need if host done off do ./2.sh mv 1.sh ~/1sh

#!/bin/bash

count=$(nmap -sP -iL hostlist -oG pingscan | grep from* | wc -l) >>/root/host.log`
if [ $? -eq 0 ] ; then
echo "$(date)" "Target host" $TARGET_HOST "unreachable, Rebooting!" >>/root/host.log
./2.sh
mv 1.sh ~/1sh
else
echo "$(date) ===-> OK! " >>/root/host.log
fi

i need if host done off do ./2.sh mv 1.sh ~/1sh and he dont do

estranho
  • 1
  • 1
  • Since `wc -l` is the last command before your if statement, I think it is always giving exit status 0. – James R. Jan 18 '23 at 20:40
  • Your code asks whether `wc -l` fails, which of course it basically never does. Perhaps tangentially see also [Why is testing “$?” to see if a command succeeded or not, an anti-pattern?](https://stackoverflow.com/questions/36313216/why-is-testing-to-see-if-a-command-succeeded-or-not-an-anti-pattern) – tripleee Jan 19 '23 at 06:25
  • Your script has many beginner errors; probably try running it through https://shellcheck.net/ and fixing the obvious ones before posting again. Perhaps see also the [Stack Overflow `regex` tag info page](/tags/regex/info) for basic information about regular expressions, and in particular the meaning of `*` to `grep`. In very brief, you probably want to check if `nmap -sP -iL hostlist -oG pingscan | grep -c from` is zero or not. Alternatively, store the output of `grep` (without `-c`) in an array and check its output status. – tripleee Jan 19 '23 at 06:28

0 Answers0