Skip to content

Instantly share code, notes, and snippets.

@helloqiu
Created April 25, 2016 10:24
Show Gist options
  • Save helloqiu/39d1cfc982ae619a443fdc966f1fe5f7 to your computer and use it in GitHub Desktop.
Save helloqiu/39d1cfc982ae619a443fdc966f1fe5f7 to your computer and use it in GitHub Desktop.
A small shell to manage something.
#! /bin/bash
max_space_user(){
du -s /home | sort -nr | head -1
}
max_file(){
find -type f -exec stat -c "%s %n" {} \; | sort -nr | head -1
}
find_cpp(){
for file in `ls $1 | egrep -e '\.(cpp|h)$'`
do
stat -c "%s %n" $file
done
}
find_user(){
expr `w $1 | grep -c ""` - 2
}
some_service(){
if test $1 -eq "start"
then
service vsftpd start
service httpd start
elif test $1 -eq "status"
then
service vsftpd status
service httpd status
elif test $1 -eq "stop"
then
service vsftpd stop
service httpd stop
else
echo "illegal parameter $1"
fi
}
temp=0
while test $temp -ne -1
do
echo "1. Find max space user"
echo "2. Find the max file"
echo "3. Find .cpp and .h"
echo "4. Get the number of the user's terminal"
echo "5. Get the status or stop or start Ftp or Http service"
echo "-1. Quit"
read temp
temp=`expr $temp + 0`
if test $temp -eq 1
then
max_space_user
elif test $temp -eq 2
then
max_file
elif test $temp -eq 3
then
echo "Please enter the path"
read temp_path
find_cpp $temp_path
elif test $temp -eq 4
then
echo "Please enter the username"
read temp_username
find_user $temp_username
elif test $temp -eq 5
then
echo "Please enter the command (status|stop|start)."
read temp_command
some_service $temp_command
elif test $temp -eq -1
then
echo "Bye~"
else
echo "unknown command number"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment