sreda, 14. november 2012

Running sudo command without password

What I found out is that running a command using sudo without entering password there are two options:

  • echo PASSWORD | sudo -S COMMAND
  • adding following lineto /etc/sudoers:
username ALL=(ALL) NOPASSWD: COMMAND
Please note that this has to be after all group definitions.
You can check what sudo priviliges you have using
sudo -l
For this case this gives:
(ALL) ALL
(ALL) NOPASSWD: COMMAND 
This means that all command require password except for the COMMAND. If we would put the username definitin before group definitions sudo -l would give:
(ALL) NOPASSWD: COMMAND
(ALL) ALL
This would still require password for all commands.

sreda, 07. november 2012

Find where code was changed in Mercurial

If you want to find out in which revisions a piece of code was changed then you can use a Mercurial command something like this:

hg grep --all PIECE_OF_CODE | awk 'BEGIN {FS=":"} {print $1" "$2}' | uniq
and you will get back a list of files with coresponding revisuin numbers:
repo/src/java/com/kovica/File1.java 30
repo/src/java/com/kovica/File1.java 10

torek, 06. november 2012

Remove empty lines from a file on Linux using command line

This one is especially useful when searching through Glassfish's log files.
There are many ways you can remove empty lines from a file:

  • awk 'NF' file
  • sed '/^$/d' file
  • grep "^$" -v file
  • grep . file
  • egrep "^[[:space:]]?$" -v file
  • perl -n -e 'print unless /^\s*$/' file
And I'm sure there are many more. :)