Saturday, September 13, 2008
Configuring Apache to run perl
I have below RPM installed: (Default Fedora 9 Sulphur)
----------------------------------
httpd-2.2.8-3.i386
mod_perl-2.0.3-21.i386
In Fedora 9 perl specification :
===============================
$cat /etc/httpd/conf.d/perl.conf
*)
LoadModule perl_module modules/mod_perl.so
*)
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
test.pl
========
#!/usr/bin/perl
Content-type: text/html;
print 'mod_perl rock';
[root@linux perl]#
Point your browser ==> http//hostname/test.pl
Should show mod_perl rock!
Sunday, September 07, 2008
rename file extentions ...
$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
of command to verify if it executed sucessfully.
True = 0
False = Non Zero Value
You can check exit status value as below:
Eg:
#!/bin/bash
echo hello
echo $?
# Exit status 0 returned because command executed successfully.
lskdf
Unrecognized command.
echo $? # Non-zero exit status returned because command failed to execute.
$./script.sh
hello
0
./script.sh line 5 lskdf command not found.
127
Shell script if statement
================================================================
#!/bin/bash
sendmail=`(ps -ef |grep -v grep |grep sendmail)`
if [ -z "$sendmail" ];
then
echo "Sendmail is not running"
else
echo "Sendmail is running"
fi
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
I was not able to run df -k command :
It says , no filesystems processed:
Solution:
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
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 ...
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 checkos.sh
#!/bin/sh
for host in `cat list_of_host`
do
if version=`(sleep 1 ; echo "") | telnet $host 22 | grep -i SSH`
then
echo "$host $version" >> HOSt-SSH-Running
else
echo "$host" >> HOST-SSH-Not-running
fi
done
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 !
are common in a different file.
Eg,
File1 (has line like below)
===========================
host1
host2
host3
etc.....
File2 (has line like below)
===========================
host2
host3
host4
host5
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 ...
host1
host2
host3
host4
the list goes on............
Now I want the above lines in files to be compared with files under
/opt/new/*
File names under /opt/new are as below:
Dev
Prod
QA
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
Ans:
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.
Options
-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
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
158
To clean the defunct Process:
$ preap 24291
24291: exited with status 0