Need help before i crack up!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help before i crack up!
# 1  
Old 03-03-2009
Need help before i crack up!

Hi guys, i'm new to the forum, i need a script badly everything i try is awful as i'm new to this and usually i jump in at the deepend....however this unix scripting has got the better of me...hope someone can help!

firstly the script will prompt the user for a filename in the current directory, if the file exists it will then prompt for a directory in which to copy the file, if the directory does not exist one will be created and then the file will be copied...and also inform the user if the file was not found.

If anyone can help with this i would greatly appreciate it....i don't have any code as everything i've tried fails and i delete it.
# 2  
Old 03-03-2009

Why don't you have any code? Surely there are some parts of the problem that you can solve.

The first thing to do is to break down the problem into its individual parts, then write the code for each one;

Code:
## print the prompt

## read the user's input

## check that the file exists

## prompt for directory

## check for directory's existsence

## if necessary, create directory

## copy the file

# 3  
Old 03-03-2009
I got as far as this but when i tried to prompt for a directory it shuts back down to the menu, as i say i'm very new to this...almost ashamed to post such pathetic code.

echo "Enter file name: ";
read fname;

if [ -f $fname ];
then
# 4  
Old 03-03-2009
Ok... so start with what you have and build on it
Code:
#!/bin/sh

## print the prompt
echo "Enter file name:";

## read the user's input
read FNAME;

## check that the file exists
if [ -f $FNAME ]; then
   echo "$FNAME found"

   ## prompt for directory
   DO SOMETHING

   ## check for directory's existsence
   DO SOMETHING

   ## if necessary, create directory
   DO SOMETHING

   ## copy the file
   DO SOMETHING

   exit
fi

## do something if the file does not exist
echo "$FNAME not found"
exit

# 5  
Old 03-03-2009
Quote:
Originally Posted by Alendrin
I got as far as this but when i tried to prompt for a directory it shuts back down to the menu, as i say i'm very new to this...almost ashamed to post such pathetic code.

Please put code inside [code] tags.
Quote:
Code:
echo "Enter file name: ";


Code:
You don't need the semi-colons.

Quote:
Code:
    read fname;
 
if [ -f $fname ];
then


Once you finish the if statement, you are half way there.

Code:
if [ -f $fname ]
then
  : do whatever
fi

The next section is simply a repetition of what you already have with slight variations.
# 6  
Old 03-03-2009
Thanks for help much appreciated, i will crack on now....probably be crying back here at sometime tomorrow though!
# 7  
Old 03-04-2009
started new thread
https://www.unix.com/shell-programmin...g-problem.html



New problem:

when the file is not found i want it to return to the menu, however it carries out the next line when i hit a key

Iknow its probably something simple can anyone help?

here is my pause function: function pause(){
read -s -n 1 -p "Press any key to return to Menu . . ."
echo
}

SCRIPT CODE

echo "Enter file name: "
read fname;

if [ -f $fname ]; then
echo "$fname found"
else
echo "$fname not found"
pause
fi
echo "Enter directory for file to be copied to: "
read dname;
if [ -d $dname ]; then
cp $fname $dname
echo "file copied"
sleep 5
else
echo "$dname not found"
sleep 5

fi;;

Last edited by Alendrin; 03-04-2009 at 09:41 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. Red Hat

Need to crack username and password on laptop

I am not a computer geek but I recently was given a Dell Latitude c400 laptop which has Red Hat Linux 2.4.20-6 GRUB Version 0.93. First of all I have no clue how to even use this operating system and I was never given the username or password. Is there anyone out there who could possibly help me... (4 Replies)
Discussion started by: missfixit74
4 Replies

2. What is on Your Mind?

Can you crack it?

Inspired by the GCHQ talent spotting code-cracker competition :eek:, here is my own little brain puzzler for budding cracker enthusiasts. Can you crack this code? If you think you know the answer, post it here (edited). There are no rewards, short of the feeling of smugness and some potential... (2 Replies)
Discussion started by: cambridge
2 Replies

3. SCO

Reset root OR crack old sco 3.2 machine

I have an old compaq running sco 3.2. the old IT guy died and we need to reset the password OR crack into the machine. I have tried mscreen and at exploits but can't seem to get them to work. I have access with other user accounts. This is a machine we own. (4 Replies)
Discussion started by: herot
4 Replies

4. Red Hat

John the Ripper / CRACK

Has anyone used JTR or CRACK to check if you have any weak passwords on your Red Hat Servers? If so can I ask some basic questions? Or would this question be better pitched in another area of the Forum, if so please suggest where, if anyone is willing to help me in this forum please let me know... (1 Reply)
Discussion started by: stevej123
1 Replies

5. Cybersecurity

WEP Crack Appz

Looking for a good app to go with my iBook/Airport Extreme card for testing WEP security on my own network... I have had a lot of luck with MacStumbler, but none with KisMAC... any suggestions? Jeffrey d9rw1n:/ root#grep ghost There's nothing like bludgeoning your self with a new box...... (0 Replies)
Discussion started by: f1r3g0dz
0 Replies

6. UNIX for Dummies Questions & Answers

nvram reset or crack password

Hello guys ,and girls. Im having a very interesting problem. I have a Netra SUN machine and i had it here for quite a while now...i wanted to install it as a new server and todo so i needed to mount a cd rom and to change the boot at the prom level to cdrom. this could work but i forgot the... (5 Replies)
Discussion started by: talroze
5 Replies
Login or Register to Ask a Question