Storing a Temporary File Using C


 
Thread Tools Search this Thread
Top Forums Programming Storing a Temporary File Using C
# 8  
Old 01-13-2015
Corona is correct - most command line utilities are tuned and designed for a particular purpose, and really are very close to as good as it gets. Unless you are doing this to learn coding, or have some fun messing around with C, I would second the idea: use command line utilities.

A very good reason for this is the 'next guy'. Somebody may need to use what you have. Or modify it because the manager is having a bad day. If it is C code and does not quite cut it, that person will have to find the source and change it. Simplicity and transparency (like a shell script) has a lot to recommend it.

Dedicated well-designed C code is often provably faster than a script. But how fast do you have to go? That file is less than 1MB. So, C may save you 1 or 2ms on modern systems.
This User Gave Thanks to jim mcnamara For This Post:
# 9  
Old 01-13-2015
Quote:
Originally Posted by jim mcnamara
Dedicated well-designed C code is often provably faster than a script.
Code which calls system() a lot, like this one, are often exceptions to the rule. It uses C and shell instead of just shell Smilie
This User Gave Thanks to Corona688 For This Post:
# 10  
Old 01-13-2015
Corona688,

One more stupid question. From your example:
Code:
#include <stdio.h>

int main() {
        char buf[4096];
        char *n=tmpnam(NULL); // Use this as the file name, not tmp_file.

// get the file
... 

        FILE *fp=fopen(n, "r");
        unlink(n);
        // Read a line into 'buf' until we run out of lines
        while(fgets(buf, 4096, fp))
        {
                // Check the contents of 'buf' for what you want
        }
}

How do I get the results of:
Code:
rsync rsync://192.168.3.1/vpnc/test.conf

into the "n" temp file? Forgive me for my stupidity. Also when I attempt to compile my code, its says to use mkstemp

Last edited by metallica1973; 01-13-2015 at 02:49 PM..
# 11  
Old 01-13-2015
Honestly I wouldn't use rsync, I'd use scp.

Code:
scp username@host:/etc/passwd /tmp/filename

...and mkstemp will not do what I want because C is not creating the file here.
# 12  
Old 01-13-2015
Unfortunately I have to use the above method (rsync) for obtaining the file. Let me see what I can come up with. Thanks for the help
# 13  
Old 01-13-2015
# 14  
Old 01-14-2015
Quote:
Originally Posted by metallica1973
Unfortunately I have to use the above method (rsync) for obtaining the file.
And what protocol is rsync using? Often it's just sftp or scp.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Finding specific string in file and storing in another file

Text in input file is like this <title> <band height="21" isSplitAllowed="true" > <staticText> <reportElement x="1" y="1" width="313" height="20" key="staticText-1"/> <box></box> <textElement> <font fontName="Arial" pdfFontName="Helvetica-Bold"... (4 Replies)
Discussion started by: aankita30
4 Replies

2. UNIX for Dummies Questions & Answers

Mailx - temporary mail message file: No such file or directory

How would I go about resolving this error temporary mail message file: No such file or directory Can anybody tell me where the default location is for the temporary mail message file is for mailx? It appears that it doesn't exist. Thanks (1 Reply)
Discussion started by: joen
1 Replies

3. Shell Programming and Scripting

How to remove a temporary file inside gawk

Hi- How can I make the temporary file 0 byte , created inside gawk. I am using system("rm -f temp_orders"); It seems system command is deleting file permanently and I am not able to execute below statement. print ORD_HEAD_FULL >> cFILE; (cFile is temp_orders) (2 Replies)
Discussion started by: ashish_kaithi
2 Replies

4. Shell Programming and Scripting

How to remove the first line of a file without using any temporary file

I want remove first line of the file without using any temporary file. Everything should be done in the original file itself since I don't any file creation access whereas I have modify access. It would be great if somebody help in this regard ASAP . Thanks in Advance. Kishore:mad: (1 Reply)
Discussion started by: tvbhkishore
1 Replies

5. UNIX for Dummies Questions & Answers

mailx command - Temporary mail file: permission denied

Hi , I am facing a problem with respect to mailx command in unix . Earlier it was working fine and I am facing this issue only from last week . I used mailx command and I am getting a error message as follows : temporary mail file: Permission denied If I run mailx command from... (2 Replies)
Discussion started by: deepav1985
2 Replies

6. Shell Programming and Scripting

temporary file to file then move to directory

Ok in my bash script i have 5 options to create a simple html script. I need to create a temporary file and whatever the user types will be stored in that file using html codes. And then I have another option in which that temporary file will be moved to the public_html directory in which the user... (19 Replies)
Discussion started by: gangsta
19 Replies

7. Shell Programming and Scripting

Perl : how to modify a file without generate a temporary file

Hi All, I have a file like below, how can i insert one line after line 1 without using a temporary file in perl? line 1 line 2 line 3 expected result line 1 new line <---insert here line 2 line 3 (2 Replies)
Discussion started by: summer_cherry
2 Replies

8. AIX

error : pg: 0652-122 Cannot write to the temporary file

Hi All, I'm getting this error when I use "pg". /tmp is not full and the permission is correct. root@axappk01::/home> hostname|pg pg: 0652-122 Cannot write to the temporary file. Please advise. (6 Replies)
Discussion started by: fara_aris
6 Replies

9. Shell Programming and Scripting

remove temporary file ?

Hi all, In the script I am creating a temporary file with process id as temp.txt.$$ I want to remove this tomporary file first from the current directory when i'll run the same script next time. Note: Every time when the script executes then it has unique process id and it'll create a... (5 Replies)
Discussion started by: varungupta
5 Replies

10. Ubuntu

Avoid creating temporary files on editing a file in Ubuntu

Hi, My ubuntu flavor always create temporary files having filename followed by ~ on editing. For eg: if I am editing a file called "sip.c", automatically a temporary (bkup) file is getting created with the name "sip.c~". How to avoid this file creation? (7 Replies)
Discussion started by: royalibrahim
7 Replies
Login or Register to Ask a Question