Tuesday, November 12, 2013

How to use SUID for shell scripts in Linux?

Question : How to write a shell script which will read the required passwords/connect strings from a config file? Other users should be able to execute the scripts, however they should not be able to read the config file.

Say, I have a config file, myconfig.txt, which contains credentials for an oracle connection:
$ cat myconfig.txt

Tuesday, August 13, 2013

Python - How to write a list to a file?

How to write an entire list of elements into a file? Let us see in this article how to write a list l1 to a file 'f1.txt':

1. Using write method:


for ele in l1:

 The list is iterated, and during every iteration, the write method writes a line to a file along with the newline character.

Tuesday, July 30, 2013

Python - How to find the location of a module?

When a module is imported into a program, how to find out the path from where the module is getting picked?

    In the Unix world, when a command say ls is executed, the operating system searches in a list of directories for the command executable and once found, executes the command. The list of directories is maintained in the PATH variable.
    Similarly, in Python, whenever a module is imported, say "import collections', python also searches in a list of directories to find the module file "collections.py", and once found, includes the module. The list of directories to be searched is maintained in a list, sys.path, from the sys module. Hence, this can be accessed using the sys.path.

Friday, July 19, 2013

Perl : Foreach loop variable is an alias

 In Perl, when an array is traversed using the foreach loop, the variable holding the element of the array during the iteration is actually an alias to the actual element itself. Due to this, any change done to this variable automatically updates the array itself.
   Let us see some examples where every element of an array has to be added by 10:

1. Array elements get updated when updating $_:
use warnings ;
use strict ;

my @arr=(5..8);
print "@arr";
foreach (@arr){
print "@arr";
 This snippet when run outputs:
5 6 7 8
15 16 17 18
  As seen above, just by updating the $_, the array elements get updated automatically.

Wednesday, July 17, 2013

Linux For You - A magazine for Open Source techies

    Linux For You(LFY) or the OpenSource For You is the magazine which you should be having if you are a techy, especially for the ones working in Unix or Linux flavors. I accidentally got my hands on the magazine once, and made it a point to subscribe to it immediately.

  My 5 reasons why it is a must in your shelf:

1. Knowledge on Linux World: Linux is one such technology which has no limits. You keep learning, Linux keeps providing something new for you to satisfy your hunger. However, its not possible to learn everything by ourself through our experiments. It takes lot of time to learn anything by oneself. This magazine  is a place wherein you get lot of knowledge, good knowledge, in a short span of time. The topics covered can be of any programming language, scripting language, system administration stuff, apps programming stuff, review of any particular software, etc. Last but not the least, the articles always come with lots of explanation.