CH:23 Scripting Flashcards

1
Q

Where user profile scripts run

A

and init scripts are run when a daemon is stopped or started

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

Why system administrators also need basic knowledge of scripting

A

to understand how their servers and their applications are started, updated, upgraded, patched, maintained, configured and removed, and also to understand how a user environment is built

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

Output Hello world

A

$echo Hello world

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

How to make printing hello world executable

A
  1. $ echo echo Hello World > hello_world
  2. $ chmod +x hello_world
  3. $ ./hello_world
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

she-bang ?

A

!

aka (sha-bang)
————————————————————————–
Used to :
To instruct a shell to run your script in a certain shell
————————————————————————-
#!/bin/bash
echo -n hello
-> this wiill run in a bash Shell

echo -n hello
-> this wiill run in a Korn Shell

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

Comment ?

A
# this is a comment line
e.g 

```script
#!/bin/bash
#
# Hello World Script
#
echo Hello world
~~~

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

Variables ?

A
#!/bin/bash 
#
# simple variable in script 
#
var1=4
echo var1 = $var1

variables do not survive the end of the script cuz scripts runs on their own shell

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

forcing a script to run in the same script is called

A
Sourcing a script 
---------------------------------------------------------------------------
paul@RHEL4a ~]$ source ./vars 
var1 = 4
[paul@RHEL4a ~]$ echo $var1 
4
[paul@RHEL4a ~]$
----- the bellow is identical to the above one
[paul@RHEL4a ~]$ . ./vars
 var1 = 4
[paul@RHEL4a ~]$ echo $var1 
4
[paul@RHEL4a ~]$
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

how to run a script in a sperate shell

A

by typing bash with name of the scripts as parameters

$ bash runme

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

hash +x ?

A

paul@debian6~/test$ bash -x runme
+ var4=42
+ echo 42
42

paul@debian6~/test$ cat runme 
# the runme script 
var4=42 
echo $var4

paul@debian6~/test$

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

setuid root spoofing

& how to improve security

A

is rare but possible attack

to improve security add – after the #!/bin/bash

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

Any arguments after the – are treated as .

A

filenames and arguments. An argument of - is equivalent to –

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