Script running in bash 3.0 not in 3.2


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script running in bash 3.0 not in 3.2
# 1  
Old 01-23-2009
Script running in bash 3.0 not in 3.2

I have wasted one working day writing this scripts.
It compares two folders and make a good tabbed report about their differences.

Code:
#!/bin/bash

function DRAW_DEPTH () {
 ROUND=$1
 while [ $ROUND -ge 0 ]
 do
   printf %s "    "
   ROUND=`expr $ROUND - 1`
 done
 printf %s "|- "
}

function MAIN () {
 
 TAB=`DRAW_DEPTH $DEPTH`
 
 DIR_LIST=`ls -l $1 | awk '{print $9}'`
 for i in $DIR_LIST
 do
   # Si es un directorio entonces vamos por aki
   
   if [ -d ${1}/${i} ]; then
     if [ -d ${2}/${i} ]; then
       echo "$TAB (OK) ${1}/${i} is a directory, it exist in ${2}"
       DEPTH=`expr $DEPTH + 1`
       MAIN ${1}/${i} ${2}/${i}
       DEPTH=`expr $DEPTH - 1`
       TAB=`DRAW_DEPTH $DEPTH` 
     else
       echo "$TAB (**) ${1}/${i} is a directory, it does NOT exist in ${2}"
     fi

   else    

     # Si no es un directorio miramos primero si es un LINK
     if [ -h ${1}/${i} ]; then
       if [ -h ${2}/${i} ]; then
         checksum_1=`sum ${1}/${i} | awk '{print $1}'`
         checksum_2=`sum ${2}/${i} | awk '{print $1}'`
         if [ $checksum_1 == $checksum_2 ]; then
           echo "$TAB (OK) $i exists as LINK in $1 and in $2 and they're EQUAL"
         else
           echo "$TAB (@@) $i exists as LINK in $1 and in $2 but they DIFFER"
         fi
       else
         echo "$TAB (**) $i exists as LINK in $1 but does NOT exist in $2"
       fi
     else
       if [ -e ${2}/${i} ]; then
         checksum_1=`sum ${1}/${i} | awk '{print $1}'`
         checksum_2=`sum ${2}/${i} | awk '{print $1}'`
         if [ $checksum_1 == $checksum_2 ]; then
           echo "$TAB (OK) $i exists in $1 and in $2 and they're EQUAL"
         else
           echo "$TAB (@@) $i exists in $1 and in $2 but they DIFFER"
         fi
       else
         echo "$TAB (**) $i exists in $1 but does NOT exist in $2"
       fi
     fi
   fi 
done;
}

DEPTH=-1
MAIN $1 $2

I wrote it while i was working with my RedHat 4-6 with bash interpreter:
GNU bash, version 3.00.15(1)-release (x86_64-redhat-linux-gnu)
But here at work i have Ubuntu 8-04 and bash:
GNU bash, version 3.2.39(1)-release (i486-pc-linux-gnu)

And it doesnt run....Smilie..... someone can tell about what commands have changed or perhaps another problem.
# 2  
Old 01-27-2009
Put "set -x" on the second line of the script, run it again, and post the last few (10 or so) lines of output (before it fails).
# 3  
Old 01-27-2009
+ DEPTH=-1
+ MAIN dir_1/ dir_2/
++ DRAW_DEPTH -1
++ ROUND=-1
++ '[' -1 -ge 0 ']'
++ printf %s '|- '
+ TAB='|- '
++ ls -l dir_1/
++ awk '{print $9}'
+ DIR_LIST=

This is complete output.....

DIR_LIST empty? why? "ls -l" works in all bash versions. Or it isnt the problem?
Thx for "set -x" good !

Last edited by trutoman; 01-27-2009 at 01:15 PM..
# 4  
Old 01-28-2009
I think it's because your new version of Linux has an alias or function overriding the ls command. Just to be sure you are using the command and not some alias'd version of it, use:
Code:
DIR_LIST=`command ls -l $1 | awk '{print $9}'`

# 5  
Old 01-28-2009
Thats true, in Ubuntu i have an alias ls="ls --color", but unfortunately thats not the problem. I have run the script with your suggestion, and the output remains the same.

Quote:
+ DEPTH=-1
+ MAIN dir_1 dir_2
++ DRAW_DEPTH -1
++ ROUND=-1
++ '[' -1 -ge 0 ']'
++ printf %s '|- '
+ TAB='|- '
++ command ls -l dir_1
++ ls -l dir_1
++ awk '{print $9}'
+ DIR_LIST=
Thx again but.....anything else?
Perhaps the name of first argument ..... ./dir_1 dir_1 ./dir_1/
i have tested but its always the same.... plz help!!
# 6  
Old 01-28-2009
What does "ls -l dir_1" give you, please? Then try "ls -l dir_1 |awk '{ print $9}'".
# 7  
Old 01-28-2009
OMG it was simple:

ls -l line in RedHat

Quote:
-rw-r--r-- 1 nor nor 0 Jan 26 08:48 Salida.aftn
ls -l line in Ubuntu

Quote:
drwxrwxr-x 5 alvaro alvaro 4096 2009-01-13 14:21 dir_1

The format of date is different, so awk was taking $9 when it must take $8. Thx Otheus.
I need make this script runable in all platforms so: --->(new thread better?)

How can i get the names of files, links and dirs without depends of platform.??

Last edited by trutoman; 01-28-2009 at 07:21 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Running nmap via bash script

Hello fellow scripters... I am trying to set up a script for work that reads the contents of a file of IP address and network names, takes these and runs a given nmap scan against them and then saves the output to a file with the filename of the network name. Such as... IP file looks like... (4 Replies)
Discussion started by: hawkeyesc72
4 Replies

2. Shell Programming and Scripting

Running options in bash script

Hello UNIX & Linux Forums community! Long time Linux daily user hobbyist, new to shell scripting.... I'm working on a script that does all the "work" in one script, and makes calls to a second script to display info to the user via mostly expanding variables in heredocs. I'm contemplating... (6 Replies)
Discussion started by: Cody Learner
6 Replies

3. UNIX for Dummies Questions & Answers

Running a C/C++ program and/or bash script from a server

I wish to be able to give to a client the opportunity to : 0) Turn one of my ubuntu computers into a webserver 1) See a webpage after visiting a url where an external user/client can set a couple of variables (e.g. Number1= ?, Number2=?) 2) By pressing "run" the program runs on my machine 3)... (1 Reply)
Discussion started by: frad
1 Replies

4. Shell Programming and Scripting

Bash shell script to check if script itself is running

hi guys we've had nagios spewing false alarm (for the umpteenth time) and finally the customer had enough so they're starting to question nagios. we had the check interval increased from 5 minutes to 2 minutes, but that's just temporary solution. I'm thinking of implementing a script on the... (8 Replies)
Discussion started by: hedkandi
8 Replies

5. Shell Programming and Scripting

script running by sh but not by bash

execute the attached script as, bash -x INFA_MAP_GEN_XML.sh "/export/home/e120945/INFORMATICA_MAPPING_GENERATOR/SOURCE" "INFA_TEMPLATE.csv" "/export/home/e120945/INFORMATICA_MAPPING_GENERATOR/TARGET" "UNIX" "/export/home/e120945/INFORMATICA_MAPPING_GENERATOR/SETUP"... (5 Replies)
Discussion started by: 120945
5 Replies

6. UNIX for Dummies Questions & Answers

Help Running a Check in Bash Script

Hey guys, so I wrote a small script that pretty much just takes in two numbers and counts from the first to the second, e.g. unknown-hacker|544> count.sh 1 3 1 2 3 My problem is I want to make it so that if you input invalid parameters, such as non-numerical characters, more than 2... (2 Replies)
Discussion started by: Duo11
2 Replies

7. UNIX for Dummies Questions & Answers

Running Executable in Bash Script

Hey guys, so I've been trying to write a bash script called runSorter.sh that runs an executable that also takes in some parameters and outputs the results to a text file. The executable, sorter, takes in a number parameter. I want to make it so that you can input as many number parameters into... (4 Replies)
Discussion started by: Duo11
4 Replies

8. Shell Programming and Scripting

Validate BASH script before running it...

Hello, Is there some way to validate a bash script before running it. I want to make sure all of the syntax and everything is good so that I dont get a false return code. Thanks, tom (7 Replies)
Discussion started by: tjones1105
7 Replies

9. UNIX for Advanced & Expert Users

debugging an already running bash script

# ps -ef | grep rc root 13903 1 0 08:56 ? 00:00:00 /usr/sbin/automount --timeout=60 /archive file /etc/auto_archive root 10706 1 0 08:55 ? 00:00:00 /bin/bash /etc/rc.d/rc 3 root 2933 20071 0 19:38 pts/1 00:00:00 grep rc Is there any way to debug the... (1 Reply)
Discussion started by: marcpascual
1 Replies

10. Linux

Cannot running export database using bash script

Hi all, I'm new in linux. When I try to run a bash script, it doesn't execute and i receive the following error message 20070321:220002|ERROR||exportDatabase.bash|Another EXPORT process (pid=2799) is still running. If i kill this pid, i receive "No such process". This process was running... (5 Replies)
Discussion started by: tovohery
5 Replies
Login or Register to Ask a Question