Difference between revisions of "Ubuntu Server Setup"
Jump to navigation
Jump to search
(Created page with "== Turn on Mod Rewrite == <pre> 1. a2enmod rewrite 2. restart apache server 3. edit vhost file AllowOverride all </pre> == Shell Scripting == <pre> • Scripts must be ch...") |
|||
Line 101: | Line 101: | ||
hello (you don't need the () just call the name of the function) | hello (you don't need the () just call the name of the function) | ||
**Positional Parameters and passing info to a funciton | ** Positional Parameters and passing info to a funciton | ||
Line 112: | Line 112: | ||
hello robert # robert is passed to the function hello | hello robert # robert is passed to the function hello | ||
#output is hello Robert | #output is hello Robert | ||
**Outputting miltple calls to a function | ** Outputting miltple calls to a function | ||
Line 171: | Line 171: | ||
== Apache Commands== | == Apache Commands== | ||
*List apache packages and versions | |||
List apache packages and versions | **dpkg -l | grep apache | ||
dpkg -l | grep apache | |||
shows version of ubnuntu | *shows version of ubnuntu | ||
cat /etc/issue | **cat /etc/issue | ||
shows version of ubuntu | |||
cat /etc/*-release | *shows version of ubuntu | ||
give detail status of the service | **cat /etc/*-release | ||
apachectl status | |||
Gives info on where config file is located | *give detail status of the service | ||
apachectl -V | **apachectl status | ||
Search the entire server for the file | |||
find / | grep "apache2\.conf" | *Gives info on where config file is located | ||
Info for each line in the .conf File | **apachectl -V | ||
http://httpd.apache.org/docs/current/mod/directives.html | *Search the entire server for the file | ||
Displays Config Info about all Virtual Hosts | **find / | grep "apache2\.conf" | ||
apachectl -t -D DUMP_VHOSTS | * Info for each line in the .conf File | ||
Display All Modules form Apache | ** http://httpd.apache.org/docs/current/mod/directives.html | ||
apachectl -t -D DUMP_MODULES | * Displays Config Info about all Virtual Hosts | ||
Enable and Disable Modules | ** apachectl -t -D DUMP_VHOSTS | ||
Directory for Modules | * Display All Modules form Apache | ||
/etc/apache2/modes-available and /etc/apache2/mods-enabled | ** apachectl -t -D DUMP_MODULES | ||
a2enmod and a2dismod will enable of disable modules | *Enable and Disable Modules | ||
Find where the apache error log is located | *Directory for Modules | ||
grep -Ri ErrorLog /etc/apache2 | **/etc/apache2/modes-available and /etc/apache2/mods-enabled | ||
Watch Error log in realtime | **a2enmod and a2dismod will enable of disable modules | ||
tail -f error.log | *Find where the apache error log is located | ||
Tools to Analize log files | **grep -Ri ErrorLog /etc/apache2 | ||
AWStats - awstats.sourceforge.net | *Watch Error log in realtime | ||
GoAccess - Terminal app | **tail -f error.log | ||
goaccess.prosoftcorp.com | *Tools to Analize log files | ||
**AWStats - awstats.sourceforge.net | |||
*GoAccess - Terminal app | |||
**goaccess.prosoftcorp.com | |||
== == | == == |
Revision as of 22:47, 7 August 2016
Turn on Mod Rewrite
1. a2enmod rewrite 2. restart apache server 3. edit vhost file AllowOverride all
Shell Scripting
• Scripts must be chmod 755 so they can execute • #!/bin/bash (add to the top of the shell script so it can use the bash shell to interpret the script, you can also add python or other shell programs) • Postional Parameters: $0 ... $9 $@ to access all 0-9 // like in a loop • Exit Status return Codes: Range from 0 to 255: 0 = success: Other than 0 = error condition: use man or info to find meanign of exit status &bull, $? contains the return code of the previously executed command ls /not/here echo "$?" Another Code example HOST="google.com" ping -c 1 $HOST # -c 1 means it will send 1 ping if["$?" -eg "0"] then echo "$HOST reachable" else "$HOST unreachable" fi && and || -the second statement only executes if the first one was successfull mkdir /tmp/bak && cp test.txt /tmp/bak/ -the second statement will execute only if the first one fails cp test.txt /tmp/bak/ || cp test.txt /tmp • chain multiple commands together using a ; (semicolon) cp test.txt /tmp/ ; cp test.txt /bak
File Operators (test)
-d FILE -true if is a directory -e FILE True if file exists -f FILE True if file exist and is a regular file -r FILE True if file is readable by you -s FILE True if file exists and is not empty -w FILE True if file is writable by you -x FILE True if file is executable by you -z FILE True if string is empty -n FILE True if string is not empty String1=String2 true if strings are equal String1 != string2 True if the strings are not equal arg1 -eq arg2 equal arg1 -ne arg2 not equal arg1 -lt arg2 less than arg1 -le arg2 less than or equal to arg1 -gt arg2 greater than arg1 -ge arg2 greater than or equal to read -p "Prompt to dispaly" VarableName accepting user input
for loop to rename all jpg files with the date
#!/bin/bash PICTURES=$(ls *.jpg) DATE=$ (date +%F) for PICTURES IN $PICTURES do echo "Renaming ${PICTURE} to ${DATE} - ${PICTURE}" mv $[PICTUE} ${DATE}-${PICTURE} done // Output renaming bear.jpg to 2015-03-06-bear.jpg
Adding exit commands to scripts
#!/bin/bash HOST="google.com" ping -c 1 $HOST IF [ "$?" -ne"0" ] then echo "$HOST unrechale" exit 1 fi exit 0
Creating a Function
function function-name() {# code goes here} Calling a Function function hello() { echo "hello: } hello (you don't need the () just call the name of the function) ** Positional Parameters and passing info to a funciton #!/bin/bash function hello(){ echo "hello $1" } hello robert # robert is passed to the function hello #output is hello Robert ** Outputting miltple calls to a function #!/bin/bahs funciton hello() { for NAME in $@ do echo "Hello $NAME" done } hello robert bob dan Output hello robert bob dan Using Wildcards * -matches zero or more characters *.txt a* a*.txt ? - matches exactly one character ?.txt a? a?.txt [] character class - matches any of the characters included between the brackets. Matches exactly one character. [aeiou]* exampld: ls -la [abge]* ca[nt] matches:(it will match either the n or the t) can, cat, candy, catch [!] Matches any characters NOT included between the brackets. Matches exactly one character. [!aeiou]* would match below bacause it does not start with any of those letters baseball, cricket Select a range [a-g]* matches files that start with a,b,c,d,e,f,g [3-6]* matches all files start with 3,4,5,6 Using predefined Character Classes [[:alpha:]] [[:alnum:]] [[:digit:]] [[:lower:]] [[:upper:]] [[:space:]] #!/bin/bash cd /var/www/bash # there's a space after the "if", space afer ! then a space after "[", space before "]" if [ ! -d /var/www/bash/text/ ] then mkdir /var/www/bash/text fi for FILE in *.txt do echo "Copying $FILE" cp $FILE /var/www/bash/text done Case Statements
Apache Commands
- List apache packages and versions
- dpkg -l | grep apache
- shows version of ubnuntu
- cat /etc/issue
- shows version of ubuntu
- cat /etc/*-release
- give detail status of the service
- apachectl status
- Gives info on where config file is located
- apachectl -V
- Search the entire server for the file
- find / | grep "apache2\.conf"
- Info for each line in the .conf File
- Displays Config Info about all Virtual Hosts
- apachectl -t -D DUMP_VHOSTS
- Display All Modules form Apache
- apachectl -t -D DUMP_MODULES
- Enable and Disable Modules
- Directory for Modules
- /etc/apache2/modes-available and /etc/apache2/mods-enabled
- a2enmod and a2dismod will enable of disable modules
- Find where the apache error log is located
- grep -Ri ErrorLog /etc/apache2
- Watch Error log in realtime
- tail -f error.log
- Tools to Analize log files
- AWStats - awstats.sourceforge.net
- GoAccess - Terminal app
- goaccess.prosoftcorp.com