Check My Script

Bash : Whats wrong with my script?

Page 1 of 1

1 Replies - 776 Views - Last Post: 25 February 2009 - 11:53 AM Rate Topic: -----

#1 Delta_Echo  Icon User is offline

  • D.I.C Addict

Reputation: 5
  • View blog
  • Posts: 722
  • Joined: 24-October 07

Check My Script

Posted 25 February 2009 - 09:18 AM

Just learning bash scripting and I wrote a simple script to scrub a harddrive to writting random values to the device.
Using "Linux shell Scripting With Bash" as a guide I wrote this:
 
# !/bin/bash 
# 
# hdds.sh 
# A hard drive scrubbing utility.
# written by James M. Thigpen (delta435@gmail.com)

# hdds <target> 

# !WARNING! | DESTROYS ALL DATA ON TARGET DEVICE | !WARNING! 
# step 1: is user argument valid?
if $# -lt 2; then
printf "%q" "Too Few Arguments!"
printf "%q" "hdds <target>"
fi

# step 2: is the user willing to continue? 
if "$3" != "-y"; then
   printf "WARNING : THIS WILL DESTROY ALL DATA ON $2 : WARNING"
   printf "Do you wish to continue? <Y/N> [ENTER]"
   read resp
	if ["$resp" != ["Y" || "y"]]; then
	exit 1
	#Script ends here
	fi
fi

# Step 3: Does device exist?
if -f $2; then
   #begin scrub 
 export counter = 0
  while [count -lt 20]; do
   export val1 = $RANDOM
   cat val1 > $2
   let "counter=counter+1"
  done
fi

printf "Done."
exit 0;
#END 


On execution I get this:
/home/devel/Development/Bash/hdd_scrub/hdds.sh: line 11: 1: command not found
/home/devel/Development/Bash/hdd_scrub/hdds.sh: line 17: : command not found
/home/devel/Development/Bash/hdd_scrub/hdds.sh: line 28: -f: command not found



Whats wrong here?
Thanks :D

This post has been edited by Delta_Echo: 25 February 2009 - 09:18 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Check My Script

#2 horace  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 290
  • View blog
  • Posts: 1,900
  • Joined: 25-October 06

Re: Check My Script

Posted 25 February 2009 - 11:53 AM

the if statements needed some correction, try
# !/bin/bash
#
# hdds.sh
# A hard drive scrubbing utility.
# written by James M. Thigpen (delta435@gmail.com)

# hdds <target>

# !WARNING! | DESTROYS ALL DATA ON TARGET DEVICE | !WARNING!
# step 1: is user argument valid?
if [ $# -lt 2 ];then
echo "%q" "Too Few Arguments!"
echo "%q" "hdds <target>"
fi

# step 2: is the user willing to continue?
if [ "$3" != "-y" ]; then
   printf "WARNING : THIS WILL DESTROY ALL DATA ON $2 : WARNING"
   printf "Do you wish to continue? <Y/N> [ENTER]"
   read resp
	if [ $resp != "Y" ]  && [ $resp != "y" ] ; then
	exit 1
	#Script ends here
	fi
fi

# Step 3: Does device exist?
if -f $2; then
   #begin scrub
 export counter = 0
  while [count -lt 20]; do
   export val1 = $RANDOM
   cat val1 > $2
   let "counter=counter+1"
  done


printf "Done."
exit 0;
#END

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1