-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathshell_scripting_notes.txt
159 lines (114 loc) · 4.91 KB
/
shell_scripting_notes.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# ===================================================================================
Why to Write Shell Script ?
1. Shell script can take input from user, file and output them on screen.
2. Useful to create our own commands.
3. Save lots of time.
4. To automate some task of day today life.
5. System Administration part can be also automated.
# ===================================================================================
There are a few other variables that the system sets for you to use as well.
$0 - The name of the Bash script. [ex: echo $SHELL or echo $0]
$1 - $9 - The first 9 arguments to the Bash script. (As mentioned above.)
$# - How many arguments were passed to the Bash script.
$@ - All the arguments supplied to the Bash script.
$? - The exit status of the most recently run process.
$$ - The process ID of the current script.
$USER - The username of the user running the script.
$HOSTNAME - The hostname of the machine the script is running on.
$SECONDS - The number of seconds since the script was started.
$RANDOM - Returns a different random number each time is it referred to.
$LINENO - Returns the current line number in the Bash script.
# ===================================================================================
How to write shell script?
Following steps are required to write shell script:
1. Use any editor like vi or mcedit to write shell script.
2. After writing shell script set execute permission for your script as follows
syntax:
chmod permission your-script-name
Examples:
$ chmod +x your-script-name
$ chmod 755 your-script-name
Note: This will set read write execute(7) permission for owner, for group and
other permission is read and execute only(5).
3. Execute your script as
syntax:
bash your-script-name
sh your-script-name
./your-script-name
Examples:
$ bash bar
$ sh bar
$ ./bar
# ===================================================================================
Linux Notes from Cihangir Beşiktaş
LVM:
---
Pyhsical volumes, volume groups, logical volumes
- pvcreate, pvdisplay, pvremove
- vgcreate, vgdisplay
- lvcreate, lvdisplay
Resource Limits:
----------------
Resource limits of processes
ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 63354
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 1024
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
Find Large Files:
----------------
Files greater than 100MB in /var/log
find /var/log -type f -size +100000k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }'
Kernel Configuration:
---------------------
There are three ways to pass options to the kernel and thus control its behaviour:
When building the kernel.
When starting the kernel (usually, when invoked from a boot loader).
At runtime (through the files in /proc and /sys).
# cat /etc/sysctl.conf
net.ipv4.ip_forward = 1
# sysctl kernel.sysrq=1
# echo "1" > /proc/sys/kernel/sysrq
Process Operations:
-------------------
List parent process:
# ps -o ppid= -p <pid>
# pstree
Kill zombie processes:
# kill -s SIGCHLD pid
Monitoring
--------------
# top
# vmstat
# lsof
# tcpdump
# netstat
# iptraf
# iftop
I/O Monitoring:
# iostat - device level stats
# sar
# iotop - process level stats
RAID:
-----
Raid 0: for large logical volume
Raid 1: redundant volumes
Raid 4: block-level striping with a dedicated parity disk
Raid 5: block-level striping with distributed parity
Raid 6: extends RAID 5 by adding another parity block
it uses block-level striping with two parity blocks distributed across all member disks.
DNS:
---
TTL: https://www.dnswatch.info/articles/dns-update