2012. február 29., szerda

sudo -e is to edit

Another interesting thing I just realised lately while reading the sudo manual page on Linux. The sudo command has an inbuilt option, '-e' to edit files. You do not have to invoke your favourite editor, provided that your EDITOR or VISUAL environment is set correctly. The '-e' option will do it for you. See the example below.

For many years before, when I wanted to edit a file with root permissions, I just did

[qmi@debian: ~]$ sudo vim /etc/shadow

Now, I use the '-e' option to sudo and leaving the editor out.

[qmi@debian: ~]$ sudo -e /etc/shadow
root:$6$[SAFEHASHDATAHERE]:15377:0:99999:7:::
daemon:*:15377:0:99999:7:::
bin:*:15377:0:99999:7:::
sys:*:15377:0:99999:7:::
sync:*:15377:0:99999:7:::
games:*:15377:0:99999:7:::
man:*:15377:0:99999:7:::
lp:*:15377:0:99999:7:::
mail:*:15377:0:99999:7:::
news:*:15377:0:99999:7:::
sudo: /etc/shadow unchanged
[qmi@debian: ~]$

A good sysadmin reads manuals, it pays off ;-)

2012. február 20., hétfő

rename - a tool to rename files in batch

A long-forgotten Linux tool I found lately, called rename. It is a Perl script on Debian in the /usr/bin/ folder available as 'prename'. It is a very useful tool to rename files in a batch! Let's take an example. Suppose you've got a bunch of .sh extension files you want to rename to .bash in one step, of course.

$ ls -1 *.sh
atnev2.sh
atnev.sh
basecssfix.sh
child.sh
ekezefix.sh
$ rename 's/\.sh/\.bash/' *.sh
$ ls -1 *.bash
atnev2.bash
atnev.bash
basecssfix.bash
child.bash
ekezefix.bash


Brilliant! You can of course do it with writing a code shell script. I already had a Python solution as well, which I liked, but now it's good to know that rename is available as part of the main distribution. Look at the Python code below.


# File: rename.py
# Desc: renames files in a directory according to a given
#       global pattern
# Date: Tue, 23 Mar 2004 17:01:03 +0200
import glob, os

DIR1="./"
DIR2="./"

os.chdir(DIR1)
for file in glob.glob('*.jpg'):
        (base, extension) = os.path.splitext(file)
        os.rename(file, os.path.join(DIR2, base + '.png'))



The above code renames files with '.jpg' extension to '.png' in the current directory.  

2012. február 13., hétfő

My work terms

After failing more than one time working with dodgy companies and finding unacceptable working conditions, I have decided to write a few words about my acceptable work terms. These outline the ideal necessary conditions under which I am willing to conduct all business at any employer's environment, including daily communication with fellow employees, code of ethics and code of conduct. This applies to working at any company regardless of the country or culture. To make it simple, this blog describes my work terms.  By following these terms I show example how to behave at a working place. These terms are a must and a mandatory requirement everywhere I will be working in the future. No IT Manager, no CTO, no other boss or no work contracts are allowed override these terms on the basis of his/her position or authority. NO EXCEPTIONS.

Individual accountibility
This means that every person, including myself must be able to stand by and take responsibility for the acts or actions during work. Each employee's acts must be able to be tracked down by the company information systems to a certain individual. This strengthens IT security and ensures the transparency of the employee's actions. Blurred lines that could jeopardise this requirement or providing unjustifiable, equivocal traces (i.e. unclear separation of duties between teams or within a group of employees) are not acceptable. Using others' credentials impersonating someone else is by no means acceptable. Each worker must use his/her credentials to conduct or complete the given task. Sharing credentials (i.e. user, password information) is only acceptable with the owner's presence and clear consent.

Focus on task
During business hours, everyone's responsitibility is to focus on the work that is assigned. No deliberate distractions are allowed. The only reason to interrupt the work is to eat or taking ergonomic breaks for general health and well being and for the reason of being ill / unwell (feeling pain).  The duration of such breaks are laid out by the work law of the country.

Respecting others
This means that the employee must respect others and only interrupt fellow employees if the topic is work related. Disturbing others with non-work related matters  (i.e. playing loud music, watching youtube/facebook etc. videos, making dirty jokes or ironical references or any other unlawful behaviour) as well as act of dishonesty, indecent or immoral acts, verbal or written harrassment, bullying (i.e. swearing, using bad or inappropriate language in email, letter) is strictly forbidden. Employees must maintain professional demeanour at all times.

Proper use of the company resources
During business hours it is every employee's responsibility to use the company work assets, network, infrastructure and equipment for only work related matters. Using the company assets, network, equipment for personal reasons is only limited to incidental situations when it is absolutely necessary and cannot be carried out otherwise. Any other personal use is not cultivated (i.e. using company email address for personal reasons, visiting social networking sites, sports, betting or online games, adult sites or any other entertainment). In the company environment (i.e. office) no picture, poster or sign is allowed that could negatively affect good morals or by any means disturbing or discriminating against any religion, human race, age, skin colour, gender, political affiliation.