Script problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script problem
# 1  
Old 11-21-2011
Script problem

Hi all,

I have a script that I was using in Mandriva and my script worked perfectly well but then I changed to using Puppy Linux and it isn't running the way I thought it would.

In Puppy Linux operating system I've encountered a few problems, first problem is the elif for option B isn't being recognised, only option A and i am receiving a error saying 'tar: removing the leading '/' from member names' and the third problem I am getting is that when I attempt to back up it seems to be trying to read instead of backing up.

This script worked perfectly well in Mandriva and I used it but since moving to Puppy it's not working the way it should. Any ideas as to where I'm going wrong would be amazing, thanks! Smilie


Code:
if [ $REPLY = A ]
then

	echo -n "Enter the name of the folder to be backed up: "
	read dir_name

	until [ -d "$dir_name" ]
	do
		echo "Please enter a valid folder name : "
		read dir_name

	done


	echo -n "Enter the Directory name of where you would like it backed up to : "
	read dir_name2

	until [ -d "$dir_name2" ] 
	do 
		echo "Please enter a valid folder name : "
		read dir_name2
	done

	tar -cvf  $dir_name2
	echo "Your backup done"
	echo Would you like any further options? - choose Y or N
	read ANSWER

	while [ "$ANSWER" != Y -a "$ANSWER" != N ]
	do
		echo "You must enter Y or N - Try again "
		read ANSWER
	done
	if [ "$ANSWER" = Y ]

	then
		source script
	else
		exit
	fi

elif [ $REPLY = B ]
then
	echo   Enter the directory name of where the backup is located :
	read dir_name2

	until [ -d "$dir_name2" ]

	do 
		echo "Please enter a valid backup name : "
		read dir_name2
	done

	ls -al $dir_name2
	echo -n "Enter the File name to be restored : "
	read filename
	until  [ -f "$dir_name2/$filename" ]

	do 
		echo "Please enter a valid filename : "
		read filename
	done
	tar -vxf $dir_name2/$filename

I didn't want to upload the whole code, so I narrowed it down to the part that I think is throwing up the problem.

Thanks
# 2  
Old 11-21-2011
Run the script with set -x turned on and post the output
# 3  
Old 11-21-2011
Hi, I would post the output however I'm running the software on a virtual machine as I brought the code home with me to try and fix and it's not allowing for copying and pasting between the host and the virtual machine.

I've fixed most of the problem however my elif still isn't working any ideas?
Code:
if [ $REPLY = A ]
then

	echo -n "Enter the name of the folder to be backed up: "
	read dir_name

	until [ -d "$dir_name" ]
	do
		echo "Please enter a valid folder name : "
		read dir_name

	done



	echo -n "Enter the Directory name of where you would like it backed up to : "
	read dir_name2

	until [ -d "$dir_name2" ] 
	do 
		echo "Please enter a valid folder name : "
		read dir_name2
	done

	tar -cvf  $dir_name2/ $dir_name 
	echo "Backup Complete"
THE CODE BELOW SEEMS TO BE THE PART OF THE CODE THAT ISN'T WORKING
elif [ $REPLY = B ]
then
	echo   Enter the directory name of where the backup is located :
	read dir_name2

	until [ -d "$dir_name2" ]

	do 
		echo "Please enter a valid backup name : "
		read dir_name2
	done

	ls -al $dir_name2
	echo -n "Enter the File name to be restored : "
	read filename
	until  [ -f "$dir_name2/$filename" ]

	do 
		echo "Please enter a valid filename : "
		read filename
	done
	tar -vxf $dir_name2/$filename 
	echo "File Restored"


Last edited by Chrissie; 11-21-2011 at 05:22 PM..
# 4  
Old 11-23-2011
Without seeing the specific error or the execution path of the code it
would be a bit difficult for me to help you.

I tested your if, elfi code in ksh and it appears to work fine for me?

How do you know the elif is where the problem is? Is there an erorr message?

If i would have to take a guess without the above information I mentioned
I would think the erorr would be tar -cvf $dir_name2/ $dir_name
since there is a space between $dir_name2 and $dir_name and that is
near your elfi

I would suggest taking "where you think" the problem is and putting that
peice of code into a standalone script and try running that. This may help
you narrow down the problem.

Last edited by BeefStu; 11-23-2011 at 01:25 PM..
# 5  
Old 11-23-2011
I fixed the elif error with the code but now the error that appears when I run is

tar: cowardly refusing to create an empty archive, however I know the archive isn't empty so have no idea why this error is running? I think it'll be easier for to switch back to operating system I was using to begin with as the code ran perfectly well there.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem in calling a script inside a script

Hi team, I have a script in different folder. Now i want to call that script and execute that script from that path alone. My code is #!/bin/bash wname=yahoo PATH='/opt/IBM' wac=`/usr/bin/ls $PATH | /usr/bin/grep "$wname"` STOP=`/usr/bin/find $PATH/$wac -type f -name "stop.sh"`... (8 Replies)
Discussion started by: natraj005
8 Replies

2. Shell Programming and Scripting

Shell script newbie, what is problem with my script?

Hello, Ubuntu server 11.10 can anybody help what is problem with my shell script? #!/bin/bash #script to find out currently logged on user is root or not. if ] then echo "You are super" else echo "You are awesome!" fi When I run script, I get following output ./uid: line 3: I... (4 Replies)
Discussion started by: kaustubh
4 Replies

3. Shell Programming and Scripting

Problem while calling a script within a script

Hi , I have moduled my scripts in three scripts . From First script i am calling second and from second i am calling third for some check . Problem is with the third script call. ---In second script EXP ='test.\abc.\Server.*abc.xml.*' pid=$($HOME/bin/checkpid $EXP) --Third... (2 Replies)
Discussion started by: amrishn
2 Replies

4. Shell Programming and Scripting

Problem running a program/script in the background from a script

Hi all, I have a script that calls another program/script, xxx, to run in the background. Supposedly this program at most should finish within five (5) minutes so after five (5) minutes, I run some other steps to run the script into completion. My problem is sometimes the program takes... (5 Replies)
Discussion started by: newbie_01
5 Replies

5. Shell Programming and Scripting

Problem with a script

Hi everyone, I got a problem with a script. What it's supposed to do is: to take as arguments a directory name <dir> and a dimension (in byte) <dim>; if <dir> exists, to write name and dimension of every regular file within it that sizes lesser than <dim> in regFileList. Nothing happens... (10 Replies)
Discussion started by: Luke Bonham
10 Replies

6. UNIX for Dummies Questions & Answers

Problem with script

Hello All. I have a script that is suppossed to start up a daemon but when executed, simply hangs. Could you please take a look and let me know where the problem might be? TIA ################################################################### # # SCRIPT: dstart3000.sh # Bring up the Domain... (6 Replies)
Discussion started by: grin1dan
6 Replies

7. Shell Programming and Scripting

call shell script from perl cgi script problem

hi,, i have perl scipt with line : system('./try.sh $t $d $m'); in shell scipt try.sh i have the line: echo $1 its not printing value of $t that i hav passed..y is it so..i am running it from apache web server (2 Replies)
Discussion started by: raksha.s
2 Replies

8. Shell Programming and Scripting

ssh script problem problem

Hi Please help me with the following problem with my script. The following block of code is not repeating in the while loop and exiting after searching for first message. input_file ========== host001-01 host001-02 2008-07-23 13:02:04,651 ConnectionFactory - Setting session state... (2 Replies)
Discussion started by: pcjandyala
2 Replies

9. Shell Programming and Scripting

Help. Script problem

hey guys. i have a bunch of programs in a script that needs to run as root and the rest as another user, we'll call him gabriel. now, in this script, i want to run the first few lines as root. now, how do i, after running as root, tell the script to run the remaining lines as the user gabriel?... (3 Replies)
Discussion started by: Terrible
3 Replies

10. UNIX for Dummies Questions & Answers

Problem starting a script from a 'main'-script

Please Help! :o I have a main script (ksh) where another script is called (convert_picture). Normally this works ok, but since some changes has been made on the unix-server (I dont know what :( ) suddenly it doesnt work anymore: i get an error message: ksh: convert_picture not found. I am... (3 Replies)
Discussion started by: Rakker
3 Replies
Login or Register to Ask a Question