Installation Script for Basic System Info


Basic System Info Script
#!/bin/bash
echo “Info about the server” > /home/Info.txt
date >> /home/Info.txt
uname -a >> /home/Info.txt
cat /etc/network/interfaces >> /home/Info.txt
route >> /home/Info.txt

Path Details
cd /home
Check This File vim Info.txtScreenshot_2016-04-04_12-42-35

Output Details
Vim Info.txtScreenshot_2016-04-04_12-42-17

Advertisements

Linux System Information Script


#!/bin/bash

clear

echo “Hello, $USER”
echo

echo “Today’s date is date, this is week date +"%V".”
echo

w | cut -d ” ” -f 1 – | grep -v USER | sort -u
echo

echo “This is uname -s running on a uname -m processor.”
echo

echo “This is the uptime information:”
uptime
echo

echo “Free memory:”
free
echo

echo “Disk usage:”
df -kh
echo

Creating New Linux User Script


#!/bin/bash

while [ x$username = “x” ]; do
read -p “Please enter the username you wish to create : ” username
if id -u $username >/dev/null 2>&1; then
echo “User already exists”

username=””
fi
done
while [ x$group = “x” ]; do
read -p “Please enter the primary group. If group not exist, it will be created : ” group
if id -g $group >/dev/null 2>&1; then
echo “Group exist”
else
groupadd $group
fi
done
read -p “Please enter bash [/bin/bash] : ” bash
if [ x”$bash” = “x” ]; then
bash=”/bin/bash”
fi
read -p “Please enter homedir [/home/$username] : ” homedir
if [ x”$homedir” = “x” ]; then
homedir=”/home/$username”
fi
read -p “Please confirm [y/n]” confirm
if [ “$confirm” = “y” ]; then
useradd -g $group -s $bash -d $homedir -m $username
fi

Deleting Empty Directories Script


#!/bin/bash

if [ x”$1″ = “x” ]; then
echo -n “Please enter directory where to delete empty folders: ”

while read dir
do
test -z “$dir” && {

echo -n “Please enter directory: ”
continue
}
break
done

else
dir=$1
fi
if [ ! -d $dir ]; then
echo “No such directory”
exit 1
fi

DirList=/tmp/ditlist.tmp
find $dir -type d > $DirList
dirs=cat $DirList
for dir in $dirs
do
[ ls $dir | wc -l -lt 1 ] || continue
echo -n “Remove empty directory $dir: [No/yes] ”
read answer
if [ “$answer” = “yes” ]; then
rmdir “$dir”
fi
done

Adding Proxy for Ftp, Http & Https Script


#!/bin/bash

proxyset=$http_proxy

proxy=”proxy.yoursite.com”
port=”3128″
username=”youruser”
password=”yourpass”

setproxy(){
setenv
setfile
}

setenv(){
if [ -n “$username” ]; then
proxy=”http://$proxy:$port/
else
proxy=”http://$username:$password@$proxy:$port/
fi

export http_proxy=$proxy
export HTTP_PROXY=$proxy
export https_proxy=$proxy
export HTTPS_PROXY=$proxy
export ftp_proxy=$proxy
export FTP_PROXY=$proxy
export all_proxy=$proxy
export ALL_PROXY=$proxy
echo “proxy added”
}

setfile(){
#edit info in the file
echo “Acquire::http::proxy \”$proxy\”;\nAcquire::ftp::proxy \”$proxy\”;\nAcquire::https::proxy \”$proxy\”;” | sudo tee /etc/apt/apt.conf.d/95proxies
}

removeproxy(){
removeenv
removefile
echo “proxy removed”
}

removeenv(){
unset HTTP_PROXY
unset http_proxy
unset HTTPS_PROXY
unset https_proxy
unset ftp_proxy
unset FTP_PROXY
unset all_proxy
unset ALL_PROXY
}

removefile(){
sudo bash -c “rm /etc/apt/apt.conf.d/95proxies”
sudo bash -c “rm /etc/apt/apt.conf.d/95Proxies”
}

if [ -n “$proxyset” ];
then
removeproxy
else
setproxy
fi

Linux Server Utilization


#!/bin/bash

date;
uptime

Currently connected
w

Last logins
last -a |head -3

Disk & Memory Usage
df -h | xargs | awk ‘{print “Free/total disk: ” $11 ” / ” $9}’
free -m | xargs | awk ‘{print “Free/total memory: ” $17 ” / ” $8 ” MB”}’
start_log=head -1 /var/log/messages |cut -c 1-12
oom=grep -ci kill /var/log/messages
echo -n “OOM errors since $start_log :” $oom

Utilization & Processes
top -b |head -3
echo
top -b |head -10 |tail -4

Open TCP Ports
nmap -p- -T4 127.0.0.1

Current Connections
ss -s

Processes
ps auxf –width=200

vmstat
vmstat 1 5