Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 01-02-2018, 12:18 AM   #1
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.


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


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, 02:06 AM   #2
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_10{.0|.1|.2}
Posts: 4,838
Blog Entries: 6

Rep: Reputation: 2667Reputation: 2667Reputation: 2667Reputation: 2667Reputation: 2667Reputation: 2667Reputation: 2667Reputation: 2667Reputation: 2667Reputation: 2667Reputation: 2667
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:

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.


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 10:50 AM
how to abort cron if the previous cron job not yet finished? Winanjaya Linux - Newbie 2 05-22-2012 07:44 PM
[SOLVED] Running batch file does not produce same results as running command from Terminal nmuleski Linux - Newbie 9 12-30-2011 10:52 AM
Running gcov when executable has command line input options jasper77 Programming 2 03-03-2011 05:55 PM
batch job finished notification nkelle Linux - General 2 03-08-2007 11:45 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:28 AM.

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