Sponsored Content
Full Discussion: C terminal commands
Top Forums Programming C terminal commands Post 302759465 by Corona688 on Tuesday 22nd of January 2013 10:46:39 AM
Old 01-22-2013
Quote:
Originally Posted by milestails
Sorry, I mean by taking this

Code:
sprintf(leftCmd,"snmpget -v 1 -c \"%s\" %s %s | awk '{print $4 >> \"/tmp/value.txt\" }'", leftComunity,leftIP,leftMIB);

And changing | awk print in=$4 }.
By doing that would I be able to call “in” and get the output?
I still have no idea what you mean by 'call in'.

Code:
./check_snmp_int.pl -H 192.168.1.1 -C public -n eth0 -k --label -w 0,0 -c 0,0 -d 15 -MB | grep in | cut -d '=' -f 2| cut -d "/" -f 1| grep [0-9.] | tr -d '[:alpha:]' | awk '{print $1}'

This command is extremely inefficient. Can you show complete output from ./check_snmp_int.pl -H 192.168.1.1 -C public -n eth0 -k --label -w 0,0 -c 0,0 -d 15 -MB and highlight the parts you want, please? You can probably do it all in one awk.

You can open commands like
Code:
FILE *p=popen("./check_snmp_int.pl ...", "r");
char buf[512];
while(fgets(buf, 512, p) != NULL)
{
        printf("Read line %s", buf);
}

pclose(p);

...but it would be far better to simplify the command you have than use it blindly. You may not need C at all.

Last edited by Corona688; 01-22-2013 at 12:02 PM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Terminal Commands

Hi there. Linux newbie and I'm trying to find commands to: Display number of executable files in a directory that i supply and list them in alphabetical order Back up all the files in the current irectory to a directory i supply, creating that directory if it's not allready there Cound... (5 Replies)
Discussion started by: indigoecho
5 Replies

2. Shell Programming and Scripting

Displaying a dialog box using terminal commands

Hello, I used the command osascript -e 'tell app "Finder" to display dialog "Hey!"' to display a dialog box..it works fine, it displays a dialog box with 'OK' and 'CANCEL' buttons..i want to get the button returned value how can i do that using terminal command? is there any command to get... (1 Reply)
Discussion started by: keshav.murthy@r
1 Replies

3. Cybersecurity

How do i find all the commands entered by root on any terminal

Can any one help me with a script, which runs in background and mails me all the commands entered by root on any terminal for every hour. We have multiple people having root access on the server and creating a mess,i just wanted to monitor all the activity of the root. (13 Replies)
Discussion started by: vishnu787
13 Replies

4. Shell Programming and Scripting

commands in the terminal

hi.. I have a small question...if I have a textfile..let say apple.txt and I want to 1. search for all strings that's 6 characters long, and contains the letters a,b,c,d. 2. search for all words that that begins with "sUn" and ends with "flower" 3. search for all the words beginning with the... (3 Replies)
Discussion started by: Oregano
3 Replies

5. UNIX for Dummies Questions & Answers

help with simple terminal commands

i am at home with a windows xp home, and i am using putty terminal to access my linux mathlab account, my task is to compile and run a C program, called a.c, i used gcc -Wall -g -o mycode a.c to compile it into a mycode file now when i want to run it, i was told i had to use $... (2 Replies)
Discussion started by: omega666
2 Replies

6. UNIX Desktop Questions & Answers

help with some basic osx terminal commands. fixing permissions on NAS share

I'm hoping someone here can help me. I'm computer literate but by no means an expert! I'm simply trying to recover data from my DLink DNS343 NAS mounted on my X86 iMac using SMB. Somehow, in moving to a new computer, I have lost access to some files on the NAS. Just some files are access denied. ... (0 Replies)
Discussion started by: Quantaa
0 Replies

7. Shell Programming and Scripting

Replicate history commands in multiple terminal

Hi, I am using putty client to connect to my remote Linux server box, and I am connecting through ssh. That system runs bash shell. So, if I use multiple putty terminal, how can I replicate those commands that I ran in other terminals to be available/shared in the current terminal window (i.e)... (1 Reply)
Discussion started by: royalibrahim
1 Replies

8. OS X (Apple)

Terminal autorunning commands at start

How do I make terminal autorun commands at start up? For example, I have several windows of terminal, I want one to automatically run 'top' and a couple others autorun 'man' pages. Is there any way I can do this? (1 Reply)
Discussion started by: randomtypos
1 Replies

9. Shell Programming and Scripting

How to save and execute terminal commands in shell?

I frequently use some commands, which I want to save in some file say myregularshell.shthese are the commands I use, I tried saving and executing, but couldn't get the preview of execution, and result is also not coming if I copy same commands and paste it on terminal result is coming cd go... (2 Replies)
Discussion started by: Akshay Hegde
2 Replies

10. Ubuntu

Creating terminal commands

I've written a program in C, called count_0.1 which is essentially a word count program. I want to be able to use it as a command in the terminal (by typing in count), like when you type in ls, you don't have to go to a directory, find an executable and type in: ./ls I've tried: Adding... (1 Reply)
Discussion started by: usernamer
1 Replies
popen(3C)						   Standard C Library Functions 						 popen(3C)

NAME
popen, pclose - initiate a pipe to or from a process SYNOPSIS
#include <stdio.h> FILE *popen(const char *command, const char *mode); int pclose(FILE *stream); DESCRIPTION
The popen() function creates a pipe between the calling program and the command to be executed. The arguments to popen() are pointers to null-terminated strings. The command argument consists of a shell command line. The mode argument is an I/O mode, either r for reading or w for writing. The value returned is a stream pointer such that one can write to the standard input of the command, if the I/O mode is w, by writing to the file stream (see intro(3)); and one can read from the standard output of the command, if the I/O mode is r, by reading from the file stream. Because open files are shared, a type r command may be used as an input filter and a type w as an output filter. The environment of the executed command will be as if a child process were created within the popen() call using fork(2). If the applica- tion is standard-conforming (see standards(5)), the child is invoked with the call: execl("/usr/xpg4/bin/sh", "sh", "-c", command, (char *)0); otherwise, the child is invoked with the call: execl("/usr/bin/sh", "sh", "-c", command, (char *)0); The pclose() function closes a stream opened by popen() by closing the pipe. It waits for the associated process to terminate and returns the termination status of the process running the command language interpreter. This is the value returned by waitpid(3C). See wait.h(3HEAD) for more information on termination status. RETURN VALUES
Upon successful completion, popen() returns a pointer to an open stream that can be used to read or write to the pipe. Otherwise, it returns a null pointer and may set errno to indicate the error. Upon successful completion, pclose() returns the termination status of the command language interpreter as returned by waitpid(). Other- wise, it returns -1 and sets errno to indicate the error. ERRORS
The pclose() function will fail if: ECHILD The status of the child process could not be obtained, as described in the DESCRIPTION. The popen() function may fail if: EMFILE There are currently FOPEN_MAX or STREAM_MAX streams open in the calling process. EINVAL The mode argument is invalid. The popen() function may also set errno values as described by fork(2) or pipe(2). USAGE
If the original and popen() processes concurrently read or write a common file, neither should use buffered I/O. Problems with an output filter may be forestalled by careful buffer flushing, for example, with fflush() (see fclose(3C)). A security hole exists through the IFS and PATH environment variables. Full pathnames should be used (or PATH reset) and IFS should be set to space and tab (" "). The signal handler for SIGCHLD should be set to default when using popen(). If the process has established a signal handler for SIGCHLD, it will be called when the command terminates. If the signal handler or another thread in the same process issues a wait(3C) call, it will interfere with the return value of pclose(). If the process's signal handler for SIGCHLD has been set to ignore the signal, pclose() will fail and errno will be set to ECHILD. EXAMPLES
Example 1: popen() example The following program will print on the standard output (see stdio(3C)) the names of files in the current directory with a .c suffix. #include <stdio.h> #include <stdlib.h> main() { char *cmd = "/usr/bin/ls *.c"; char buf[BUFSIZ]; FILE *ptr; if ((ptr = popen(cmd, "r")) != NULL) while (fgets(buf, BUFSIZ, ptr) != NULL) (void) printf("%s", buf); (void) pclose(ptr); return 0; } Example 2: system() replacement The following function can be used in a multithreaded process in place of the most common usage of the Unsafe system(3C) function: int my_system(const char *cmd) { FILE *p; if ((p = popen(cmd, "w")) == NULL) return (-1); return (pclose(p)); } ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ |MT-Level |Safe | +-----------------------------+-----------------------------+ SEE ALSO
ksh(1), pipe(2), fclose(3C), fopen(3C), stdio(3C), system(3C), wait(3C), waitpid(3C), wait.h(3HEAD), attributes(5), standards(5) SunOS 5.10 17 Mar 2004 popen(3C)
All times are GMT -4. The time now is 05:45 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy