Scripting Flashcards
1
Q
What is the location for system binaries?
A
/usr/local/sbin
2
Q
Bash shbang
A
#!/bin/bash
3
Q
Check if user exist
A
getent passwd $user
4
Q
Execute a script on which you have no executable permission
A
sh script.sh
5
Q
Loop through servera to serverd, utility, bastion and get their uptime
A
for i in server{a..d} utility bastion; do ssh $i uptime; done
6
Q
Read input from keyboard into a variable animal
A
read -p "Then your animal: " animal
7
Q
Example case statemen
A
case $animal; in person) echo "This is a person" ;; dog) echo "This is a dog" ;; *) echo "Unknown anuimal" exit 1 ;; esac
8
Q
BRE
A
Basic Regular Expression
9
Q
ERE
A
Extended Regular Expression
10
Q
With grep show the line number where the pattern was found
A
grep -n root /etc/passwd
11
Q
With grep, count the number of lines where the pattern was found
A
grep -c root /etc/passwd
12
Q
Grep: match to the begining of the line
A
grep ^root /etc/passwd
13
Q
Grep: match to the end of the line
A
grep root$ file
14
Q
Grep to match non comment line
A
grep ^[^#] file.txt
15
Q
strip comment function
A
sc(){ grep ^[^#] $1 }