Scripting Flashcards

1
Q

What is the location for system binaries?

A

/usr/local/sbin

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Bash shbang

A
#!/bin/bash
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Check if user exist

A

getent passwd $user

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Execute a script on which you have no executable permission

A
sh script.sh
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Read input from keyboard into a variable animal

A
read -p "Then your animal: " animal
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

BRE

A

Basic Regular Expression

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

ERE

A

Extended Regular Expression

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

With grep show the line number where the pattern was found

A

grep -n root /etc/passwd

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

With grep, count the number of lines where the pattern was found

A
grep -c root /etc/passwd
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Grep: match to the begining of the line

A
grep ^root /etc/passwd
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Grep: match to the end of the line

A
grep root$ file
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Grep to match non comment line

A
grep ^[^#] file.txt
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

strip comment function

A
sc(){
   grep ^[^#]  $1
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

grep case insensitive search

A

grep -i root /etc/passwd

17
Q

Explain:

grep -e user -e group file.txt
A
grep -E 'user|group' file.txt