Friday, December 1, 2017

Mocking a Web Service with NetCat

Write the web service's response(xml, json, plain text) in a file, and then run the following in a terminal:
$ while true; do echo -e "HTTP/1.1 200 OK\r\n\r\n$(cat wsresponse.file)" | nc -l 9999; done

Where wsresponse.file is the file with the web service response.

In this case, the web service mock is listening in the port 9999. Just change the port as your needs.


Tuesday, August 29, 2017

Thursday, March 9, 2017

Find text inside compressed files


You have a group of files and some of them are compressed with zip or gz and you want to search for a specific text in each of them. To do this, you can use the following command:
find -name [FILE_PATTERN] -print0 | xargs -0 zgrep "[TEXT_TO_FIND]"
Where:
[FILE_PATTERN] : is the pattern of the files.
[TEXT_TO_FIND] : is the text to find inside the files.

Let's say we have the following files:

peter-01.gz
peter-02
peter-03.gz
peterA
peterB.gz
maria-01
maria-02.gz

And you want to find the text "my friend" only in the files that begininng with "peter-". To do this, you can use the following:
find -name peter-\* -print0 | xargs -0 zgrep "my friend"

Note the use of  \* as a wildcard.




Tuesday, March 7, 2017

Copy directories with scp

scp -rp [directory_to_copy] [user]@[host]:[path]
Where:

[directory_to_copy]: directory to be copied
[user]: destination host user
[host]: destination host
[path]: destination path
-r: recursive, copy all directory content.
-p: preserves modification times, access times, and modes from the original file.

Wednesday, February 1, 2017

reboot vs shutdown -r now

Generally shutdown -r now is safer.

In most of the unix distributions they perform exactly the same actions except for Mac OSX. On Mac OSX reboot performs an instant reboot. There is no unmounting and no syncing. So, to avoid headaches, play safe and do not use reboot.

Syntax of shutdown command:

shutdown [OPTION] [TIME] [MESSAGE]

To reboot the system right now safely write:

shutdown -r now


Tuesday, January 24, 2017

Tail command with color

tail -f myfile.log | perl -pe 's/.*TEXT_TO_FIND.*/\e[1;31m$&\e[0m/g'

\e[1;31m will give you the red color. If you would like some yellow, use \e[1;33m, and for green use \e[1;32m. The \e[0m restores the normal text color.

SOURCE: http://unix.stackexchange.com/questions/8414/how-to-have-tail-f-show-colored-output
(Answer <37>)


Popular Posts

Recent Posts

Unordered List

Text Widget

Pages

Search This Blog

Powered by Blogger.