Script does not execute properly

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions Script does not execute properly
# 1  
Old 08-10-2009
Script does not execute properly

I am trying to create a Unix script that when ran will provide a veiw of the files of the week that the user inputs, I have this one down. Then I would like them to be able to type in one of the files that is in that week and it displays that file. The script that I have keeps looping the week number until I hit q for quit and then it asks the user the name of the file they want to view, but does not display the contents. Some help would be appreciated. Thank you.

Course: POS 420/University of Phoenix

Code that I have been working with:

Code:
echo author : Goob
date

echo "Please enter week number (1-3) or q to quit"
read num

while test $num ! =q
do

       if [ $num -lt 4 ]
          then echo "The files submitted in week $num are:"
                     ls /mnt/sdb1/week$num/file*
          else echo "Incorrect week number!"

fi

echo "Please enter file name from chosen week"
read file

while test $file != q
do

      if [ -f /mnt/sdb1/week$num/$file ]
      then echo "The contents of file $file are:"
          cat /mnt/sdb1/week$num/$file
          break
      else read -p "Incorrect file name! Please select again or enter q:" file

fi

done


Last edited by DukeNuke2; 08-10-2009 at 06:08 PM..
# 2  
Old 08-10-2009
To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags [code] and [/code] by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums
# 3  
Old 08-10-2009
Hi.

Does the script output an error?

Question: In your first while loop, you write "ls /mnt/sdb1/week$num/file*"

Is the user expected to type "file" as part of the filename?

i.e. your cat in the second while is "cat /mnt/sdb1/week$num/$file"

So to see file "whatever", I'd have to type "filewhatever".

If the file is not being displayed, either there is an error, or the follow on prompt "Incorrect filename ... Please select again.... " would be given. Is it?
# 4  
Old 08-10-2009
is the following a typo in this forum, or is this the code as you wrote it?
Code:
while test $num ! =q

there's an inversion (of nothing really) followed by the equal to operator.
# 5  
Old 08-18-2009
Homework and coursework questions can only be posted under special homework rules.

Please review the rules, which you agreed to when you registered, if you have not already done so.


Thank You.

The UNIX and Linux Forums.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

File count script not working properly

Hi Experts, I have this script to count the number of files based on prefix and suffix values. #!/bin/ksh file_date=$1 prefix=$2 suffix=$3 file_count=$(ls -l /db/day_file/{$prefix}*${file_date}*{$suffix}) The files in the directory /db/day_file are as below. 20170501 20170501... (7 Replies)
Discussion started by: nalu
7 Replies

2. Shell Programming and Scripting

Script does not run properly

Hello everybody Im learning bash scrpting language and im making a script that read a file line by line and it does a comparison if in a line start with a letter or number and it will delete every ones that start with a letter. But im getting some errors First of all, this is the script's... (5 Replies)
Discussion started by: alienrunes
5 Replies

3. Shell Programming and Scripting

Shell script not working properly

Hello, i have below shell script to process ftp get from server and create file list afte finish. this shell scipt has 6 parameter input. unfortunately, it is only working to get the file and terminated before creating file list. please help. thanks, #!/bin/ksh ## example usage :... (3 Replies)
Discussion started by: daryatmo
3 Replies

4. Shell Programming and Scripting

script line not working properly

Hi , I am using the below command in script. $_IDLETIME is returning value if i execute the script manually. sar > $_LOCATION/sar.txt _IDLETIME=`tail -2 $_LOCATION/sar.txt | head -1 | tr -s ' ' ' ' | cut -d ' ' -f8 | cut -d '.' -f1`; if But it s not returning any value if it put the... (3 Replies)
Discussion started by: ahamed
3 Replies

5. Shell Programming and Scripting

Script not running properly when run from Crontab

Hi I am a novice Linux/Perl user and am struggling to overcome what I am sure is a simple problem. I am using a perl program to create a shell script daily containing between 10 and 30 "at -f" commands for the same day. Then I change the file attributes to allow the file to be executed. When... (2 Replies)
Discussion started by: simoncjones
2 Replies

6. Shell Programming and Scripting

A script doesnt work properly when crontab

Hi, I have a script which does a tar and sends it to another server as backup. Script is as below # Locations to be backed up. Seperate by space BACKUP_LOCATIONS=/repos/subversion BACKUP_BASE_FOLDER=/bakpool BACKUP_FILE_NAME_ROOT=svn-backup START_TIME_DISP=`date` START_TIME=`date... (11 Replies)
Discussion started by: digitalrg
11 Replies

7. Shell Programming and Scripting

cron does not execute script properly

I have a simple script that checks for certain printers and records them to a file. When I run the script manually at the command prompt, it works perfect, but when I run the script via cron, nothing happens. No errors reported, and no records are written out. I'm using Solaris 10. Below is the... (4 Replies)
Discussion started by: lmatlebyane
4 Replies

8. Shell Programming and Scripting

expr not outputting properly.. bsd sh script

When i run sh -x test.sh, expr outputs x=expr $x + 1 instead of doing the arithmetic.. been working on this overnight.. and its being a pain in the arse if you ask me.. :confused::confused: #!/bin/sh #script for downloading numerical filenames chap=1 p=1 count=0 x=1 while do if ... (2 Replies)
Discussion started by: aspect_p
2 Replies

9. UNIX for Dummies Questions & Answers

Script not running properly

I created a script before which was this :- cd /mike/dataxfer for dir in *; do if ; then ssh -l abc nissan "mkdir -p /mike/web/$dir" scp -r ${dir}/priceops nissan:mike/web/${dir}/ fi done exit 0 This script worked fine for me with no problem. It will... (5 Replies)
Discussion started by: chris1234
5 Replies

10. Shell Programming and Scripting

Shell script not processing if statement properly

Hi I am trying to create a shell script that will look for a contracthead file first and if the contract head file does not exist on day1 exit script. Now on day2 if contracthead exists or not run the script uploading files in order such as contract line then contract contact so the... (2 Replies)
Discussion started by: jonathan184
2 Replies
Login or Register to Ask a Question