Tuesday, September 22, 2009
Posted by venu k
1 comment | 10:22 PM
#!/bin/bash# sys_monitor2.sh# Usage: sys_monitor2.sh [-u|-d|-f (D/M)| -c number | -m number]# Sample system monitor script using options# Tested under Fedora 9Invalidoptions(){ echo "Usage: `basename $0` [OPTIONS]" echo "OPTIONS:" echo -e "\t -d for display today's date" echo -e "\t -u for Logged in users list" echo -e "\t -f ARG for Disk and Memory Statistics" echo -e "\t (ARG=D for disk statistics; ARG=M for memory statistics)" echo -e "\t -c ARG for Top CPU consuming process" echo -e "\t (ARG=10 means top 10...
Posted by venu k
12 comments | 9:31 PM
#!/bin/bash# sys_monitor.sh# Sample system monitor script using menu# Tested under Fedora 9## Create the following menu and clear the screen each time it appears#clearecho -e "\033[1m `uname -or` Monitor script\033[0m"items=" 1.Date 2.Current Users 3.Disk Statistics 4.Memory Statistics 5.Top 10 Memory consuming process 6.Top 10 CPU consuming process 7.Exit"exit_function(){ clear exit}#function enter is used to go back to menu and clear screenenter(){ ans= echo "" echo -e "Do you want to continue(y/n):\c"...
Saturday, September 19, 2009
Posted by venu k
78 comments | 10:33 AM
#!/bin/bash# isuserloggedin.sh# Usage: isuserloggedin.sh username# Shell script which checks after every one minute whether a user has logged in# or not# You can also run script in background using & then foreground it to view resultif [ $# -ne 1 ]then echo "You supplied wrong arguments" echo "usage : `basename $0` username"exit 1fiisuserexist(){grep -w "$1" /etc/passwd > /dev/nullif [ $? -eq 1 ]then echo "$1 is not a valid user"exit 1fi}isuserexist $1time=0while truedo# you can replace following two statements with# if `who|grep...
Posted by venu k
12 comments | 10:11 AM
#!/bin/bash# validuser.sh# Usage: validuser.sh username# Script to check whether suplied user has an account in your systemif [ $# -ne 1 ]then echo "You supplied wrong arguments" echo "Usage : `basename $0` user_name"exit 1fi#grep -w "$1" /etc/passwd > /dev/nullgrep -w "^$1" /etc/passwd > /dev/nullif [ $? -eq 1 ]then echo "$1 is not a valid user"else echo "$1 is a valid user"fi# Using greps -q option you can simplify and faster your script# if `grep -qw "^$1" /etc/passwd`# greps -q option prints nothing just returns exit status 0...
Wednesday, September 2, 2009
Posted by venu k
8 comments | 1:25 PM
There are various ways to read input within the time limit in shell script. I am posting 4 methods here.First three are direct methods. Final one implemented with some logic, just for practice only.Method 1: #!/bin/bash # timedinput1.sh: prompts times out at five seconds. # Using read command timelimit=5 echo -e " You have $timelimit seconds\n Enter your name quickly: \c" name="" read -t $timelimit name #read -t $timelimit name <&1 # for bash versions bellow 3.x if [ ! -z "$name" ] then ...
Subscribe to:
Posts (Atom)