def SearchString(pattern,string):
ulist = pattern.split('*')
if len(ulist) > 1:
k = '^' + ulist[0] + '[\w|\_|\-]*' + ''.join([ i + '[\w|\_|\-]*' for i in ulist[1:-1]]) + ulist[-1] + '$'
print k
if re.search(k,user) != None:
return "Found"
else:
return "Not Found"
elif ulist == string:
return "Found"
else:
return "Not Found"
>>> SearchUser('vin*jda*is','vinojdavis')
^vin[\w|\_|\-]*jda[\w|\_|\-]*is$
'Found'
>>> SearchUser('vi**jda*is','vinojdavis')
^vi[\w|\_|\-]*[\w|\_|\-]*jda[\w|\_|\-]*is$
'Found'
>>> SearchUser('vin*jda*is','viojdavis')
^vin[\w|\_|\-]*jda[\w|\_|\-]*is$
'Not Found'
Search This Blog
Tuesday, February 10, 2009
Regular Expression
Tuesday, February 3, 2009
Kill process in Linux or terminate a process in UNIX or Linux systems
Q. How do I kill process in Linux?
A. Linux and all other UNIX like oses comes with kill command. The command kill sends the specified signal (such as kill process) to the specified process or process group. If no signal is specified, the TERM signal is sent.
Kill process using kill command under Linux/UNIX
kill command works under both Linux and UNIX/BSD like operating systems.
Step #1: First, you need to find out process PID (process id)
Use ps command or pidof command to find out process ID (PID). Syntax: ps aux | grep processname pidof processname
For example if process name is lighttpd, you can use any one of the following command to obtain process ID:
# ps aux | grep lighttpdOutput:
lighttpd 3486 0.0 0.1 4248 1432 ? S Jul31 0:00 /usr/sbin/lighttpd -f /etc/lighttpd/lighttpd.conf lighttpd 3492 0.0 0.5 13752 3936 ? Ss Jul31 0:00 /usr/bin/php5-cg
OR use pidof command which is use to find the process ID of a running program:
# pidof lighttpdOutput:
3486
Step #2: kill process using PID (process id)
Above command tell you PID (3486) of lighttpd process. Now kill process using this PID:
# kill 3486
OR
# kill -9 3486
Where,
- -9 is special Kill signal, which will kill the process.
killall command examples
DO NOT USE killall command on UNIX system (Linux only command). You can also use killall command. The killall command kill processes by name (no need to find PID):
# killall -9 lighttpd
Kill Firefox process:
# killall -9 firefox-bin
As I said earlier killall on UNIX system does something else. It kills all process and not just specific process. Do not use killall on UNIX system (use kill -9).
Sunday, February 1, 2009
Variable Datatypes & Range in C
- short int (short)
- unsigned short int (unsigned short )
- char
- unsigned char
- signed char
- int
- unsigned int (unsigned )
- long int (long)
- unsigned long int (unsigned long )
- float
- double
- long double
- short int -128 ® 127 (1 byte)
- unsigned short int 0 ® 255 (1 byte)
- char 0 ® 255 or -128 ® +127 2 (1 byte)
- unsigned char 0 ® 255 (1 byte)
- signed char -128 ® 127 (1 byte)
- int -32,768 ® +32,767 (2 bytes)
- unsigned int 0 ® +65,535 (2 bytes)
- long int -2,147,483,648 ® +2,147,483,647 (4 bytes)
- unsigned long int 0 ® 4,294,967,295 (4 bytes)
- float single precision floating point (4 bytes)
- double double precision floating point (8 bytes)
- long doubl e extended precision floating point (10 bytes)
Wednesday, January 28, 2009
How do I label a Linux partition? How do I display current label?
Display current label
If the optional argument new-label is not present, e2label will simply display the current filesystem label.
$ sudo e2label /dev/sda1
or
# e2label /dev/sda1
Sample output:
/boot
Set a new label
If the optional argument new-label is present, then e2label will set the filesystem label to be new-label. Ext2 filesystem labels can be at most 16 characters long; if new-label is longer than 16 characters, e2label will truncate it and print a warning message. To set a new label, enter:
# e2label /dev/sdb2 usbstroage
It is also possible to set the filesystem label using the -L option of tune2fs, enter:
# tune2fs -L usbstroage /dev/sdb2