Skip to main content

DevNet notes - Linux - Bash (2)

grep basics

grep is a command line tool for searching plain text to match a regular expression

grep use examples:


#grep 'import' test_requests.py - will display line in the file that contains word 'import'


output:


    from turtle import title

    import requests

    from bs4 import BeautifulSoup


#grep -R 'import' . - will look for all files within the directory and subdirectories that contain word 'import'


output:


    ./test_urllib:import urllib3

    ./xml2-to-dict.py:import xmltodict

    ./xml-to-dict.py:import xmltodict

    ./eveng-request.py:import requests

    ./parse_yaml.py:import yaml

    ./test_requests.py:from turtle import title

    ./test_requests.py:import requests

    ./test_requests.py:from bs4 import BeautifulSoup

    ./automate-l1.py:from __future__ import print_function, unicode_literals

    ./automate-l1.py:import logging

    ./automate-l1.py:from netmiko import ConnectHandler, redispatch

    ./automate-l1.py:from netmiko import Netmiko

    ./automate-l1.py:from getpass import getpass

    ./json-test.py:import json

    ./parse_json.py:import json


other options:


'-i' - will make above search case sensitive, example:


#grep -R -i 'Cisco123' .


output:


    ./curl_get_token.sh:curl -X POST -u 'devnetuser:Cisco123!' -H 'Content-Type: application/json' https://sandboxdnac.cisco.com/dna/system/api/v1/auth/token


'-G' -indicates a standard regular expression, supports following metachracters:

     ^ beggining of the line

     $ end of the line

     . single character

     * zero or more occurences of the preceeding character

     [xyz] to match either 'x', 'y' or 'z'

     [d-f] or [1-3] to match character in the range between 'd-f' or '1-3'

     \< or \b to match beggining of the word

     \> to match end of the word

     \ escape character

     

'-E' -indicates extended regular expression, supports all above metacharacters used in standard expression and additionally:

     ? zero or one occurance of the proceeding character

     + one or more occurancess of the proceeding character

     {X} or {X,Y} strings with X repetition or X repetition but lower that Y repetition

     | operator 'OR'

     () capture group


'-F' -indicates fixed regular expression

'-P' -indicates Perl regular expression


Bash - echo command


echo " Hello! " - outputs the text inside quatation marks, also supports following escape characters:

    \n -new line

    \t -horizontal tab

    \v -vertical tab

    \b -backspace

    \\ -prints the backslash


echo - how to show variable/run command within quotation marks? use '$' sign, example:


lets set a variable:

#MY_VAR='0123456789'


use case:

#echo "my test variable is: $MY_VAR" 


output:

    my test variable is: 0123456789


another use example:

#echo "list of my files: $(ls)" - will return list of files in the current location


Comments

Popular posts from this blog

Plumbing... QoS

Plumbing... QoS Rule no. 1: QoS doesn't create bandwidth. If the pipe is permanently too small, the only fix is a bigger pipe. What QoS does is decide who waits and who gets dropped when congestion happens. That makes it the right tool for short, recurring bursts of congestion, not for a chronic shortage of capacity. Most common problems to solve 1. Delay (latency): the time a packet takes to cross the network. Real-time traffic such as voice becomes unusable when one-way delay gets too high. 2. Jitter: the variation in delay between packets of the same flow. QoS reduces it by giving delay-sensitive packets a fast, predictable path through the queues. 3. Packet loss: QoS ensures that traffic which can tolerate loss (and recover from it, like TCP) is dropped before traffic that can't. 4. TCP global synchronisation: when a queue fills up and tail drop discards packets from many TCP flows at the same moment, all of those flows slow down together. The link is then underused until t...

Multicast - Part 1

Multicast is a communication method that lets a source send traffic to a group of receivers simultaneously. The source sends a single stream, and the network copies it only where the paths to the receivers split. Multicast relies on two protocols: Internet Group Management Protocol (IGMP) and Protocol Independent Multicast (PIM). IP multicast concept: - receivers use IGMP to tell their local router which multicast groups they want to join - routers use PIM to route multicast traffic between each other - only members of the group receive the traffic - a source sends traffic once to the group address, and all members receive it - a source doesn't need to be a member of the group to send traffic to it - a multicast group address is only ever a destination; the source address is always a unicast address IPv4 multicast address space Multicast uses 224.0.0.0 - 239.255.255.255 (224.0.0.0/4, formerly Class D), which includes: 1. 224.0.0.0 - 224.0.0.255 - Local Network Control Bloc...

Routing protocols - ISIS brief

What is IS-IS? - a link-state routing protocol defined in ISO/IEC 10589, originally designed as the routing protocol for CLNP (ISO 8473), the OSI connectionless network protocol - IPv4 support was added in RFC 1195 (Integrated IS-IS) and IPv6 support in RFC 5308 - runs directly over Layer 2, not over IP, but still uses OSI addresses (NETs) to identify routers. A side benefit: because it doesn't run over IP, it is hard to attack remotely - mostly popular in large ISP environments - similarly to OSPF, it runs the Dijkstra SPF algorithm - uses Hello packets (IIHs) to form and maintain adjacencies - uses a two-level hierarchy: Level 1 for routing within an area and Level 2 for routing between areas - elects a Designated Intermediate System (DIS), similar to the OSPF DR, but with no backup DIS - in general simpler than OSPF: fewer packet types, no LSA types to learn, no special area types (stub, NSSA), and TLVs make it easy to extend with new features Terminology - a router is an Interm...