bash debug – log all executed commands

2014-02-03 1 min read bash
Screenshot of a Bash 3.1 session demonstrating its particularities. Shows exporting a variable, alias, type, Bash’s kill, environment variables PS1, BASH_VERSION and SHELLOPTS, redirecting standard output and standard error and history expansion. A POSIX session is launched from a normal session. Finally, the POSIX session kills itself (since just “exit” would be too boring). (Photo credit: Wikipedia) Whenever I am writing a script in perl or bash, I always wish that there Continue reading

vim maps – simple commands to do stuff.

2013-08-28 1 min read Vim Tips
Some time back, I was working on some script for logging and I wanted to change the class to function like this: $logger->Debug("Test string"); loggerFunc("Debug", "Test String"); As you can see, this change could be quite frustrating if you have quite a few references. And thus vim comes to rescue. Simple map like :: :map ,mm :s/(.*)$logger->(.*)((.*)).*/1loggerFunc("2",3);/ and then I can do “/$logger->” and then “n” to go to next match. Continue reading

convert tabs to spaces, the easy way

2013-07-08 1 min read bash Fedora
Lots of times you want to convert tabs to spaces and sometimes from a shell script, if that is the case, then simple solution is “tidy“. First you need to install tidy as follows: sudo yum install tidy and then you can use the command tab2space. tab2spcae This will print the output to STDOUT by default which you can redirect if you want. Related articles All You Wanted To Know About HERE Documents in Linux

Compare files excluding certain lines.

2011-10-18 1 min read bash Fedora Learning Linux
Quick tip, you can use any expression for the sed commands in the (). With this trick you can redirect the stdout of 2 commands to the diff command. This might become very useful, if you want to compare 2 files, excluding the first line. diff <(sed '1d' file) <(sed '1d' file2) More interesting example is where the string ABC is converted to abc before comparing in the second file with the following command: Continue reading

faster bash operations on files with File Descriptors.

2011-06-11 2 min read bash Learning Linux
I was writing a bash script that would do some operations and read and write to file. Seems that that was pretty simple with 1 2 3 4 5 <td> <div class="text codecolorer"> while read line<br /> <br /> do<br /> <br /> done<file </div> </td> </tr> and then use redirection operations like “>” and “»” to write to file. Done with the script pretty fast. So far so good, when I went for real life tests, no one was interested in using it, why? Continue reading

Terminating a SSH session after starting background process.

2011-05-14 3 min read Learning Linux
This is too good. If you are planning to start a background process in the bash script in the background and continue in the script, you cannot do it until……. You would need to close the stdout/stdin and stderr before you can terminate any ssh session automatically. Here’s some more light on this topic. On Thu, Sep 01, 2005 at 05:33:28PM -0400, Roberto C. Sanchez wrote: > I occasionally log into a machine remotely and start a process in the > background: > > command & > > However, when I log out of the machine, the ssh process on my local > machine blocks. Continue reading

write the output of a command to /var/log/user.log… each line will contain $USER, making this easy to grep for.

2010-12-28 2 min read bash Learning Linux
write the output of a command to /var/log/user.log… each line will contain $USER, making this easy to grep for. 1 <td> <div class="text codecolorer"> &nbsp;log() { (echo "$ $@";$@) | logger -t $USER; } </div> </td> </tr> This command is useful if you want to copy the output of a series of commands to a file, for example if you want to pastebin the output from ‘uname -a’, ‘lspci -vvv’ and ‘lsmod’ for video driver trouble-shooting on your favorite Linux forum. Continue reading
Older posts