Hi everyone, I need a C++ script to extract only the time's value from this terminal output (for example 0.019 0.019 0.024 etc.) and to do it for every line while I'm pinging. Any ideas how this can be achieved? Thank you!
You can form a command as which will dump the ping result in a file and then you can get the time from the file.
std::string command ="ping 192.162.1.11 > myfile.txt"
system(command.c_str());
you will get result into myfile and then grep "time=" from the file.
Related
I am trying to redirect outputs of systat -ifstat and systat -vmstat to a file and When I open that file, lot of special chars are added to a file like below
(B)0[?1049h[1;39r[m[4l[H[2J[1;21H/0 /1 /2 /3 /4 /5 /6 /7 /8 /9 /10
[68DLoad Average
[11DInterface[4;27HTraffic[4;49HPeak[4;69HTotal[2;21H[5;13H1/1 in[6C0.000 KB/s[5;46H0.000 KB/s[5;66H260.087 MB[6;18Hout 0.000 KB/s[6;46H0.000 KB/s[6;66H205.319
The command I am using to redirect to a file is below:
systat -ifstat 1 > text.txt
Can someone guide me to get rid of these special chars.Help is appreciated.
Keep in mind that systat(from the man page) display system statistics in a screen-oriented fashion using the curser screen display library, therefore in the try to get something like a screenshot, this partially works:
systat -ifstat | tee /tmp/output
to see the output like when using the command you will need to do cat /tmp/output, otherwise you will see all the shell escape characters.
You could also try script:
$ script
Script started, output file is typescript
$ systat -ifstat
next, you exit systat ctrl+c
$ exit
exit
Script done, output file is typescript
This will create a file named typescript but the output is not as clear as when using tee. (still, haven't found a way of how to render properly typescript within csh)
I need to make some bash script that stores all its input to file/pipe and reads its output from other file pipe and run forever. First part is like cat - > pipein and second is like cat pipeout. But how to make both parts simultaneously?
I also tried to mess with additional file descriptors but with no success.
Found an answer!
#!/bin/bash
cat pin &
cat >pout
wait
i have a file consists of each word in a line.
eg:- file consists of
9/20/16
11:00
vamsi
I want to make each line as an input to console when ever it waits for input
eg:- console is like
PLEASE ENTER TODAY'S DATE : 9/20/16
PLEASE ENTER CURRENT TIME : 11:00
PLEASE ENTER USER NAME : vamsi
It should take input from the file line by line like above.
Looks like you need Expect. It's commonly used to respond to interactive prompts in shell programs based on file input.
Simply use that file as input:
program < file
For example, I want to select my timezone using the tzselect tool.
For my timezone, I need to enter
7
16
2
1
Saving this contents into input.txt, I can run tzselect with
tzselect < input.txt
This gives the same output as if the values have been typed in manually.
I have a script that pulls information from a file and outputs it to a different file. What i need to do is run this script everyday but output to a different file. I will have this in the crontab to run everyday at the same time but i dont know how to output to a different file everyday. Is there a loop i can use?
Regards,
John
You don't need a loop. Rather, use a stdout/stderr redirection to a filename created using 'date'
e.g.
$ myprocess.sh > `date +"%m-%d-%Y"`.log
so date is executed in the backticks (this is known as command substitution) and the output substituted in the line. Here the formatted output of date is used as the log file name (in this case 04-24-2014.log)
I'd like to run a program several times with slightly different inputs. The input file is a long .in file, and I'd only want to edit a single number in a specific line of that file. So ideally I'd like to write a Unix script that repeats this process several times:
Edits a line in a .in file
Runs a program which uses that file as input
Renames the output .nc file from the program and saves it
I'm completely new to this sort of scripting, and while I'm pretty sure I can figure out how to do steps 2 and 3 of this process, I'm not sure how to do the second step. Is it possible to use a script to automate the editing of a .in file, and how would I do that?
Here's an example that should get you started:
$ echo cat says meow >say.txt
$ sed -i s/meow/meowwwwwww/ say.txt
$ cat say.txt
cat says meowwwwwww
Let me know if you need more help.