LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Create CD catalogue using Shell Script (https://www.linuxquestions.org/questions/programming-9/create-cd-catalogue-using-shell-script-168154/)

Helene 04-09-2004 10:51 AM

Create CD catalogue using Shell Script
 
I am making a record of all the files on a CD. All the files on the CD should be listed in a text file using this format:

CD Volume Name;Path and name of file;Modification Time;Size in bytes;Comment;<Newline>

The result should look like this:
Adios;/adk/Makefile;24/02/04 13:03:36;20865;Adios files on CDROM;
....

My head is spinning and I am not sure where to start.

I have used the 'find' utility to print the ;Path and name of file; to the text file. The problem is appending the ;Modification Time; Size in bytes; and so on. To make it even more complicated; The user should be allowed to add a comment to each record.

I greatly appreciate any help or comments!

- Helene

nhs 04-09-2004 01:32 PM

Try using

#!/bin/bash
# Read cd name:
cd_name=`isoinfo -d -i /dev/cdrom | grep 'Volume id: ' | sed 's/Volume id: //'`

# Loop through each file on disc:
for cd_path in `find /mnt/cdrom`

# Get modification in "dd/mm/yy hh:mm:ss" format
do cd_mod_time=`stat -c %y $cd_path | cut -c 1-19 | sed 's/[0-9]\{2\}\([0-9]\{2\}\)-\([0-9]\{2\}\)-\([0-9]\{2\}\)/\3\/\2\/\1/'`

# Get file size in bytes:
cd_size=`stat -c %s $cd_path`

# Get comment:
echo -n "Enter comment for file $cd_path: "
read cd_comment

# Output record:
echo "$cd_name;$cd_path;$cd_mod_time;$cd_size;$cd_comment;"
done

and work on that. I have guessed about the functionality required in places however I hope it helps.

Helene 04-09-2004 09:42 PM

You made my day , nhs. Everything seems to work so far. Thank you very much!


All times are GMT -5. The time now is 03:01 AM.