Saving Ping command output into a variable with a batch file [closed] - string

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am building a batch-file for some rudimentary ping connection monitoring on my network and i want to know how i might save the output from a ping command to string. later steps i would like to pull specific data out of that string as needed. Then i would like to do things based on the data stored in the string. such as play a sound when packet loss occurs.

Split the ping output line with delimiters Space, Equal, Less, and use 7th token if 8th token is "TTL".
This code works for me, it puts reponse time in miliseconds to environment variable %RESPONSE%:
SET IP=google.com
FOR /F "tokens=1-9 delims==< " %%a IN ('PING -n 1 -w 2500 %IP%') DO IF "%%h"=="TTL" SET RESPONSE=%%g

Related

How to scan a folder for unused images Python [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 11 months ago.
Improve this question
I have a folder of images.
I want to read all images and do some processing.
But next time if I run the script again, it should not consider already processed image, only new one.
What is the conventional way to do this?
You could use sqlite to store data about already know files https://docs.python.org/3/library/sqlite3.html
Later you could expanse the idea and use SQL to get bigger goals as "when it was processed" "what command you used to process"

Output with 3 dots and 2 dots, read from right to left [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I get an exit behind a series of commands that returns me a huge list of servers.
Which start like this:
...linux.sapsmftexp01 ...linux.sappiftexp01 ...linux.sapbwftexp01
..linux.radiuswifiexp01 ..linux.gitlabexp01 ..linux.redisccexp01
I need to get only the name information, i.e .:
sapsmftexp01
sappiftexp01
sapbwftexp01
When I have tried to do it with cut -d
It deprives me of others, the same happens with awk, but someone has told me that I can do it from right to left, but I don't know how to do it.
Could someone help me please?
With sed:
sed -r 's/(linux)|(\.)//g;s/ /\n/gp' file
First remove any occurrences of "linux" or full stop and then replace spaces for new lines.

Redirect file in linux using length [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Am trying to redirect the file based on the length.
I have a file having the value, I like Linux
I have to create a new file base on length, 0-6 will provide me I like.
In case of line number we can redirect using,
head-100 file_name.txt > file_name_new.txt
Not sure how to redirect using length of the data.
Any suggestion will be helpful
When you say "length of data", do you mean number of characters of each line? If so you can use cut command:
head -n100 file_name.txt | cut -c 1-10 > file_name_new.txt
Where [1-10] is the range of the characters you want to keep.

Change the name log names with increment number when new log name created [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I have following log files in my directory
process.1.log, process.2.log, process.3.log, process.4.log, process.5.log
I want to run one script or command where the directory files should change
process.2.log, process.3.log, process.4.log, process.5.log, process.6.log
I recommend rename rather than mv. Of course we will start with renaming the highest number first as user1934428 wrote, but rename without any extra option prevents loss of logfiles if we get the order wrong.
ls -rv process.*.log|rename 's/\d+/$&+1/e'

How to print on stderr without using /dev/stderr [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
How can a linux command script print warnings or error messages without using >/dev/stderr each time?
This should be simple but I don't get it.
Can you post a simple example?
To print to standard error, use a command that writes to standard output (like echo or printf) and redirect the output to file descriptor 2.
echo "This goes to standard output"
echo "This goes to standard error" >&2
This is the most common use of the file descriptor duplication operator, which makes the descriptor indicated by the preceding number (or 1 if omitted) a copy of the descriptor indicated by the following number.
Every unix process always has three open file descriptors when the process starts.
0 is stdin
1 is stdout
2 is stderr
http://man7.org/linux/man-pages/man3/stdout.3.html

Resources