Find the answer to your Linux question:
Results 1 to 3 of 3
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Bash-If statement issues

    Hey guys. This is my first post. I've found a lot of answers I need on this site in the past by googling. Here is my problem. I'm writing a script for work (i work network security) and this script tests printers to make sure their default passwords have been changed. I'm trying to write an if statement based on if the address is ping able or not. My problem is if [ "ping -c1 -w1 $ip | grep 1 received" ] If the IP isn't ping able i want it to store that IP in a new file. I can't grep for "1 received" because there is a space. does anyone have a work around for this or can tell me what my problem is?

    ip=`sed -n "$x p" IPlist.txt`
    if [ "ping -c1 -w1 $ip | grep 1 received" ]
    #code to test password
    echo "IP is not responding"
    echo "$ip not online" >> offlinePrinters.txt

    Thanks in advanced
    (I havn't written bash in a loooong time)

  2. #2
    Oh and by the way. This doesn't throw any error messages. It just doesn't write "$ip not online" to "offlinePrinters.txt" so it runs... but it doesn't work

  3. #3
    Figured it out. I had to use ( ) around the condition. Not [ ]

  4. $spacer_open

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts