#!/bin/bash# check character divice filesif[-c/dev/tty];thenecho"yes '/dev/tty' is a character device"fi# check block divice filesif[-b/dev/sda];thenecho"yes '/dev/sda' is a block device"fi# check character divice files# mkfifo /tmp/pipefif[-p/tmp/pipef];thenecho"yes '/tmp/pipef' is a pipeline device"fi# check symbolic link filesif[-h/usr/bin/java];thenecho"yes '/usr/bin/java' is a symbolic link"fi# check symbolic link filesif[-L/usr/bin/java];thenecho"yes '/usr/bin/java' is a symbolic link"fi# check socket filesif[-S/run/cups/cups.sock];thenecho"yes '/run/cups/cups.sock' is a socket file"fi# check readable filesif[-r/etc/passwd];thenecho"yes '/etc/passwd' is a readable file"fi# check writable filesif[-w/etc/passwd];thenecho"yes '/etc/passwd' is a writable file"fi# check executable filesif[-x/bin/bash];thenecho"yes '/bin/bash' is a executable file"fi# check modifaction filesif[-N/bin/bash];thenecho"yes '/bin/bash' has been modified"fi# check SUID filesif[-u/usr/bin/passwd];thenecho"yes '/usr/bin/passwd ' has s-user-id"fi# check SGID filesif[-g/usr/bin/wall];thenecho"yes '/usr/bin/wall' has s-group-id"fi# check sticky bite filesif[-k/tmp];thenecho"yes '/tms' has has active sticky bit"fi# check the file existsif[-e/etc/passwd];thenecho"yes '/etc/passwd/' is exists"fi# check file exists and a directoryif[-f/etc/passwd];thenecho"yes '/etc/passwd' is exists and also is a file"fi# check file exists and a directoryif[-d/etc];thenecho"yes '/etc' is a file and also is a directory"fi# check file exists and readableif[-s/etc/passwd];thenecho"yes '/etc/passwd' is a file and also has content"fi# check file ownerif[-O/etc];thenecho"yes '/etc' is for mehrdad"elseecho"no '/ect' for root"fi# check file groupif[-G/etc];thenecho"yes '/etc' in mehrdad group"elseecho"no '/ect' in root group"fiif[-f/etc/passwd]||[-r-x/etc/passwd];thenecho"yes"elseecho"no"fiif[!-d/var/log];thenecho"directory '/var/log' does not exist"elseecho"directory '/var/log' exists"fi
#!/bin/bashif[$#-ne1];thenecho"your input arguments are not equel to 1"echo"usage: $0 start|stop|restart|status"exit1fiif[$1="start"];thenecho"going to start service..."elif[$1="stop"];thenecho"going to stop service..."elif[$1="restart"];thenecho"going to restart service..."elif[$1="status"];thenecho"going to status service..."elseecho"sub-commnad is not found."exit1fi
#!/bin/bashtestuser=$1# grep generate exit-code 0 if the condition is true# if grep $testuser /etc/passwd; then# echo "user $testuser has been found"# else# echo "user $testuser does not exists"# fi# ---# if [ $testuser -eq 1 ]; then# echo "$1 is euqel with 1"# elif [ $testuser -lt 1 ]; then# echo "$1 is less then 1"# elif [ $testuser -gt 1 ]; then# echo "$1 is greather then 1"# else# echo "false"# fi# ---if[$(echo"2>1"|bc)-eq1];thenecho"yes"elseecho"no"fi
#!/bin/bashif[$#-ne1];thenecho"your input arguments are not equel to 1"echo"usage: $0 start|stop|restart|status"exit1ficase$1instart)echo"going to start service...";;stop)echo"going to stop service...";;restart)echo"going to restart service...";;status)echo"going to status service...";;*)echo"sub-commnad is not found."exit1;;esac
#!/bin/bashPS3="Enter the value: "selectitemin"option1""option2""exit"docase$itemin"exit")break;;"option1")"option-1 is selected";;"option2")"option-2 is selected";;*)clear
echo"wrong selection";;esacdone
#!/bin/bashfunctiondiskspace(){clear
df-kh
}functionwhoison(){clear
who
}functionmemusage(){cat/proc/meminfo
}functioncpuinfo(){cat/proc/cpuinfo
}PS3="Enter your command: "commands=(cpuinfomeminfodiskinfoonline_usersexit)selectcommandin${commands[@]};docase$commandin"meminfo")memusage
;;"cpuinfo")cpuinfo
;;"diskinfo")diskspace
;;"online_users")whoison
;;"exit")break;;*)echo"wrong selection";;esacdone
#!/bin/bash# C stylefor((c=1;c<=10;c++));doecho"C is $c"doneecho"---"# python styleforpin{1..20..2};doecho"P is $p"doneecho"---"# for in listforcolorinredgreenblue;doecho"color is $color"done
#!/bin/bash# file as a listlc=1forlinein$(tail-5/etc/passwd);dousername=$(echo$line|cut-d":"-f1)echo"$lc username: $username"lc=$(($lc+1))doneecho"---"IFS=$'\n'lc=1forlinein$(tail-5/etc/services);doecho$lc$line|cut-d":"-f1
lc=$(($lc+1))doneecho"---"forfin/etc/*;doif[!-r$f];thenecho"file $f is not readable"fidoneecho"--- show hostname ips by type ---"IPS=$(hostname-i)forxin$IPS;docase$xin*"."*)echo"IPv4S $x";;*":"*)echo"IPv6 $x";;esacdone
#!/bin/bashread-p"pleas enter a number: "no
for((c=0;c<no;c++));doecho"Hello $c"doneecho"---"forcountin$(seq1$no);doecho"Hi $count"done
#!/bin/bashcount=10while[$count-ge1]doecho$countcount=$[$count-1]doneecho"---"whileread-n1-r-p"choose Yes|No or e for exit "&&[[$REPLY!=q]];docase$REPLYiny)echo"Yes";;n)echo"No";;e)exit;;*)echo"What?";;esacdone
#!/bin/bashanswer=""while["$answer"!="yes"]&&["$answer"!="no"];doecho"do you want to exit? yes|no "readanswer
answer=`echo$answer|tr[A-Z][a-z]`done
#!/bin/bashecho"\$0 your script name is $0"echo"\$1 your first parameter is $1"echo"\$2 your second parameter is $2"echo"\$# you entered $# input parameter"echo"\$? current status code is $?"echo"'\$*' is $*"echo"'\$@' is $@"
#!/bin/bashif[$#-ne1];thenecho"miss or more input argument!"echo"exact argument is one"exit1fiquery=`cut-d:-f1/etc/passwd|grep-x"$1"`if[${#query}-ne0];thenecho"user $1 has been found"exit0elseecho"user $1 does not exitst"exit1fi
#!/bin//bashwhile[-n"$1"];docase"$1"in-a)echo"found -a option";;-b)echo"found -b option";;-c)echo"found -c option";;*)echo"$1 is not define";;esacshiftdone