The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Need Help Urgent SanjayLinux Shell Programming and Scripting 4 10-29-2007 02:41 AM
Help me for AWK URGENT readycpbala Shell Programming and Scripting 2 02-22-2007 01:03 PM
URGENT,URGENT- Need help tape drive installation sriny UNIX for Advanced & Expert Users 3 11-16-2006 03:43 PM
URGENT---URGENT--No OK PROMPt after RSC CONFIG sriny SUN Solaris 7 10-29-2006 11:06 AM
Urgent !! desiondarun UNIX for Dummies Questions & Answers 1 08-08-2006 09:49 AM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 02-15-2008
namishtiwari namishtiwari is offline Forum Advisor  
Registered User
  
 

Join Date: Aug 2007
Location: Bangalore
Posts: 377
need urgent help

Code:
Programname=$(basename $0)  # While scheduling to cron, program name is needed.

Usage="Usage: $Programname [-a mtDelete/mtBackup] [-l/-L Backuplocation] [-t now/cron/hh:mm]"

IsCronJob=1     # default, script will run at now.
isBackUp=0	# default, it will take back up.
lFlag=0		# it is optional. default value is zero
LFlag=0		# it is optional. dfault value is zero
ERR=1
 
LOGDIR="$INTAS_INSTALL_DIR/envsw/logs"
BackupLocation="$INTAS_INSTALL_DIR/mt_backup"

mtlogFile="/tmp/mtclean.log.$$"

if [[ $# -lt 1 ]];
then
	echo "$Usage"
	return $ERR
fi

if [[ ! -d $BackupLocation ]];
then
	mkdir -p $BackupLocation 2>/dev/null
fi

while  getopts a:l:L:t: optvar
do
	case $optvar in
	a) action="$OPTARG"
		if [[ $action = "mtBackup" ]];
		then
			isBackUp=1
		fi
		;;
	l) BackupLocation="$OPTARG"
		if [[ $lFlag -eq 1 ]]; then
			echo "Either option l or L should be given to $Programname"
			echo "$Usage"
			echo "$Programname is terminated"
			return $ERR;
		fi
		if [[ $isBackUp -eq 1 ]];
		then	
			givenPath="$BackupLocation"
			if [[ ! -d $BackupLocation ]];
			then
				echo "Non-existant directory specified"
				
				mkdir -p $BackupLocation >/dev/null 2>&1
	                        if [[ $? = 0 ]];
        	                then
					echo "$Prograname creates the dirctory $BackupLocation"
				else
					echo "$Programname could not able to create the directory $BackupLocation"
					return $ERR
				fi
			else
				echo "Backup directory already exists"
			fi
			lFlag=1
			Llcron=l
		else
			echo "$Programname is executed with -l option without action mtBackup"
			echo "$Usage"
			echo "$Programname is terminated"
			return $ERR
		fi
		;;
	L) BackupLocation="$OPTARG"
		if [[ $LFlag -eq 1 ]]; then
			echo "Either option l or L should be given to $Programname"
			echo "$Usage"
			echo "$Programname is terminated"
			return $ERR;
		fi
		if [[ $isBackUp -eq 1 ]];
		then
		        givenPath="$BackupLocation"
			BackupLocation=$BackupLocation/backup$(date +%w)
			if [[ ! -d $BackupLocation ]];
			then
				echo "Non-existant directory $BackupLocation"
				mkdir -p $BackupLocation >/dev/null 2>&1
	                        if [[ $? = 0 ]];
        	                then
					echo "$Prograname creates the dirctory $BackupLocation"
				else
					echo "$Programname could not able to create the directory $BackupLocation"
					return $ERR
				fi
			else
				echo "Backup directory $BackupLocation is already exists"
			fi
			lFlag=1
			Llcron=L
		else
			echo "$Programname is executed with -L option without action mtBackup"
			echo "$Programname is terminating"
			return $ERR;
		fi
		;;
	t) WhentoRun="$OPTARG"
		#echo "$WhentoRun"
		if [[ $WhentoRun = "cron" ]];
		then
			IsCronJob=1
			echo "$Programname is running from cron"
		elif [[ $WhentoRun = "now" ]];
		then
			IsCronJob=1
			echo "$Programname starts Now"
		else
			if /bin/echo $WhentoRun | egrep '^[0-9]{1,2}:[0-5][0-9]$' >/dev/null; then
	                	echo "$Programname is scheduled to $WhentoRun at cron"
				hour=$(/bin/echo $WhentoRun | cut -d: -f1)
				minute=$(/bin/echo $WhentoRun | cut -d: -f2)
				IsCronJob=0
			else
                        	echo "Incorrect time format, time must be in HH:MM format"
                        	return $ERR
                	fi
		
		fi
		;;
	*) echo $Usage
	   return $ERR 
	  	;;
	esac
done

if [[ ! -w $BackupLocation ]];
then
	echo "$BackupLocation is not writable"
	return $ERR;
fi

if whence $Programname >/dev/null; then
        : We found this program in the path
else
        echo "Unable to locate $Progname in the PATH, check the .kshrc for correctness"
	return $ERR
fi

cd $LOGDIR
if [[ $? != 0 ]]; 
then
        echo "Unable to cd to $INTAS_INSTALL_DIR/envsw, exiting..."
	return $ERR
fi

if [[ ! -d $LOGDIR && -w $LOGDIR ]];
then
	echo "$LOGDIR directory does not exist or not writable."
	echo "Please check the user permission"
	return $ERR
fi


# If mtclean is exceuted from cron or with option now, we can skip below scheduling part.
if [[ $IsCronJob -eq 0 ]]; 
then
        if (crontab -l 2>&1 1>/dev/null | grep 'not authorized'); 
	then
                echo "Unable to use cron, contact your system administrator"
                echo "Check that $(whoami) has an entry in cron.allow"
                return $ERR;
 	else
		cronfile="crontab"	
		cronfile="$INTAS_INSTALL_DIR/envs/tmp/cur_crontab$$"
	        crontab -l 2>&1 | grep -v '^crontab' >$cronfile
        	if grep "$Programname .* cron .*" $cronfile >/dev/null; then
                	tmpvar=$(grep -v "$Progname .* cron .*" $cronfile)
                	echo "$tmpvar" >$cronfile
        	fi

		#echo "Cron: $cronfile"
		echo "$minute $hour" '* * *' ". ~/.kshrc; $(whence $Programname) -a $action -$Llcron $givenPath -t cron >>$mtlogFile" >> $cronfile
        fi
	crontab $cronfile >/dev/null 2>&1
        if crontab -l | diff - $cronfile >/dev/null; then
                if [[ $WhenToRun != 24:00 ]]; then
                        echo crontab has been installed correctly
                else
			echo "Error in crontab entry"
		fi
	else
		echo "Error in installing crontab"
	fi
else
	curmonth=$(date +%b)
	curdate=$(echo "$(date +%c)" | cut -d' ' -f3)

	if [[ $curdate = "" || $curdate = " " ]];
	then
		curdate=$(echo "$(date +%c)" | cut -d' ' -f4)
		today="$curmonth  $curdate"
	else
		today="$curmonth $curdate"
			
	fi

	FileList=$(find . -type f -name "*")	# List all the files.
	
	echo "Starting moving/removing files from $LOGDIR"
        extrafiles1=$(ls mt.*.*.*.* 2>/dev/null) 
	extrafiles2=$(ls *core* 2>/dev/null)
	for file in $FileList
	do
		if [[ $(ls -l $file 2>/dev/null) = *$today* ]]; 
		then
			echo "Skips $file file. It is today's file"
			cp $file $BackupLocation 2>/dev/null
			cat /dev/null >$file
			continue
					        
		fi
	        
		if [[ $isBackUp -eq 1 ]];
		then
			mv $file $BackupLocation 2>/dev/null
			
		else
			rm $file $BackupLocation 2>/dev/null
                        
		fi
	done
when i am running the script it is not throwing any error but not giving me the desired output for the one case that is--

mt_clean -a mtbackup
or
mt_clean -a mtBackup

first of all it is taking both without displaying any error and taking the doing some weird thing which i do not want.
first of all it should display a message that mtbackup is specified without -l/-L option.

can anybody help me out in this.

Thanks
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:46 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0