Saturday, September 13, 2008

Configuring Apache to run perl

Configuring Apache to run perl :

I have below RPM installed: (Default Fedora 9 Sulphur)

In Fedora 9 perl specification :

$cat /etc/httpd/conf.d/perl.conf

LoadModule perl_module modules/

Alias /perl /var/www/perl

< Directory /var/www/perl >
SetHandler perl-script
AddHandler cgi-script .cgi .pl
PerlResponseHandler ModPerl::Registry
PerlOptions +ParseHeaders
Options +ExecCGI
< /Directory >

< Location /perl-status >
SetHandler perl-script
PerlResponseHandler Apache2::Status
Order deny,allow
#Deny from all
Allow from all
< /Location >

in my /etc/httpd/conf/httpd.conf i have below line
Include conf.d/*.conf

Now put your perl script in /var/www/perl
Content-type: text/html;
print 'mod_perl rock';
[root@linux perl]#

Point your browser ==> http//hostname/

Should show mod_perl rock!

Sunday, September 07, 2008

rename file extentions ...

I wanted to rename all .txt file extensions as .html

$rename s/\.html/.txt/ *.html

Oh, also, this isn't a "standard Unix(TM) command, but it does come with most Perl installations that I know of and Perl is on most Unix machines that I know of.

Also i tried for loop :

for i in *.txt; do mv "$i" `basename $i`.html

But this renames a file file1.txt as file1.txt.html

anyone know how get avoid .html added after .txt ?

Try this :

for i in "${i%.txt}"; do mv "$i" "${i%.txt}".html; done

Exit Status - Shell script

Whenever a shell script is executed it checks the exit status
of command to verify if it executed sucessfully.

True = 0
False = Non Zero Value

You can check exit status value as below:



echo hello
echo $?
# Exit status 0 returned because command executed successfully.

Unrecognized command.
echo $? # Non-zero exit status returned because command failed to execute.



./ line 5 lskdf command not found.

Shell script if statement

Shell script using if statement to check if process is running:


sendmail=`(ps -ef |grep -v grep |grep sendmail)`
if [ -z "$sendmail" ];

echo "Sendmail is not running"

echo "Sendmail is running"


WHat each line means:
1) #!/bin/bash
This generates a Process ID for shell

2) PROCESS=`(ps -ef |grep -v grep |grep sendmail)`
Defining Variable Process:
# When we grep a process ps -ef |grep sendmail, the output result also shows "grep sendmail" line, in order to avoid that we use grep -v grep.

3) if [ -z "$sendmail" ];

-z option tells it should return a null value(no value)

Check for more : man bash

-n str True if string str is not a null string
-z str True if string str is a null string

Sunday, June 22, 2008

while running df command it says read only filesystem

Taking further from my previous post,

I was not able to run df -k command :

It says , no filesystems processed:


To remount root filesystem with read-write :
$mount -o remount,rw /

This will make a entry in /etc/mtab for read,write access to root filesystem

Using Linux Rescue

While trying to install Fedora core 8 on my Virtualbox(VM)
It got hanged after installation was done ...

Here's what I did:

1) Boot through Fedora core 8 CD

2) Select rescue installed system.

3) You will be asked to select the language, which defaults to English. Select the appropriate language and press OK to continue.

4)You will be asked to select the keyboard type, which defaults to us (USA). Select the appropriate keyboard type and press OK to continue.

5) do you want to start network interface - NO

6) Now it says, the rescue environment will find linux install and mount it under /mnt/sysimage - Select Continue

7) now it will say: your sytem is mounted under /mnt/sysimage and will reboot
if you exit - OK

8) now you you get a shell prompt

Once at shell prompt, Type :

i) chroot /mnt/sysimage
ii) fsck /dev/sda1 or fsck -p /dev/sda1

remove disk.
Reboot and check ... your system should be up !

Tuesday, May 27, 2008

Check OS Script ...

I had to check all hosts in a list , if its windows or unix.

Here's what helps identify whether it is Unix or Windows,
Note: Our Windows systems did not have ssh daemon running,

bash-2.03$ cat
for host in `cat list_of_host`
if version=`(sleep 1 ; echo "") | telnet $host 22 | grep -i SSH`
echo "$host $version" >> HOSt-SSH-Running
echo "$host" >> HOST-SSH-Not-running

The above scripts verify if the list of host in file has ssh daemon
running on port 22, in case if it finds running then it appends
that host to HOSt-SSH-Running and rest in HOST-SSH-Not-running.

Sunday, May 25, 2008

Finding Common Occurence in Files and Writing to a New file !

I wanted to compare lines in 2 files and write things which
are common in a different file.

File1 (has line like below)

File2 (has line like below)
etc ...

Which ever is common among file1 and file 2 should be written to file3

Grep does it :

grep -f file1 file2 > file3

file3 will have host2, host3 from above example shown under it.

Tuesday, May 20, 2008

Shell Script Comparing files ...

I have a file (file1) which is like

the list goes on............

Now I want the above lines in files to be compared with files under

File names under /opt/new are as below:

And suppose host1 from file1 is found under Dev(file under /opt/new)
than it should write under a seperate file New-list as host1-DEV


while read line; do echo ${line}-$(grep -l $line /opt/new/*); done < file1 > new-file

The above line reads from file1 and compares the list of hosts given under it with
all files under /opt/new/* and if the host on file matches on any of file.

Then it writes to a new file (new-file) as
host-filename, here host is the one listed in file1 and filename is
the file under which it found the host .

eg if it finds host1 under dev file (/opt/new)

It will write as host1-dev under new-file !

Tuesday, April 08, 2008

echo Command

Use echo command to display text or value of variable.

echo [options] [string, variables...]
Displays text or variables value on screen.
-n Do not output the trailing new line.
-e Enable interpretation of the following backslash escaped characters in the strings:
\a alert (bell)
\b backspace
\c suppress trailing new line
\n new line
\r carriage return
\t horizontal tab
\\ backslash

Thursday, March 27, 2008

Identify Zombie Process in Solaris and Clean it :

bash-2.03$ ps -ef |grep defunct (The one marked in dark below is Parent Process)
zasshr 8134 24291 0 0:00 <defunct>
..It will show u a list.........................

bash-2.03$ ptree 24291
24291 /opt/VRTSvcs/bin/CitiEquity/CitiEquityAgent -type CitiEquit
8134 <defunct>
8205 <defunct>

..It will show u a list.........................

To Find total count for the defunct Parent Process :

bash-2.03$ ptree 24291 |wc -l


To clean the defunct Process:

$ preap 24291
24291: exited with status 0