LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-01-2018, 11:18 PM   #1
cilbuper
Member
 
Registered: Mar 2008
Posts: 137

Rep: Reputation: 0
Question Running a batch command of the same executable when previous is finished


I have a number of folders with a text file in them and I have a program that accesses this text file and does it's deed as per the instructions inside.

Example:

Here are where the files are located and the program needs to go to the directory where the file is.

/BaseFolder1/WorkFolderA/wfa.txt
/BaseFolder1/WorkFolderB/wfb.txt
/BaseFolder1/WorkFolderC/wfc.txt
/BaseFolder2/WorkFolderQ/wfq.txt
/BaseFolder2/WorkFolderW/wfw.txt
/BaseFolder3/WorkFolderE/wfe.txt
/BaseFolder3/WorkFolderR/wfr.txt

This is what it would look likd if typed it in at the command prompt
/BaseFolder1/WorkFolderA/$>Program_name --input wfa.txt
/BaseFolder1/WorkFolderB/$>Program_name --input wfb.txt




I want to be able to add folders & data files (append them) when I get new ones. I don't care if the program starts over b/c it is fast and skips if it is there already.

So what would a program/batch/script look like that would do this?
 
Old 01-02-2018, 01:06 AM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_10{.0|.1|.2}
Posts: 4,718
Blog Entries: 6

Rep: Reputation: 2575Reputation: 2575Reputation: 2575Reputation: 2575Reputation: 2575Reputation: 2575Reputation: 2575Reputation: 2575Reputation: 2575Reputation: 2575Reputation: 2575
It would probably help if you could provide a better description of exactly what you are trying to do.

From what you have posted with your question I think that you want a script to run continuously or repeatedly, which finds all subdirectories and files along some path matching a pattern like /BaseFolder*/.../wf?.txt, change CWD to that directory and invoke Program_name with the file name. If new directories or files are added it should find them the next time the script is run.

I would suggest using a simple wrapper script (prog_wrapper) which is invoked by a cron rule (cron_wrapper) which uses find to locate the target files and paths.

In pseudo-code, it might look something like this:

Code:
cron wrapper {
     find /BaseFolder* -type f -name wf?.txt -exec prog_wrapper {} ;
}

prog_wrapper {
     cd dirname $1
     Program_name --input basename $1
}
You could implement that as a shell script or in any scripting language with which you are familiar.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Running "top" command in Batch mode. sunilchand Linux - Newbie 1 02-01-2017 09:50 AM
how to abort cron if the previous cron job not yet finished? Winanjaya Linux - Newbie 2 05-22-2012 06:44 PM
[SOLVED] Running batch file does not produce same results as running command from Terminal nmuleski Linux - Newbie 9 12-30-2011 09:52 AM
Running gcov when executable has command line input options jasper77 Programming 2 03-03-2011 04:55 PM
batch job finished notification nkelle Linux - General 2 03-08-2007 10:45 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:11 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration