Other Shell Scripts
========================== list-users-crond.sh ========================
#!/bin/bash
# List all the user cronjobfor user in $(cut -f1 -d: /etc/passwd); do crontab -u $user -l; done >> /opt/scripts/usercronjob.txt
=================== 1. Check parameter are supplied.sh ==================
#!/bin/bash
# Checking if 2 parameters are supplied
if (! test $1)
then
echo "Usage: $0 username domainname"
exit 1
fi
if (! test $2)
then
echo "Usage: $0 username domainname"
exit 1
fi
================= 2. Check parameter are supplied.sh ======================
#!/bin/bash
# Checking if 2 parameters are supplied
USAGE="Usage: $0 username domainname"
if (! test $1 || ! test $2)
then
echo $USAGE
exit 1
fi
============ user-info.sh ===========
#!/bin/bash
read -p "Enter User Name: " n
while IFS=: read -r f1 f2 f3 f4 f5 f6 f7
do
[ "$n" == "$f1" ] && echo "Welcome ${f5%%,*}"
done </etc/passwd
echo "Your Home Directory Is: $HOME"
echo "Your Working Directory Is: $PWD"
echo "Your Current Processes Are: $PS"
=============== run-with-root.sh ==============
#!/bin/bash
# This is script is going to check the VirtualHost exit ot not.
# Checking for user
if [ "$(whoami)" != 'root' ]; then
echo "You have no permission to run $0 as non-root user.Log in as user root or Use sudo !!!"
exit 1;
fi
================ user-act.sh =================
#!/bin/bash
if whoami | grep -v root >> /dev/null; then
echo "you have to be root to use this"
exit 1
else
cat /etc/passwd | cut -f1 -d : | grep -v halt | grep -v operator | \
grep -v root | grep -v shutdown | grep -v sync | grep -v bin | \
grep -v ftp | grep -v daemon | grep -v adm | grep -v lp | \
grep -v mail | grep -v postmaster | grep -v news | grep -v uucp | \
grep -v man | grep -v games | grep -v guest | grep -v nobody > user.list
fi
for USER in `cat user.list`; do
if cat /home/$USER/.bash_history | grep passwd >> /dev/null; then
echo
echo "user $USER have tried to access the passwd file"
echo "do you want to remove $USER from your system [y/n] "
read YN
if [ "$YN" = "y" ]; then
echo "user $USER is being deleted"
echo "home dir of user $USER is however intact"
echo
remuser $USER
else
echo "user $USER is not deleted"
echo
fi
else
echo "$USER haven't tried to access the passwd file"
fi
done
rm user.list
echo
echo "Script finished"
echo
exit 0
================ check-a-word.sh =================
#!/bin/bash
FILE=/root/shell.txt
grep -w "nixcraft" $FILE >/dev/null
if [ $? -eq 0 ]
then
echo "Word found!"
else
echo "Word NOT found!"
fi
================ check-a-word.sh =================
#!/bin/sh
file=/root/shell.txt
word="linux"
if [ -f "$file" ]; then
echo "File $file does not exist."
exit 1
fi
cmd=$(grep -ci "$word" $file)
if [ "$cmd" != "0" ]; then
echo "Word exists"
else
echo "Word does not exist."
fi
================ Start-stop-service.sh =================
#!/bin/bash # # description: SERVICE_NAME DAEMON=/path/to/SERVICE_NAME/bin/SERVICE_NAME case "$1" in start) $DAEMON start ;; stop) $DAEMON stop ;; status) $DAEMON status ;; restart) $DAEMON stop sleep 1 $DAEMON start ;; *) echo "Usage: $0 {start|stop|status|restart}" exit 1 ;; esac exit 0
No comments:
Post a Comment