Bash script monitor directory and subdirectories for new pdfs


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash script monitor directory and subdirectories for new pdfs
# 15  
Old 02-28-2015
Quote:
Originally Posted by Don Cragun
OK. So you will have PDF files in multiple folders in the file hierarchy rooted in $SYSDIR.

What are you hoping to produce? Are you trying to produce:
  1. one XML file in $RSSDIR for all of the PDF files in and under $SYSDIR,
  2. one XML file in $RSSDIR for each directory in and under $SYSDIR containing one or more PDF files, or
  3. one XML file in a subdirectory under $RSSDIR corresponding to each subdirectory under $SYSDIR containing one or more PDF files?
What data is supposed to be included with the <description> tags in your XML file(s) for each PDF file?
I need one xml for all pdfs in and under specified directory.
For description tags I need pdf name, and folder name for two levels up. Info should be sorted by date, showing newest first, and links to files.
# 16  
Old 02-28-2015
Quote:
Originally Posted by markus1981
I need one xml for all pdfs in and under specified directory.
For description tags I need pdf name, and folder name for two levels up. Info should be sorted by date, showing newest first, and links to files.
Your script is creating 3 XML tags per PDF file in the rss_body function:
  1. the data stored between <title> and </title> tags in the final component of the absolute pathname of the PDF file,
  2. the data stored after the <link> tag (there is no closing </link> tag) is the string stored in the shell variable $RSSDIR followed by a slash, the last directory in the absolute pathname of a PDF file (not necessarily the directory of the current PDF file's pathname), followed by a slash and the final component of the absolute pathname of the PDF file, and
  3. the data stored between <description> and </description> tags is an empty string.
Should there be a </link> tag after the data you insert following the <link> tag?

Please show an explicit example of the data that you want created for the following PDF file:
Code:
-rw-r--r--  1 dwc  staff  2895323 Oct 23  2013 /var/www/html/Intranet/pdf/IEEE/20601-Rev-D7r02-clean.pdf



Your current code is creating one XML file for each different final directory name in the PDF pathnames found. One of these XML files is created for each PDF file found. If another PDF file with the same final directory name is found, it overwrites the previous XML file. (This is just slow if there is only one directory under $SYSDIR with that name. If there are two or more directories with the same final component name, there could be several problems.)

Furthermore, if there are more PDF files than xargs will process in a single invocation of ls your files will NOT be sorted from newest to oldest; there will be groups of PDF files sorted in timestamp order, but the complete list might not be correctly ordered. So, to get a time ordered list of files we either need to gather data needed for each file into single lines in a file that we can sort by timestamp, or we need to create files in a single directory with the same timestamps as your PDF files that we can then sort us ls -t. Creating a single file will probably be faster if you have an easy way to convert file timestamps into text. If not, we can use touch to copy file timestamps to other files.

Does your system have a stat utility?
# 17  
Old 03-02-2015
Quote:
Originally Posted by Don Cragun
You have a loop over all PDF files in and under $SYSDIR in your main loop that includes a call to rss_body which includes a loop over all PDF files in and under $SYSDIR. This is almost certainly not what you want, but without a better description of where PDF files are located in your file hierarchy and what XML files you're trying to create, I'm not clear on what you want to accomplish.

What OS are you using? How are you invoking feedgen1.sh?

Are you getting any output at all from feedgen1.sh?

Are any files being created by your current script? (And, if so, what is in them?)

What is the output from the commands:
Code:
ls -l feedgen1.sh
find $SYSDIR -type f -name '*.pdf' -exec ls -l {} +
find $RSSDIR -type d -exec ls -ld {} +
find $RSSDIR -type f -name '*.xml' -exec ls -l {} +

Is the output you see from the above commands representative of the locations of the PDF files you want to report in your XML files (or do you just have 1 or 2 PDF files installed for testing)? Is the output you see from the above commands representative of the directory structure you hope to see under $RSSDIR?

What XML files are you hoping to create from the output shown by the above commands?

The variable DESC is unset in this script, but $DESC is used in rss_body. What is the description tag in your XML files supposed to contain for your PDF files?
Output from commands:
Code:
ls -l feedgen.sh
 -rwxr-x--- 1 root root 1529 Feb 27 14:27 feedgen.sh

find $SYSDIR -type f -name '*.pdf' -exec ls -l {} +
no output

> find $RSSDIR -type d -exec ls -ld {} + drwxr-xr-x 2 root root 4096 Feb 27 14:12 .

> find $RSSDIR -type f -name '*.xml' -exec ls -l {} +
no output 

I have STAT utility, I think. Does code work on your system? On my system there is no output after running the code at all, still.

Last edited by Don Cragun; 03-02-2015 at 06:24 AM.. Reason: Change ICODE tags to CODE tags for multiline output and edit to put typed in commands and output on different lines.
# 18  
Old 03-02-2015
The > at the start of next to the last two command lines you typed is a secondary prompt indicating that you probably mistyped or omitted a quote in the first find command. Hit the control (or cntl or ctl depending on who made your keyboard) key and the c key at the same time to generate an interrupt signal to get back to your primary prompt. And, then, copy the find command I requested and paste it into your shell.

And, for the third time, what operating system are you using?
# 19  
Old 03-02-2015
I copied your commands to Webmin command shell, when I tried it, no mistype I think. OS is Ubuntu Server 14.04.
# 20  
Old 03-02-2015
I'm sorry. I completely misunderstood your problem. I thought you wanted help with a bash shell script. Now it appears that you are unable to run simple bash shell commands on the system where you want to run that bash shell script with the environment variables set as they are used in that script.

If you look back through this thread, you'll see that I have asked several questions that you still have not answered. Without answers to those questions (and a real sample of the desired output based on at least two PDF files from different direcctories), I can't figure out what needs to be done to satisfy your requirements.
# 21  
Old 03-03-2015
It is OK, no harm done. We are in miscommunication from start. Bash scripting is not my thing, so I will try another solution for this problem, without bash. Thanks again.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash to create new directory by date followed by identifier and additional subdirectories

I have a bash that downloads a list and if that list has data in it then a new main directory is created (with the date) with several subdirectories (example1, example2, example3). My question is in that list there are portion of specific file types (.vcf.gz) - identifier towards the end that have... (0 Replies)
Discussion started by: cmccabe
0 Replies

2. Shell Programming and Scripting

Bash script deleting my files, and editing files in subdirectories question

#!/bin/bash # name=$1 type=$2 number=1 for file in ./** do if then filenumber=00$number elif then filenumber=0$number fi tempname="$name""$filenumber"."$type" if (4 Replies)
Discussion started by: TheGreatGizmo
4 Replies

3. Shell Programming and Scripting

Script to monitor directory size of specific users

Hi, i am new to shell scripts, i need to write a script that can monitor size of directory of specific users. Please help. Thanks, Nitin (2 Replies)
Discussion started by: nicksrulz
2 Replies

4. Shell Programming and Scripting

Bash Script to Compress All Subdirectories

I'd like to create simple bash script that, given a directory, compresses each directory by name, e.g.: Contents of ~/Documents Folder1 Folder2 Folder3 compress-subdirectoies.sh ~/Documents Results: Folder1. Folder2. Folder2. Any advice would be appreciated (7 Replies)
Discussion started by: furashgf
7 Replies

5. Shell Programming and Scripting

need help with little bash server monitor script

hello, i`m new in bash scripting and i getting an error with my little server monitoring script example of my script: #!/bin/sh s1_ats=0 while ; do sleep 5 s1=`ping -c 1 xxxx.xxxx.xxxx.xxxx | grep 64 | awk '{print $1}'` if ; then $s1_ats=0 else if ; then (2 Replies)
Discussion started by: grauzikas
2 Replies

6. Shell Programming and Scripting

Bash: Gzip files in Directory and itīs Subdirectories

Hello dear Community, I have a task to wrtie a script which will gzip not zipped files in a directory and itīs subdirectories. I succeeded in gzippung the directory but not the subdirectories: #/bin/bash #go to the directory where to zip cd $1 #Zip unzipped files for i in `ls | xargs... (2 Replies)
Discussion started by: JamesCarter
2 Replies

7. Shell Programming and Scripting

Korn/bash Script to monitor a file a check for specific data

Hi, Im trying to write this script but im stuck on it, basicaly what i want to do is to write a code to verify a log file ( apache log file for example ) and for each new line with specific data , then, output this new line for another file: full ex: output of the server.log is (... (4 Replies)
Discussion started by: Thales.Claro
4 Replies

8. Shell Programming and Scripting

script to monitor files in a directory and sending the alert

Hi All, We are having important config files in an directory which was accessable by all /auto/config/Testbed/>ls config1.intial config2.intial config3.inital often we find that some of the lines are missing in config files, we doubt if some one is removing. I would like to write... (0 Replies)
Discussion started by: shellscripter
0 Replies

9. Shell Programming and Scripting

script to monitor directory

What is the best way for a script to run to monitor a directory for the presence of files and then perform a function afterwords? I was hoping to have it continually run and sleep until it detects that files are present in the directory, then break out of the loop and go on to the next step. ... (17 Replies)
Discussion started by: nulinux
17 Replies

10. UNIX for Dummies Questions & Answers

Hep with script to monitor directory

Hello, I am a newbie who is attempting to write a script to monitor a directory for a set of 3 files that I am expecting to get ftp'd. Occasionally, we suspend operations for maintenance etc. but we still get the files so there can be more than 1 set. If there is more than 1 set, I would like... (2 Replies)
Discussion started by: cmf00186
2 Replies
Login or Register to Ask a Question