![]() The question mark is a Boolean test which returns true or false based on the value tested. These checks are a good example of the Ruby syntax for asking questions about objects. If the line is empty, or if the line starts with reboot or wtmp, we want to skip it otherwise, we want to process it. Then we use an if/elsif/else conditional block to check for different values that we want to ignore. ![]() ![]() We iterate through each line of our output from last with our for loop and assign each item to the l variable. Next, we create two empty arrays to store the unique users and hosts that we discovered with the last command. The execution returns a string, which we split based on newlines and assign to our data array. We put the last command in ` marks in order to tell Ruby that we want to run that command within the operating system, and then return stdout to the application. ![]() The last command lists the last logins for the system. The Python and Perl conditional operators work identically in Ruby. Ruby conditionals are very similar to what we have seen before. Jason Andress, Ryan Linn, in Coding for Penetration Testers (Second Edition), 2017 Control statementsĮarlier, we used some basic if statements and for loops. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |