Showing posts with label scripting. Show all posts
Showing posts with label scripting. Show all posts

Sunday, February 3, 2013

Uninstall cpan perl module

Well, cpan is not really a package management system; cpan is more of a package installer, it can resolve dependencies as well, but apparently not in a way that allows it to know if it can safely remove a package or not.

Never the less, there is hope!

There is a cpan package that can actually remove packages :) it installs a tool to remove packages, I'm not sure it does it in an intelligent way actually; but it did it for me.

So, what is it?

The module is App::pmuninstall ; it stands for Perl Module Uninstall. To install pmuninstall just do:

sudo cpan -i App:pmuninstall

then use it to remove modules as it provides a command which is "pm-uninstall":

pm-unistall

for example:

pm-uninstall XML::SAX

FUCK RELIGIOUS NATIONALISM; FUCK ISLAMISM, FUCK ZIONISM, FUCK DOMINIONISM!

Saturday, January 26, 2013

How to convet Months names into numbers in bash

So, today i needed a quick way to rename files and folders with names that include month name into a more computer readable numerical presentation.

I wrote a small shell one-liner that does that for me; i pass the file name as a parameter to a script; the script would remove the month name (whether its short (ex Jan) or long (ex November) and would replace it with a two digit number (from 01 to 12) using sed. the script also matches the names regardless of their capitalization (case insensitive) as sed understands "i" for "insensitive".

the script is below:

#!/bin/bash
echo $1 | sed "s/Jan\|January/01/gi;s/Feb\|February/02/gi;s/Mar\|March/03/gi;s/Apr\|April/04/gi;s/May\|May/05/gi;s/Jun\|June/06/gi;s/Jul\|July/07/gi;s/Aug\|August/08/gi;s/Sep\|September/09/gi;s/Oct\|October/10/gi;s/Nov\|November/11/gi;s/Dec\|December/12/gi;"


The script has been auto generated pretty quickly as well, i had a list of the names of months:

January
February
March
April
May
June
July
August
September
October
November


i piped it ino a small loop that matches the first three characters:

echo January | sed "s/^\(...\)/\1\\\|\1/g"

to output
Jan\|January

a shell variable ($cnt) was set to 0 ; and incremented to print the numerical value corresponding to the month (months are in correct order); and was printed using printf:

printf "%02d" $cnt

a while loop glued it togather:

cnt=0
while read line ; cnt=`expr $cnt + 1` ; do echo -n s/ ;echo -n $line |sed "s/^\(...\)/\1\\\|\1/g" ; echo -n / ;printf "%02d" $cnt ; echo -n /gi\; ; done

and the list was pasted as input! viola! a sed pattern is created :)

Now, Egyptians, Syrians, Palestinians, Iraqis and Bahrain's people are being oppressed for the same reason, INEQUALITY imposed by those who do not believe in equality! call it racism, greed, capitalism ...etc.

Tuesday, August 12, 2008

Windows for Linux Administrators I

I've never been a fan of M$ Windows, but lateley im forced to deal with Windows, So since im having a lot of trouble doing even simple things, i've decided to write a few notes i've learned that would help those who are familiar with linux to administrate windows machines, but you should also know that im not an expert in either systems, any any information provided here is my own interpretation of similarities between these two systems.

First, lets put a list of commands and their equivilent that i learned recently, i wont be talking about "dir" and "rem".

Starting with the ugly "cmd" of windows, we can see that we can use the command "set" to display environment variables, which is the same as what we have in Linux! nice! thats a good starting point. and and interesting example of how things might be a little diffrent, lets try to print the current directory, in linux we would simply type pwd, in windows, you'll do "echo %CD%", where %CD% is an environment variable that holds the "Current Directory".

Variables in windows are put between percentage signs , %VARNAME% and are not case sensetive.

Now the first thing i wanted to do was listing users i have and gather info about them, but in my case, the machine i have access to, via rdestop, is an Active Directory server, which i hope to be able to switch to SAMBA 4 when the later is ready ... so ... how do we do that in active directory?

the command to do so is called dsquery, it stands for "Directory Service Query" and is one tool from the "Directory Service" tools suite that comes with windows 2003, i dont know about older versions.

Now ill try to see how it works, so i look at :
dsquery /? | more


Looks unixish ... heh :), reading a little there i managed to list users (first 100) using the command:
dsquery user


and then i filtered out myself using the command find! an interesting tool that provides similar functionality to some unix tools. lets suppose my name was "Edward Saeed", i do :
dsquery user| find "Edward Saeed"


but note that you Have to use the quotes, and the string IS case sensitive ... inconsistency ... i belive ... but i could use /I to make it case insensitive!

So now we know that find "something" is similar to the "grep" command in unix!

reading find /? shows that find can also count lines! so find /C "something" is equivilent to "grep "something" | wc -l" . thats good to hear ... who can live without grep and wc :)

Thats it for today :), i'll be packing and hitting the road .

Maybe next time ill be trying to rewrite a few bash scripts in this windowish fashion.

;)