LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Seeking advice on bash script (https://www.linuxquestions.org/questions/programming-9/seeking-advice-on-bash-script-241263/)

satimis 10-11-2004 06:01 AM

Seeking advice on bash script
 
Hi folks,

I have following script but it only worked once. Steps performed as follows;

save it /home/satimis/mkiso_new and chmod +x

[satimis@localhost satimis]$ cat mkiso_new

Code:

#!/bin/sh

ISO_FILE=/home/satimis/To_burn/Image.iso

mkisofs_args="-R -o ${ISO_FILE} -l -hide-rr-moved \
Document=/home/satimis/Document \
Photo=/home/satimis/Photo \
Working=/home/satimis/Working"

#  set the paths variable to all the remaining command-line arguments
paths="$@"

echo "Remaining arguments ${paths}"

# iterate through all paths given on the command-line

for path in $paths
    do
        if [ -d $path ] ; then
            echo "Adding ${path}"
        else
            echo "Dir ${path} doesn't exist"
            exit 1
        fi

        # for each path given, add the appropriate graft-point to mkisofs's arguments
        mkisofs_args="${mkisofs_args} ${path##*/}=${path}"

    done

# and now call mkisofs

1)
# sh -vx ./mkiso_new
Code:

#!/bin/sh

ISO_FILE=/home/satimis/To_burn/Image.iso
+ ISO_FILE=/home/satimis/To_burn/Image.iso

mkisofs_args="-R -o ${ISO_FILE} -l -hide-rr-moved \
Document=/home/satimis/Document \
Photo=/home/satimis/Photo \
Working=/home/satimis/Working"
+ mkisofs_args=-R -o /home/satimis/To_burn/Image.iso -l -hide-rr-moved Document=/home/satimis/Document Photo=/home/satimis/Photo Working=/home/satimis/Working

#  set the paths variable to all the remaining command-line arguments
paths="$@"
+ paths=

echo "Remaining arguments ${paths}"
+ echo 'Remaining arguments '
Remaining arguments

# iterate through all paths given on the command-line

for path in $paths
    do
        if [ -d $path ] ; then
            echo "Adding ${path}"
        else
            echo "Dir ${path} doesn't exist"
            exit 1
        fi

        # for each path given, add the appropriate graft-point to mkisofs's arguments
        mkisofs_args="${mkisofs_args} ${path##*/}=${path}"

    done

# and now call mkisofs

2)
[root@localhost satimis]# ./mkiso_new /home/satimis/Working
Remaining arguments /home/satimis/Working
Adding /home/satimis/Working

[root@localhost satimis]# ls /home/satimis/To_burn/
Image.iso

[root@localhost satimis]# mount -t iso9660 /home/satimis/To_burn/Image.iso -o loop /mnt/floppy

Files can be read.

[root@localhost satimis]# umount /mnt/floppy


3)
[root@localhost satimis]# rm /home/satimis/To_burn/Image.iso


[root@localhost satimis]# ./mkiso_new /home/satimis/Working

[root@localhost satimis]# ./mkiso_new /home/satimis/Document
/homesatimis/Photo
/home/satimis/Working

[root@localhost satimis]# ./mkiso_new /home/satimis/Document/
/homesatimis/Photo/
/home/satimis/Working/

None of them can create Image.iso

Remark:

Code:

[root@localhost satimis]# ./mkiso_new /home/satimis/Working
Remaining arguments /home/satimis/Working
Adding /home/satimis/Working

etc.  indicated.

I can't find out the cause.


4)
With following command, Image.iso can be creaded

# mkisofs -R -o /home/satimis/To_burn/Image.iso -l -graft-point -hide-rr-moved /Document/=/home/satimis/Document/ /Photo/=/home/satimis/Photo/ /Working/=/home/satimis/Working/
......
Total translation table size: 0
Total rockridge attributes bytes: 735885
Total directory bytes: 1953792
Path table size(bytes): 14456
Max brk space used 5e2000
138979 extents written (271 MB)

Image.iso created on /home/satimis/To_burn

Could you please shed me some light. TIA

B.R.
satimis

MrBrain 10-11-2004 07:08 AM

Isn't "mkisofs_args="-R -o ${ISO_FILE}..." supposed to be "mkisofs_args="-R -o $ISO_FILE..."?

mirradric 10-11-2004 07:12 AM

Quote:

Originally posted by lindsven
Isn't "mkisofs_args="-R -o ${ISO_FILE}..." supposed to be "mkisofs_args="-R -o $ISO_FILE..."?
Should be equivalent.

satimis 10-11-2004 07:37 AM

Hi folks,

Tks for your advice. Problem still remains intact.

Made following change;
$ cat mkiso_new
Code:

#!/bin/sh

ISO_FILE=/home/satimis/To_burn/Image.iso

mkisofs_args="-R -o $ISO_FILE -l -hide-rr-moved .....

# ./mkiso_new /home/satimis/Working/
Remaining arguments /home/satimis/Working/
Adding /home/satimis/Working/
# ls /home/satimis/To_burn/
No printout
# ./mkiso_new /home/satimis/Working
Remaining arguments /home/satimis/Working
Adding /home/satimis/Working
# ls /home/satimis/To_burn/
No printout
# find / -name Image.iso
find: /proc/2665/task: No such file or directory

The funny thing is why it worked once only.

B.R.
satimis

mirradric 10-11-2004 07:56 AM

First, you seem to be missing the -graft-point argument to mkisofs.
2nd, the arugments to mkiso_new cannot end with / or else you can't get the part for the left side of =

satimis 10-11-2004 09:58 AM

Hi mirradric,

Tks for your advice.
Quote:

First, you seem to be missing the -graft-point argument to mkisofs.
Added "-graft-point"

$ cat mkiso_new
Code:

#!/bin/sh

ISO_FILE=/home/satimis/To_burn/Image.iso

mkisofs_args="-R -o $ISO_FILE -l -graft-point -hide-rr-moved \
Document=/home/satimis/Document \
Photo=/home/satimis/Photo \
Working=/home/satimis/Working"

#  set the paths variable to all the remaining command-line arguments
paths="$@"

echo "Remaining arguments ${paths}"

# iterate through all paths given on the command-line

for path in $paths
    do
        if [ -d $path ] ; then
            echo "Adding ${path}"
        else
            echo "Dir ${path} doesn't exist"
            exit 1
        fi

        # for each path given, add the appropriate graft-point to mkisofs's arguments
        mkisofs_args="${mkisofs_args} ${path##*/}=${path}"

    done

# and now call mkisofs

Quote:

2nd, the arugments to mkiso_new cannot end with / or else you can't get the part for the left side of =
# ./mkiso_new /home/satimis/Working
Remaining arguments /home/satimis/Working
Adding /home/satimis/Working
[root@localhost satimis]# ls /home/satimis/To_burn/
No printout
[root@localhost satimis]# ./mkiso_new /home/satimis/Document
Remaining arguments /home/satimis/Document
Adding /home/satimis/Document
[root@localhost satimis]# ls /home/satimis/To_burn/
No printout
[root@localhost satimis]# find / -name Image.iso
find: /proc/2591/task: No such file or directory

One thing I can't resolve.

# ./mkiso_new /home/satimis/Working
Remaining arguments /home/satimis/Working
Adding /home/satimis/Working

only worked once having created an Image.iso. It never works again.

B.R.
satimis

satimis 10-11-2004 11:01 AM

Hi folks,

Further to my last posting, following script works without problem

[satimis@localhost satimis]$ cat mkiso_01.iso
Code:

#!/bin/sh

ISO_FILE=/home/satimis/To_burn/Image.iso

mkisofs -R -o ${ISO_FILE} -l -graft-point -hide-rr-moved \
/Document/=/home/satimis/Document/ \
/Photo/=/home/satimis/Photo/ \
/Working/=/home/satimis/Working/

[satimis@localhost satimis]$ ./mkiso_01.iso
Code:

INFO:  UTF-8 character encoding detected by locale settings.
        Assuming UTF-8 encoded filenames on source filesystem,
        use -input-charset to override.
.......
.........
Total translation table size: 0
Total rockridge attributes bytes: 736242
Total directory bytes: 1953792
Path table size(bytes): 14456
Max brk space used 5e2000
138985 extents written (271 MB)

[satimis@localhost satimis]$ ls /home/satimis/To_burn/
Image.iso

An Image.iso was created under /home/satimis/To_burn/


Now the remaining works are;

1) How to make /Working/=/home/satimis/Working/ variable, keeping the other 2 directories permanent.

i.e.
/Working/=/home/satimis/Working/ plus
/dir-AAA/=/path/to/dir-AAA/
/dir-BBB/=/path/to/dir-BBB/
etc. can be added as optional. Or they can be ignored without added.

2) How to make "Image_01.iso" changed.

i.e. "01" can be changed to read as "02 or 03 or 04, etc."

TIA

B.R.
satimis


All times are GMT -5. The time now is 04:27 AM.