forked from jivoi/Cheatsheets
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bashscripting and CiscoIOS
- Loading branch information
Showing
2 changed files
with
215 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
Simple Bash Scripting Cheatsheet | ||
-------------------------------- | ||
|
||
[+] nano Shortcuts | ||
ctrl v Next page. | ||
ctrl y Previous page. | ||
ctrl w Where is (find). | ||
ctrl k Cut that line of test. | ||
ctrl x Exit editor. | ||
|
||
[+] Create a text file: | ||
touch file Creates an empty file. | ||
ifconfig > tmp pipe the output of a command | ||
nano file | ||
|
||
[+] Create a file and append text to it: | ||
ifconfig > tmp | ||
echo >> tmp | ||
ping google.com -c3 >> tmp | ||
|
||
[+] How to view a file: | ||
cat file Show entire contents of file. | ||
more file Show one page at a time. Space bar for next page and (q) to exit. | ||
head file Show the first 10 lines. | ||
head -15 file Show the first 15 lines. | ||
tail file Show the last 10 lines. | ||
tail -15 file Show the last 15 lines. | ||
tail -f file Useful when viewing the output of a log file. | ||
|
||
[+] pipe | ||
cat tmp | grep Bcast Feeds the output of one process to the input of another process. | ||
|
||
[+] Processes | ||
ps aux Show all running process for all users. | ||
kill -9 PID Nicely kill a PID. | ||
|
||
[+] Word Count | ||
wc -l tmp2 Count the number of lines in a file | ||
|
||
[+] cut | ||
-d delimiter | ||
-f fields | ||
|
||
[+] sort | ||
Sort by unique sort -u file | ||
sort IP addresses correct sort -t . -k 1,1n -k 2,2n -k 3,3n -k 4,4n | ||
cat tmp2 | cut -d '(' -f2 | cut -d ')' -f1 | sort -u Isolate the IP address | ||
|
||
[+] awk | ||
awk '{print $1}' file Show the 1st column. | ||
awk '{print $1,$5}' file Show the 1st and 5th columns. | ||
|
||
[+] grep | ||
grep -v Remove a single string. | ||
grep -v 'red' file | ||
|
||
[+] egrep -v | ||
Remove multiple strings egrep -v '(red|white|blue)' file | ||
|
||
[+] sed | ||
sed 's/FOO/BAR/g' file Replace FOO with BAR. | ||
sed 's/FOO//g' file Replace FOO with nothing. | ||
sed '/^FOO/d' file Remove lines that start with FOO. | ||
|
||
[+] colour | ||
31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan | ||
echo -e "\e[1;34mThis is a blue text.\e[0m" | ||
|
||
|
||
|
||
|
||
Bash Scripts | ||
------------ | ||
|
||
[+] Simple bash script: | ||
#!/bin/bash | ||
clear | ||
echo | ||
echo | ||
print "Hello world." | ||
|
||
[+] Make a file executable. | ||
chmod +x file | ||
chmod 755 file | ||
|
||
[+] Variables | ||
name=Bob | ||
echo $name | ||
user=$(whoami) | ||
echo $user | ||
echo 'Hello' $name. 'You are running as' $user. | ||
|
||
#!/bin/bash | ||
clear | ||
echo "Hello World" | ||
name=Bob | ||
ip=`ifconfig | grep "Bcast:" | cut -d":" -f2 | cut -d" " -f1` | ||
echo "Hello" $name "Your IP address is:" $ip | ||
|
||
[+] User Input | ||
read -p "Domain: " domain | ||
|
||
#!/bin/bash | ||
echo "Please input your domain:" | ||
read -p "Domain:" domain | ||
ping -c 5 $domain | ||
|
||
[+] Check For No User Input | ||
if [ -z $domain ]; then | ||
echo | ||
echo "#########################" | ||
echo | ||
echo "Invalid choice." | ||
echo | ||
exit | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
Cisco IOS Command Line Cheatsheet | ||
--------------------------------- | ||
|
||
--- Verify Basic Configuration: | ||
|
||
Shows information about the switch and its interfaces, RAM, NVRAM, flash, IOS, etc. | ||
SW1# show version | ||
|
||
Shows the current configuration file stored in DRAM. | ||
SW1# show running-config | ||
|
||
Shows the configuration file stored in NVRAM which is used at first boot process. | ||
SW1# show startup-config | ||
|
||
Lists the commands currently held in the history buffer. | ||
SW1# show history | ||
|
||
Shows an overview of all interfaces, their physical status, protocol status and ip address if assigned. | ||
SW1# show ip interface brief | ||
|
||
Shows detailed information about the specified interface, its status, protocol, duplex, speed, encapsulation, last 5 min traffic. | ||
SW1# show interface vlan 1 | ||
|
||
Shows the description of all interfaces | ||
SW1# show interfaces description | ||
|
||
Shows the status of all interfaces like connected or not, speed, duplex, trunk or access vlan. | ||
SW1# show interfaces status | ||
|
||
Shows the public encryption key used for SSH. | ||
SW1# show crypto key mypubkey rsa | ||
|
||
Shows information about the leased IP address (when an interface is configured to get IP address via a dhcp server) | ||
SW1# show dhcp lease | ||
|
||
--- Router Modes: | ||
|
||
Router>: User mode = Limited to basic monitoring commands | ||
Router#: Privileged mode (exec-level mode) = Provides access to all other router commands | ||
Router(config)#: global configuration mode = Commands that affect the entire system | ||
Router(config-if)#: interface mode = Commands that affect interfaces | ||
Router(config-subif)#: subinterface mode = Commands that affect subinterfaces | ||
Router(config-line)#: line mode = Commands that affect in lines modes (console, vty, aux…) | ||
Router(config-router)#: router configuration mode | ||
|
||
--- Changing switch hostname: | ||
|
||
Switch(config)# hostname SW1 | ||
|
||
--- Configuring passwords: | ||
|
||
SW1(config)# enable secret cisco ! MD5 hash | ||
SW1(config)# enable password notcisco ! Clear text | ||
|
||
--- Securing console port: | ||
|
||
SW1(config)# line con 0 | ||
SW1(config-line)# password cisco | ||
SW1(config-line)# login | ||
|
||
--- Securing terminal lines: | ||
|
||
SW1(config)# line vty 0 4 | ||
SW1(config-line)# password cisco | ||
SW1(config-line)# login | ||
|
||
--- Encrypting passwords: | ||
|
||
SW1(config)# service password-encryption | ||
|
||
--- Configuring banners: | ||
|
||
SW1(config)# banner motd $ | ||
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- | ||
UNAUTHORIZED ACCESS IS PROHIBITED | ||
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- | ||
$ | ||
|
||
--- Giving the switch an IP address: | ||
|
||
SW1(config)# interface vlan 1 | ||
SW1(config-if)# ip address 172.16.1.11 255.255.255.0 ! or DHCP | ||
SW1(config-if)# no shutdown | ||
|
||
--- Setting the default gateway: | ||
|
||
SW1(config)# ip default-gateway 172.16.1.1 | ||
|
||
--- Saving configuration: | ||
|
||
SW1# copy running-config startup-config | ||
Destination filename [startup-config]? ! Press enter to confirm file name. | ||
Building configuration… | ||
[OK] | ||
|
||
! Short for write memory. | ||
SW1# wr | ||
Building configuration… | ||
[OK] |