Bash-script for adding SSL at startup. 

This is a small part of the script that we use in the ownCloud VM, and it’s good to have if you want to do the same thing as we do – distribute VMs with SSL activated from start.

1. cREATE THE .SH FILE IN NANO
~:$ sudo nano /example/folder/ssl.sh
2. put this in ssl.sh
#!/bin/bash
# Activate self-signed SSL
a2enmod ssl &&
a2ensite default-ssl &&
a2dissite 000-default.conf &&
service apache2 reload &&
rm /example/folder/ssl.sh 
exit 0
3. When you saved the ssl.sh you need to give it the correct permissions by typing
:~$ chmod 755 /example/folder/ssl.sh
4. When that is done you need to create a crontab by typing
~:$ sudo -i

:~$ crontab -e
5. Then put this in the crontab file:
 @reboot /example/folder/ssl.sh

A script that sends you the owncloud.log when you desire, by setting up a cronjob

To be able to be updated about what’s going on with your ownCloud server this is a very good script that takes care if that! So instead of checking your owncloud.log manually all the time, this script just emails you the file when you want it to do so. The setting that is now is @daily, which means that it’s sending the mail every day at 00.00.

Note: You need to have send installed before you can send mail from the system.

1. Create the file:
 ~:$ sudo nano /var/www/logscript.sh
2. Put this in logscript.sh
#!/bin/bash
# This script emails a file free of choice to whoever you wants to receive it.
# The script then deletes the file on your computer / server.
# The script does not run any checks if mail-utils or sendmail are installed.
# They must be installed before this script can be executed.

# This is the subject of the mail
SUBJECT="Logfile from $(printf $HOSTNAME)"

# What file is the mail containing
FILE="/var/www/owncloud/data/owncloud.log"

# Decide what level of messages you want, 
# in this case at least "level2" warnings:
# INFO="level"":2"
# grep "$INFO" /var/www/owncloud/data/owncloud.log
# sed '\message\,\level":2\p' /var/www/owncloud/data/owncloud.log
# var=$ (sed -n '/message/,/"level":3,/p' /var/www/owncloud/data/owncloud.log)
# var=$ (sed -n '/message/,/"level":3,/p' "$FILE")

# Receiver of mail
RECEIVER="example@mail.com"

# Here we make a control that the script runs as root
# If not, we send a error message.
if [ `id -u` -ne "0" ]; then
printf "\nYou have to run this script as root.\n\n"
exit 192
fi

# Here the mail program collects the information it's about to send.
mail -s "$SUBJECT" "$RECEIVE" < $FILE

# This deletes the file we just emailed (owncloud makes a new one by itself)
rm -rf $FILE
exit 0
3. WHEN THAT IS DONE YOU NEED TO CREATE A CRONTAB BY TYPING
:~$ sudo -i

:~$ crontab -e
4. THEN PUT THIS IN THE CRONTAB FILE:
@daily /var/www/logscript.sh


Pro tip

Install ownCloud and host your own private cloud. Download  the pre-configured ownCloud VM today!