root@server:~# cat hostname_check
#!/bin/bash
#
# Checking wether the hostname is correct
#

name=`hostname`
if [ $name == "server" ]; then
        echo "Hostname is:CORRECT"
        echo "Hostname is: $name "
else
        echo "Hostname is:FALSE"
fi

/-------------------------------------------------------------------------------------------------------------------------/

root@server:~# cat DNS_test2
#!/bin/bash

tests=(client-1 client-2 gw)

echo "a)"
for i in ${tests[*]}
do
	AuthAns=$(dig +search +norecurse $i | grep " aa " >/dev/null 2>&1)
	if [[ $? -eq 0 ]]
	then
        	echo "Authorative answer recieved from: $i."
	else
        	echo "Authorative answer was not recieved from: $i."
	fi
done

echo "b)"
for i in ${tests[*]}
do
	RecurTest=$(dig +search $i | grep "ANSWER: 1" >/dev/null 2>&1)
	if [[ $? -eq 0 ]]
	then
        	echo "Recursive answer recieved from: $i."
	else
	        echo "Recursive answer was not recieved from: $i."
	fi
done

echo "-x 172.16.0.11   (client-2)"
        xtest=$(dig -x 172.16.0.11 | grep "11.0.16.172.in-addr.arpa. 3600	IN	PTR	client-2.example.com." >/dev/null 2>&1)
        if [[ $? -eq 0 ]]
        then
                echo "Reverse search, Answer from client-2.example.com recieved"
        else
                echo "Reverse search, incorrect answer"
        fi


/-------------------------------------------------------------------------------------------------------------------------/


root@server:~# cat user1_2_permissions 
#!/bin/bash

user1perm=$(ls -l /home1 | grep "drwxr-xr-x 2 user1   user1" >/dev/null 2>&1)
if [[ $? -eq 0 ]]
then
	echo "User1: Correct Permissions."
	
else
	echo "User1: Wrong Permissions."
fi

user2perm=$(ls -l /home2 | grep "drwxr-xr-x 2 user2 user2" >/dev/null 2>&1)
if [[ $? -eq 0 ]]
then
        echo "User2: Correct Permissions."
else
        echo "User2: Wrong Permissions."
fi

/-------------------------------------------------------------------------------------------------------------------------/


root@client-1:~# cat nfs_test
#!/bin/bash

a=$(nfsstat -m | grep "/usr/local from 172.16.0.2:/usr/local" >/dev/null 2>&1)
if [[ $? -eq 0 ]]
then
	echo "Connection to nfs-server found"
	exit 0
else
	echo "The folder connection server and client was not found"
	exit 1
fi

/-------------------------------------------------------------------------------------------------------------------------/

root@client-1:~# cat nis_test 
#!/bin/bash

echo "nisdomainname should be: nis.server.example.com"
domain=$(nisdomainname | grep "nis.server.example.com" >/dev/null 2>&1)
if [[ $? -eq 0 ]]
then
	echo "nisdomain = nis.server.example.com"
else
	echo "Wrong domain"
fi

echo "******************************************************"

yp=$(ypwhich | grep "server.example.com"  >/dev/null 2>&1)
if [[ $? -eq 0 ]]
then
	echo "ypwhich: server.example.com"
else
	echo "Wrong output with ypwhich. Something is wrong"
fi

echo "******************************************************"

echo "Added user should be: lookatme"
pb=$(ypcat passwd.byname | grep "lookatme" >/dev/null 2>&1)

if [[ $? -eq 0 ]]
then 
	echo "User found: lookatme"
	exit 0
else
	echo "User not found"
	exit 1
fi

/-------------------------------------------------------------------------------------------------------------------------/

root@client-1:~# cat ntp_test 
#!/bin/bash

syncorno=$(timedatectl | grep "NTP synchronized: yes" >/dev/null 2>&1)
if [[ $? -eq 0 ]]
then
	echo "NTP Synhcronized"
	exit 0
else
	echo "NTP not Synchronized"
	exit 1
fi

/-------------------------------------------------------------------------------------------------------------------------/
Vet inte ifall du ville ha denna, men om intressant: Varsågod :)

root@server:~# cat user_autofs
#!/bin/bash

while read line
do
	name=""	
	namearray=(${line,,| tr -dc})
	namearray[0]=${namearray[0],,}
	namearray[1]=${namearray[1],,}
	unique=0	
	while [ $unique -eq 0 ]
	do
		rand_val=$((RANDOM % 999))
		name=${namearray[0]:0:2}${namearray[1]:0:2}$rand_val
		if getent passwd $name > /dev/null 2>&1; then
			echo "User exists, re-attempting to make user."
		else
			unique=1
		fi
	done

	user_password=$(pwgen 12 1)	 
	
	useradd --shell /bin/bash -m -d /home/$name -p `openssl passwd -1 $user_password` ${name}
	mv /home/${name} /home1
	echo -e "Name: ${name}\t Password: $user_password"
done

make -C /var/yp
systemctl restart autofs

/-------------------------------------------------------------------------------------------------------------------------/