• 10.Aug.17
    Interlacing file lines shell | fernape | (0)
    Recently I needed to mix several files into one single file. The point was that I needed to interlace the files so I had all the first lines of every file followed by all the second lines and so on. Put it simply, this is what I had: fapesteguia@fapesteguia:~/test$ cat file1 file 1 row 1 file 1 row 2 file 1 row 3 file 1 row 4 file 1 row 5 file 1 row 6 file 1 row 7 file 1 row 8 file 1 row 9 file 1 row 10 fapesteguia@fapesteguia:~/test$ cat file2 file 2 row 1 file 2 row 2 file 2 row 3 file 2 row 4 file 2 row 5 file 2 row 6 file ...
  • 18.Feb.17
    Understanding the strace command shell | fernape | (0)
    strace is a utility that traces system calls and signals. It is very useful for debugging purposes, specially if you don't have the source code of the problematic software. In its simple form it works like this: $ strace ls /tmp strace ls /tmp/ execve("/bin/ls", ["ls", "/tmp/"], [/* 80 vars */]) = 0 brk(0) = 0x1c3e000 access("/etc/", F_OK) = -1 ENOENT (No such file or directory) mmap(NULL, 8192, ...
  • 04.Mar.16
    growisofs has the best command flag ever shell | fernape | (2)
    With all the hype about Star Wars, I think this is very appropriate. growisofs is a DVD command-line recorder. It can be used this way: growisofs -Z /dev/dvd StarWars.avi The command has a lot of options, but one of them will catch your eye in the man page. If you find yourself having problems with growisofs and feel like you can take a risk, try with the -use-the-force-luke= option. For example: -use-the-force-luke=dummy for Test Write mode. Enjoy! and may the Force be with you.
  • 29.Jan.16
    What do you expect? shell | fernape | (0)
    Recently at work, we had to write a script to upload several files to an ftp server. Initially, we developed a first version using here documents. It was not bad, but it wasn't exactly what we needed. We told ourselves: "We just want to do this as if we were typing it". After googling for a couple of minutes, we found expect. expect is an utility to program a dialogue with interactive programs. How does this work? It is something like the following: I would launch this program I would expect something in the terms of this string as a result I would ...
  • 13.Jan.16
    Add timestaps to your bash history shell | fernape | (0)
    bash history is very useful to access your past commands. Sometimes it would be just great to know when a command was typed to be able to correlate it to another event. Imagine we know that there was a change in a repository that might have fixed a heisenbug. But we know that not long ago, we saw the bug again. But are we sure it was before the change in the repository was made? We can solve this (and other problems) by adding time stamps to our bash history. Add the following line to your .bash_profile file: export HISTTIMEFORMAT="%d/%m/%y %T " The ...
  • 04.Apr.15
    String manipulation in Bash shell | rafacas | (0)
    I rely on Bash on much of my scripting needs although it is usually not worthy when you need to do something complicated. However, we usually think Bash limits are lower than they really are. In this post I am going to explain the surprising number of string manipulation operations that Bash supports. String Length The syntax to know the lenght of a string is: ${#string} For example: $ string=abcdefghijklmnopqrstuvwxyz $ echo ${#string} 26 Substring Extraction ${string:position} Extracts substring from $string at $position. $ string=abcdefghijklmnopqrstuvwxyz $ echo ${string:1} bcdefghijklmnopqrstuvwxyz Note that strings are zero-based indexed. If you want to extract a substring of a specific length then: ${string:position:length} Extracts $length characters from $string at $position. For example: $ echo ${string:5:3} fgh It ...
  • 09.Feb.15
    Moving a Repository from Bitbucket to GitHub shell | rafacas | (4)
    Some people have asked me how they can move a repository from Bitbucket to Github (or vice versa). To know how to do it we need to understand Git’s remote repositories. Remote repositories are versions of your project that are hosted on the Internet or network somewhere (you can have several of them). First, let’s clone the Bitbucket repository: $ git clone Cloning into ’test'... remote: Counting objects: 124, done. remote: Compressing objects: 100% (120/120), done. remote: Total 124 (delta 42), reused 0 (delta 0) Receiving objects: 100% (124/124), 1.31 MiB | 541.00 KiB/s, done. Resolving deltas: 100% (42/42), done. Checking connectivity... done. To see which remote servers you ...
  • 04.Feb.15
    Editing Binary Files shell | rafacas | (0)
    In a previous post we learnt how to back up the MBR of a hard disk in a file called mbr.img. That file has the first 512 bytes (the first sector) of the hard disk. One way to see the content of a binary file is dumping it to hexadecimal. In Linux the xxd command makes a hex dump: $ xxd mbr.img 0000000: eb63 9010 8ed0 bc00 b0b8 0000 8ed8 8ec0 .c.............. 0000010: fbbe 007c bf00 06b9 0002 f3a4 ea21 0600 ...|.........!.. 0000020: 00be be07 3804 750b 83c6 1081 fefe 0775 ....8.u........u 0000030: f3eb 16b4 02b0 01bb 007c b280 8a74 018b .........|...t.. 0000040: 4c02 ...
  • 02.Feb.15
    Find Integrated Lights-Out IPs in a network shell | rafacas | (0)
    Integrated Lights-Out, or iLO, is a proprietary embedded server management technology by Hewlett-Packard which provides out-of-band management facilities. The physical connection is an Ethernet port that can be found on most Proliant servers of the 300 and above series. It is very useful because it allows to perform activities on an HP server from a remote location. The iLO card has a separate network connection (and its own IP address) to which one can connect via HTTPS. Some of the options I have used are: Reset the server (very useful when the server doesn't respond anymore via the normal network card). Power-up the server ...
  • 30.Jan.15
    Backup & Restore the Master Boot Record shell | rafacas | (0)
    Some days ago I had to recover the Master Boot Record (MBR) of a damaged hard disk. The MBR is the first 512 bytes of a storage device. It contains an operating system boot loader and the storage device’s partition table. If you need to make a backup of the MBR type the following command: dd if=/dev/sda of=/root/mbr.img bs=1 count=512 You only have to change sda with the device name that correponds to your hard disk. To restore it: dd if=/root/mbr.img of=/dev/sda bs=1 count=512 And as before, change sda with the device name that corresponds to the hard disk you are going to restore the MBR ...