running C program to output in multiple locations


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting running C program to output in multiple locations
# 8  
Old 10-09-2011
Ok guys, here goes:

Firstly, I want to use the symlink as
Code:
s101/myprogram

and not
Code:
aa/bb/cc/myprogram

because there exists about 50 different path locations and each of these paths are extremely long (many subdirectories) and so shortening them down to a single word/symlink (sl01) helps me in identifying the complete path easily - i.e. "sl01" is strategically named.

What I have is as follows:
In my home directory (/user/dept/homes/) I have a program called myprogram.

I want to run myprogram for ~50 different situations as follows:

Situation 1:
Input file located at /vol/bb/cc/dd/ee/ff/gg.
Want to be able create output file (in already existing directory) at /vol/bb/cc/dd/ee/ff/gg/hh.


Situation 2:
Input file located at /vol/ac/ad/ae.
Want to create output file (in already existing directory) /vol/ac/ad/ae/af

Question 1) Initially I was wondering if I could run myprogram from my home directory for all the situations, instead of having copies of myprogram in all the 50 different paths. Is this possible?

Question 2) If not, its fine. But what I do not want to do is have a lot of symlinks in my home directory, instead I was hoping to use a shell script in order to run myprogram from my home directory. Is this possible - i.e. can I use a shell script to execute a program instead of using symlinks.

Thanks for your time, appreciate it!
# 9  
Old 10-09-2011
Quote:
Originally Posted by Jatsui
Initially I was wondering if I could run myprogram from my home directory for all the situations, instead of having copies of myprogram in all the 50 different paths. Is this possible?
Absolutely.

If /user/dept/homes/ appears in $PATH, then you can just type myprogram, regardless of the current working directory, and it'll be found (unless there's another executable by the same name in a directory in $PATH which is listed before /user/dept/homes/).

If /user/dept/homes/ is not part of your environment's command search path, you must provide an absolute path: /user/dept/homes/myprogram (or an equivalent tilde expression). Even if /user/dept/homes/ is in your $PATH, providing an absolute pathname is safer, though less flexible.


Quote:
Originally Posted by Jatsui
Situation 1:
Input file located at /vol/bb/cc/dd/ee/ff/gg.
Want to be able create output file (in already existing directory) at /vol/bb/cc/dd/ee/ff/gg/hh.

Situation 2:
Input file located at /vol/ac/ad/ae.
Want to create output file (in already existing directory) /vol/ac/ad/ae/af
Code:
/user/dept/homes/myprogram /vol/bb/cc/dd/ee/ff/gg > /vol/bb/cc/dd/ee/ff/gg/hh
/user/dept/homes/myprogram /vol/ac/ad/ae > /vol/ac/ad/ae/af

Regards,
Alister

Last edited by alister; 10-09-2011 at 06:24 PM..
# 10  
Old 10-10-2011
Understood.

Also, to be able to do
Code:
/user/dept/homes/myprogram /vol/bb/cc/dd/ee/ff/gg > /vol/bb/cc/dd/ee/ff/gg/hh

...how/where in myprogram.c can I sort of "link" the input file to the input location and output file to the output location - hope that makes sense - for e.g. if I have an output file by the name output.dat, how can I say that it goes into the directory /vol/bb/cc/dd/ee/ff/gg/hh

Thanks for all your time and effort!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Run a script before and after reboot automatically and send output to two locations.

Hello Team . I am working a health check script ( bash) to run on linux server ( RedHat) and requirements are 1. The o/p of script need to be send to two diff files . I am testing with tee command . But I am not successful yet , any recommendations if that is the right approach ? 2. The same... (2 Replies)
Discussion started by: Varja
2 Replies

2. Shell Programming and Scripting

Running program and output files in specific directories

I have been running a program mseed2sac using the following command cd IV find . -type f -exec /swadmin/mseed2sac '{}' \; The problem is that I end up with a lot of files in directory IV. Instead I would like to select the designator HHZ, create a directory IV.SAC and all the files output... (11 Replies)
Discussion started by: kristinu
11 Replies

3. Shell Programming and Scripting

Storing multiple sql queries output into variable by running sql command only once

Hi All, I want to run multiple sql queries and store the data in variable but i want to use sql command only once. Is there a way without running sql command twice and storing.Please advise. Eg : Select 'Query 1 output' from dual; Select 'Query 2 output' from dual; I want to... (3 Replies)
Discussion started by: Rokkesh
3 Replies

4. Shell Programming and Scripting

Grep from multiple patterns multiple file multiple output

Hi, I want to grep multiple patterns from multiple files and save to multiple outputs. As of now its outputting all to the same file when I use this command. Input : 108 files to check for 390 patterns to check for. output I need to 108 files with the searched patterns. Xargs -I {} grep... (3 Replies)
Discussion started by: Diya123
3 Replies

5. Shell Programming and Scripting

Passing multiple C program output into a shell

Hi I have the following C code # cat test.c #include <stdio.h> main() { printf ("The output is : Power\n"); printf ("The output is : No Power\n"); } The output of this C code is # ./test The output is : Power The output is : No Power Now i need to pass this outputs into a shell... (4 Replies)
Discussion started by: Priya Amaresh
4 Replies

6. Shell Programming and Scripting

Running a program multiple times to search pattern and assign structure

Hi all, I have a big file (n.txt) with following pattern: ATOM 1 N SER A 1 122.392 152.261 138.190 1.00 0.00 N ATOM 2 CA SER A 1 122.726 151.241 139.183 1.00 0.00 C TER ENDMDL ATOM 1 N SER A 1 114.207 142.287 135.439 1.00 0.00 ... (3 Replies)
Discussion started by: bioinfo
3 Replies

7. Programming

Control multiple program instances - open multiple files problem

Hello. This shouldn't be an unusual problem, but I cannot find anything about it at google or at other search machine. So, I've made an application using C++ and QtCreator. I 've made a new mime type for application's project files. My system (ubuntu 10.10), when I right click a file and I... (3 Replies)
Discussion started by: hakermania
3 Replies

8. UNIX for Dummies Questions & Answers

running script in multiple locations

Hey guys I have written a bash script that compares two directories and displays the files that are different in the directories. Now my problem is the script only runs in my home directory. What do I have to do so it will run in other directories. Thanks if anyone can help. Duplicate post.... (0 Replies)
Discussion started by: Joey12
0 Replies

9. Shell Programming and Scripting

Program to insert Delimiters at fixed locations in a file, Can you please Debug it for me??

Can someone please help?I have a file - fixed.txt----------------------------AABBBBCCCCCCDDDEEFFFFGGGGGGHHHIIJJJJKKKKKKLLL----------------------------To insert delimiters at fixed lengths of 2, 4, 6, 3, I created a file text1.txt as-------------------2463----------------------and trying to execute... (10 Replies)
Discussion started by: jd_mca
10 Replies

10. UNIX for Dummies Questions & Answers

Running a program

Hi.Iam new to Linux.i got linux 7.0 pro and dont know how to run programs. I want a perl interputer and i know i installed one but how do i run it ??? Also how do i run a C or C++ editor ?and how do i run cron ? (3 Replies)
Discussion started by: perleo
3 Replies
Login or Register to Ask a Question