Jump to content

http://pastebin.com/ehHz7r9P

I wanted to make a program that (hopefully if you can understand what i wrote) does that. I wanted to run it on a Linux machine. I was wondering why its not working.. Well, it was not working because the syntax is completely wrong

 

It is only 18 lines of code, could someone please help me fix this so it can be run on the linux machine?

In any language (any) as long as it can run on my computer.

 

 

 

OFF TOPIC: I suggest every poll from now on to have "**CK EA" option instead of "Other"

Link to comment
https://linustechtips.com/topic/636986-what-is-wrong-with-this-code/
Share on other sites

Link to post
Share on other sites

1 hour ago, jimistephen said:

while(online = false) 

 

I don't know what language this is, but in most languages I know this is not checking if it's equal, it's setting it to false. Like in c++ you would have

bool online = false;

while(online == false)

bash/linux , and I believe he's setting the boolean to true based on the output from the ping command not checking

 

I can't test it but 

1) hy set a boolean? just set the rm in the if/fi statement 

2) linux lets ping run endlessly unlike windows so I think the first line is just running non-stop

 

edit

try this or something like this

ping -q -c5 google.com > /dev/null

if [ $? -eq 0 ]
then
        'rm -rf ~Desktop/afile.txt'
fi

 

 

                     .
                   _/ V\
                  / /  /
                <<    |
                ,/    ]
              ,/      ]
            ,/        |
           /    \  \ /
          /      | | |
    ______|   __/_/| |
   /_______\______}\__}  

Spoiler

[I5-12600k | 32gb DDR5 6000 | RTX5070 | 2x1tb M.2]

 

[Ryzen 5 1600 | 16gb DDR4 3200 | GTX1030 | 4x 8tb HDD] 

 

Link to post
Share on other sites

2 hours ago, RedWulf said:

bash/linux , and I believe he's setting the boolean to true based on the output from the ping command not checking

 

I can't test it but 

1) hy set a boolean? just set the rm in the if/fi statement 

2) linux lets ping run endlessly unlike windows so I think the first line is just running non-stop

 

edit

try this or something like this


ping -q -c5 google.com > /dev/null

if [ $? -eq 0 ]
then
        'rm -rf ~Desktop/afile.txt'
fi

 

 

You are completely correct, I want to test the output of a certain command (not ping, ls, rf, etc) and set it to either true or false accordingly

So, what I tried to do was test the output of ping google.com (lets say ping runs once)

and if the output was containing what I had stated, it would set it to false and run the command at the end of the loop, and end. If true it would repeat until false

 

I will try rewriting it in a hopefully working bash form and then consult you guys 

 

Sorry :(

OFF TOPIC: I suggest every poll from now on to have "**CK EA" option instead of "Other"

Link to post
Share on other sites

Just now, babadoctor said:

You are completely correct, I want to test the output of a certain command (not ping, ls, rf, etc) and set it to either true or false accordingly

So, what I tried to do was test the output of ping google.com (lets say ping runs once)

and if the output was containing what I had stated, it would set it to false and run the command at the end of the loop, and end.

 

I will try rewriting it in a hopefully working bash form and then consult you guys 

As i mentioned, unlike some languages, with sh you can get the ping results directly as 0 or 1 no need to check for words in the response that just makes it messy unless you're looking for a specific timing. Also for syntax, the if statement needs a fi and a then. If you want it to loop then I would suggest a for or while loop, though you'll want to check for said file to avoid it exiting from an error. 

                     .
                   _/ V\
                  / /  /
                <<    |
                ,/    ]
              ,/      ]
            ,/        |
           /    \  \ /
          /      | | |
    ______|   __/_/| |
   /_______\______}\__}  

Spoiler

[I5-12600k | 32gb DDR5 6000 | RTX5070 | 2x1tb M.2]

 

[Ryzen 5 1600 | 16gb DDR4 3200 | GTX1030 | 4x 8tb HDD] 

 

Link to post
Share on other sites

7 minutes ago, RedWulf said:

As i mentioned, unlike some languages, with sh you can get the ping results directly as 0 or 1 no need to check for words in the response that just makes it messy unless you're looking for a specific timing. Also for syntax, the if statement needs a fi and a then. If you want it to loop then I would suggest a for or while loop, though you'll want to check for said file to avoid it exiting from an error. 

OKAY OKAY

lets ignore ping command

I dont want the ping command

Those commands that I had there were placeholders.

What I DO want is to get the output of a command like ls

and then if it has certain words in it then report as false and run separate command

and it runs forever until the certain word is detected, in which it will run the other command and exit the script.

OFF TOPIC: I suggest every poll from now on to have "**CK EA" option instead of "Other"

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×