Can't understand script output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Can't understand script output
# 1  
Old 01-05-2016
Can't understand script output

New to korn shel1 and having an issue. The following is suppose to read the parameter values from files in a source directory and then pass them on to a log file in a different directory, The ArchiveTracker scripts is suppose to call the parameterreader script to exact the parameter values and pass them on to a log file.

But I keep getting the following when I run the script.
Code:
-bash: ./: is a directory


code
Code:
 #/bin/ksh
  
 #ArchiveTracker

SourceLocation='pwd'
 TrackerLocation=~/Scripts/Test/Tracker
  

 
  
 LOGFILE=$TrackerLocation/processing.log
  
 rm -f $LOGFILE
 touch $LOGFILE
  

 
 for sfile in $SourceLocation/*
 do
         if [ ! -s "$SourceLocation/$file" ];
         then
  
         echo Step 2: Processing $file >>  $LOGFILE
  
        while read line < $file
        do
                 PARNAME=`echo $line | awk -f "=" '{print  $1}'`
  
                 PARVALUE`parameterreader $file  $PARNAME`
                 echo  file $PARNAME >>  LOGFILE
         done
  
         sftp -p "$SourceLocation/$file  $TargetLocation/$file"
         ret_code=$?
         if [$ret_code != 0]; then
         printf "error : [%d] when executing command:"  $ret_code
         #exit $ret_code
         else
         echo Step 3: Writing  $TrackerLocation/$file
         touch "$TrackerLocation/$file"
         fi
 else
         echo Step 2: $file previously  processed
 fi
  
 done

code

code
Code:
#/bin/ksh
 #parameterreader script
  
  
 PARVALUE=`grep $2 $1 | awk -f "=" '{print  $1}'`
  
 echo $PARVALUE

code

Last edited by Scrutinizer; 01-05-2016 at 01:59 PM.. Reason: code tags added
# 2  
Old 01-05-2016
it is hard to tell anything without way more info. Where - in which line - does the error occur? You say you're running ksh, but the error is from bash. What is PARVALUE in the first script supposed to be? Where is file set? And, if you intended to set a shebang in the first line of both scripts, the correct syntax is #!/bin/ksh.
This User Gave Thanks to RudiC For This Post:
# 3  
Old 01-05-2016
I have correct the portion identifying the script as ksh. But when should I include the PARVALUE variable within the first script. Script is running but always going to step portion of the script.
# 4  
Old 01-05-2016
I assume that you meant for the code:
Code:
SourceLocation='pwd'

to set SourceLocation to the pathname of the current directory, but that is not what this code does. It sets SourceLocation to the literal string pwd.

Try this instead:
Code:
SourceLocation=$PWD

or one of the much slower options:
Code:
SourceLocation=$(pwd)

or (the less preferred form of command substitution):
Code:
SourceLocation=`pwd`

Note the huge difference in behavior between backquote ` and single-quote '.

Then note that the code:
Code:
 for sfile in $SourceLocation/*
 do
         if [ ! -s "$SourceLocation/$file" ];
         then

is setting sfile as the loop control variable and using file inside the loop. And, that the if test is looking at the size of $SourceLocation/$SourceLocation/filneame. Maybe you meant something more like:
Code:
 for file in $SourceLocation/*
 do
         if [ ! -s "$file" ];
         then

If this still doesn't work turn on tracing so you can see what is happening as your script runs. You can run on tracing by invoking your script with:
Code:
ksh -xv scriptname

or by adding the following line as the second line of your script:
Code:
set -xv


Last edited by Don Cragun; 01-05-2016 at 07:07 PM.. Reason: Add note about another problem in the code.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Help me understand this script

#!/bin/awk -f BEGIN {i=1;file="modified.txt"} { if ($0 !~ /^DS:/) {print $0 >> file} else { if ($0 ~ /^DS:/) {print "DS: ",i >> file;if (i==8) {i=1} else {i++}}; } } END {gzip file} Can someone explain to me how this above script works, I got it from a friend but not able... (3 Replies)
Discussion started by: Kamesh G
3 Replies

2. UNIX for Advanced & Expert Users

unable to understand the output of TRUSS command

Hi, I am trying to set ulimit for soft stack unlimited, but this is not taking effect, after tracing the ulimit -a unlimited command, the below output was generated, which i am unable to comprehend. Could any one help me with this? prcbap1-r10prod: truss -d ulimit -s unlimited Tue Dec 30... (2 Replies)
Discussion started by: NasirAbbasi
2 Replies

3. Shell Programming and Scripting

Help to understand a script

Hello world! Can someone please explain me how this code works? I'ts supposed to find words in a dictionary and show the anagrams of the words. { part = word2key($1) data = $1 } function word2key(word, a, i, x, result) { x = split(word, a, "") asort(a) ... (1 Reply)
Discussion started by: jose2802
1 Replies

4. Shell Programming and Scripting

Do not understand grep output

In my directory I have two files and one subdirectory. When I run ls -l |grep -v ^d I get the following output: total 8 -rwxrwxrwx 1 qms qms 254 Oct 3 16:00 file1.txt -rwxrwxrwx 1 qms qms 7167 Oct 11 15:46 file2.txt Can you explain what is total 8 if the number of files is 2 and is... (3 Replies)
Discussion started by: rdogadin
3 Replies

5. UNIX for Dummies Questions & Answers

Not able to understand this output

I am hitting this command: dvlna021-(/cm/ims/dev/gds-scheduler/10/app/Software/active/Soft/conf)->ls -lrt gds_userenv_* This is the output lrwxrwxrwx 1 aimse was 65 Jul 31 12:56 gds_userenv_scheduler_2.ksh -> /cm/ims/dev/gds-scheduler/10/app/conf/gds_userenv_scheduler_2.ksh ... (2 Replies)
Discussion started by: Nsharma3006
2 Replies

6. UNIX for Dummies Questions & Answers

Not able to understand the output of w command

I have taken putty session of a server from two separate machines namely HOST1(3 sessions) and HOST2(1 Session) . However w command says there are 5 users Confused over the output any clue will be appreciated. # w 09:29:36 up 34 days, 15:48, 5 users, load average: 0.62, 4.33, 8.16 USER ... (3 Replies)
Discussion started by: pinga123
3 Replies

7. UNIX for Dummies Questions & Answers

Unable to understand ps output.

I m executing ps command and sorting it according to memory usage. Please find the output of the command. # ps aux --sort pmem USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.0 2060 624 ? Ss 01:54 0:00 init root 2 0.0... (1 Reply)
Discussion started by: pinga123
1 Replies

8. Shell Programming and Scripting

I can't understand sed error output.

Hey forum, I have a problem with a script what used to work, but suddenly is not working anymore. I have been trying different things for an hour now and I give up :D . #!/bin/sh asukoht=`pwd` template=$1 for values in... (4 Replies)
Discussion started by: mario8eren
4 Replies

9. Shell Programming and Scripting

Need to understand the output of last command

root@desktop:~# last reboot | head -1 reboot system boot 2.6.31-17-generi Tue Jan 26 12:05 - 13:52 (01:46) What does the last two fields(12:05 - 13:52 (01:46)) of the output mean? (2 Replies)
Discussion started by: proactiveaditya
2 Replies
Login or Register to Ask a Question