CH:23 Scripting Flashcards
Where user profile scripts run
and init scripts are run when a daemon is stopped or started
Why system administrators also need basic knowledge of scripting
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
Output Hello world
$echo Hello world
How to make printing hello world executable
- $ echo echo Hello World > hello_world
- $ chmod +x hello_world
- $ ./hello_world
she-bang ?
!
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
Comment ?
# this is a comment line e.g
```script
#!/bin/bash
#
# Hello World Script
#
echo Hello world
~~~
Variables ?
#!/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
forcing a script to run in the same script is called
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 to run a script in a sperate shell
by typing bash with name of the scripts as parameters
$ bash runme
hash +x ?
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$
setuid root spoofing
& how to improve security
is rare but possible attack
to improve security add – after the #!/bin/bash
#!/bin/bash - or #!/bin/bash --
Any arguments after the – are treated as .
filenames and arguments. An argument of - is equivalent to –