How to configure Jenking without GUI

It is possible to create the jobs in jenkins using Groovy.
You can create a Groovy script file $JENKINS_HOME/init.groovy, or any .groovy file in the directory $JENKINS_HOME/init.groovy.d/, to run some additional things right after Jenkins starts up.

In Ubuntu $JENKINS_HOME is by default configured in /var/lib/jenkins/

Continue reading

Remove line breaks in CSV

You have a CSV lines with new line breaks and you need one line per entry.


A simple solution could be:
sed ':a;N;$!ba;s/\r\n/ /g' myfile.csv > myfile_no_nline.csv
If the new lines inside the CSV body are Windows new lines (\r\n) and the CSV lines are UNIX (\n).

But normally you are not so lucky. So if your CSV new lines are between quotes (“) you can use the following command:
cat myfile.csv | gawk -v RS='"' 'NR % 2 == 0 { gsub(/\n/, "") } { printf("%s%s", $0, RT) }' > myfile_no_nline.csv

Minimum HTTP server with netcat


Sometimes you need to have a simple HTTP server. You want to check connectivity from other machine or whatever sinister reason you can have.


We are going to create a simple HTTP server at port 8000.
You can use the netcat command:

nc -l -p 8000 -c 'echo -e "HTTP/1.1 200 OK\n\nHello $(id -un)\nCurrent time $(date)"

Then you can go to a web browser and write load the url at the port 8000


But this works just for one connection, after that connection you must execute again the nc command, so to accept more connections you must add a while loop:

while [ 1 ];do nc -l -p 8000 -c 'echo -e "HTTP/1.1 200 OK\n\nHello $(id -un)\nCurrent time $(date)"'; done

May be you want to display a simple html file (with no images, ajax or any other HTML element that launchs more HTTP requests) like this one:

<!DOCTYPE html>
This is a simple<br/>
webserver running with

Let’s suppose that you have your html saved in a file called index.html, then you can show it in your netcat server as follows:

while [ 1 ];do nc -l -p 8000 -c 'echo -e "HTTP/1.1 200 OK\n";cat index.html'; done

If you are not able to connect to your netcat server may be you have activated iptables, take a look writing as root:

iptables -L

If you want to remove the iptables that can be blocking this requests write the following commands as root:

iptables -F
iptables -X
iptables -P INPUT ACCEPT

Replace content of multiple files


Imagine you have some misspelled words in some documents:

$ grep Intalac *
file02.html: <h2 align="left"><a name="ubuntu"></a>Intalación en Ubuntu 12.10<img src="img/009-ubuntu.png" width="62" height="59"></h2>
file04.html: <h3 align="left">Intalación en Ubuntu <img src="img/009-ubuntu.png" width="62" height="59"></h3>
file04.html: <h3 align="left">Intalación en Ubuntu <img src="img/009-ubuntu.png" width="62" height="59"></h3>

In this case you want to change a word in all the documents.


You can use sed with vi commands:

sed -i 's/<original>/<replaced>/g' 

In this case we can solve the problem with

sed -i 's/Intal/Instal/g' *.html