Search

Thursday, August 21, 2008

All time 101 linux commands

Below is 101 Linux commands. As soon as, I get some time I will add description with output of all commands. Please help me to add few more commands and let's touch 500 commands.

1. cat
2. useradd
3. vi
4. kibitz
5. tar
6. gzip
7. gunzip
8. grep
9. head
10. tail
11. more
12. less
13. chmod
14. chown
15. ifconfig
16. awk
17. sed
18. cut
19. service
20. tr
21. paste
22. diff
23. pipe |
24. date
25. cal
26. alias
27. set
28. export
29. touch
30. mount
31. uname
32. free
33. df
34. du
35. rpm
36. last
37. locate
38. find
39. ps
40. top
41. tcpdump
42. ls
43. logout
44. login
45. rlogin
46. telnet
47. ftp
48. history
49. cp
50. cmp
51. cksum
52. rm
53. mount
54. echo
55. uniq
56. sort
57. hostname
58. wget
59. rsync
60. cd
61. ssh
62. scp
63. bzip2
64. which
65. whereis
66. who am i
67. who
68. wc
69. type
70. traceroute
71. tee
72. su
73. sudo
74. split
75. pwd
76. ping
77. nsloopup
78. nice
79. mv
80. mkdir
81. man
82. info
83. init
84. setup
85. chkconfig
86. clear
87. crontab
88. dir
89. fdisk
90. dos2unix
91. expr
92. expand
93. mc
94. wall
95. watch
96. uptime
97. bc
98. ln
99. kudzu
100. kill
101. pkill

Tuesday, August 19, 2008

shell script to check Server Status

#!/bin/bash
clear
#Global variable
#Please enter the free memory you want to keep in server else mail will send
FMEM=10
#Please Enter free disk Space in MB
FDSK=1000
#Your Default Gateway
DGATE=20.12.31.101
#Please enter the email address
EMAIL=mailtodaman@gmail.com
#Enter the name of the http server you want to monitor.
SNAME=http://linuxguruji.blogspot.com
#Your SMTP Service
SMTP=mailtodaman@gmail.com
#Default Time for SMTP
SEL=5

TMEM=`free -m | awk '{ print $2}' | head -n 2 | tail -1`
echo "Total Memory(Mb) in your system is -->" $TMEM

MEM=`free -m | awk '{ print $4}' | head -n 2 | tail -1`
echo "Free Memory(Mb) in your system is -->" $MEM

FDSK=`df -h | awk '{ print $4}' | head -n 2 | tail -1`
echo "Free HardDisk(Kb) in your System is -->" $FDSK
FDSKK=`df | awk '{ print $4}' | head -n 2 | tail -1`
last | awk '{ print $3}' > a.bat
w | grep pts | awk '{ print $3}' > current.bat


if [ "$MEM" > "$FMEM" ]; then
mail -s " Critical --> Your server memory " $EMAIL <<> "$FDSKK" ]; then
mail -s " Critical --> Your server HDD " $EMAIL <<> Your server Has Hacked " $EMAIL <<>> last.bat

fi
done

for uname1 in $(cat current.bat);
do if [ "$DGATE" != "$uname1" ]; then
mail -s " Critical --> Your server Has Hacked " $EMAIL <<>> last1.bat


fi
done
if ! $(lynx -head -dump "$SNAME" 2> /dev/null | head -1 \
| grep ' 200 ' > /dev/null )
then
mail -s " Critical --> Your site is down " $EMAIL <<> mtest.bat



for uname2 in $(cat mtest.bat);
do if [ "$SMTP" = "$uname2" ]; then
mail -s " Critical --> Your SMTP Service " $EMAIL << EOF
Hello,
Your SMTP Service is not working fine.
Regards,
System Admin
EOF


fi
done

Arguements check

#!/bin/bash
if [ -z "$1" ]
then
echo "Oops! Sorry no arguement $0"
exit
fi

While Example

#!/bin/bash
c=0
while [ $c -lt 100 ]
do
echo "counter is $c"
let c=c+1
done

list of users and count total number of users

#!/bin/bash
for i in $(cat /etc/passwd | cut -d: -f 1) ; do
echo username:$i

done
echo "Total number of user is $(cat /etc/passwd | wc -l)"

File description

if [ $# -ne 1 ]
then
echo "Argument not given"
exit 0
else

Filename=$1
if [ -f $1 ]
then
echo "File Name is $1"
echo "Owner is $(ls -la $Filename | awk '{print $3}')"
echo "Group is $(ls -la $Filename | awk '{print $4}')"
echo "Size is $(ls -hls $Filename | awk '{print $1}')"
echo "Inode number is $(ls -ils $Filename | awk '{print $1}')"
echo "File type is $(file $1)"
echo "File is mounted in $(df -h $Filename | grep -v Mou | awk '{ print
$6}')"

else
echo "Oops! $1 doesn't exist"
fi
fi

check if I am xyz user or not

if [ "$(whoami)" != 'xyz' ]; then
echo "You are not xyz user."
exit 0
fi