Thursday, 27 February 2014

Watch videos in linux terminal

To install Livestreamer on Fedora, CentOS or RHEL:

 yum install python-pip
  pip install livestreamer 

Run livestreamer command with the URL:

 livestreamer http://www.youtube.com/watch?xxxxxxxxxx

You can also adjust the quality,

livestreamer http://www.youtube.com/watch?xxxxxxxxx 360p

Also with specific palyer,

livestreamer --player=mplayer http://www.youtube.com/watch?xxxxxxxxx
 360p
 

Wednesday, 26 February 2014

script to create tar files within specific size

If you want to take backup tar of public_html folder with tar files have specific size.
Please use below command.

tar -cv public_html/* | split -b 25000K --suffix-length=4 --numeric-suffix - sara.tar.

It creates many tar files with size of 25MB.

If you place this files under same directory and execute the below command to extract it.

cat falooka.tar.* | tar xvf -

it provides the public_html folder.

I already tested this script. Use it.

Tuesday, 25 February 2014

search and remove specific content in files.


f above command gives you correct output, execute following command to perform actual cleaning:


grep -lr --include=*.php "eval(base64_decode" /path/to/webroot | xargs sed -i.bak 's/<?php eval(base64_decode[^;]*;/<?php\n/g'


Executing above will remove eval(*) codes.  Above command will also generate a backup version of files it will modify. For example, if it removes code from index.php, you will find a new file index.php.bak in same directory with original content of index.php


Missing <?php tag in the beginning:
To add “<?php: tag in the beginning of index.php files, in case if you remove it accidentally use following command:

find /var/www/ -name "index.php" | grep "/htdocs/index.php" | xargs grep -L "<?php" | xargs sed -i "1s/^/<?php \n/"

Don’t worry. If you already have a “<?php ” tag in the beginning, it won’t be added again.
Extra Newlines at the top!
If you find after cleanup, extra newlines at the top of your code, then use following command to remove trailing newlines. Extra newlines creates problem for blog feeds.

find . -name '*.php' -exec sed -i -e :a -e '/^\n*$/{$d;N;ba' -e '}' '{}' \;




Saturday, 22 February 2014

Redirect the request from Apache to tomcat using mod_proxy

If you want to redirect the apache request to tomcat[8080],use mod_proxy module.

Eg:

You want access http://192.168.1.10:8080/support with this url example.com/support.

Please go to virtual host entry for example.com in httpd.conf,

<VirtualHost 192.168.1.10:80>
ServerAdmin support@example.com
DocumentRoot /var/www/example.com/public_html
ServerName example.com
ServerAlias www.example.com
ScriptAlias /cgi-bin/ /var/www/example.com/public_html/cgi-bin
#Options +Indexes
<Directory /var/www/example.com/public_html/cgi-bin>
AddHandler cgi-script .cgi .pl
</Directory>
ProxyPass /support/ http://192.168.1.10:8080/support/
RewriteEngine On
RewriteOptions Inherit
</VirtualHost>


Also if you want to redirect some specific url's to another port use below method,

ProxyPassReverse / http://%{HTTP_HOST}:8080/
RewriteEngine on
RewriteCond  %{REQUEST_URI} .*\.(flv|mp4|mp3)$
RewriteRule ^/(.*) http://%{HTTP_HOST}:8080/$1 [P]

In this above example, requests for flv,mp4 & mp3 are redirected to port 8080 and then remaining ports are handled on regular port 80.

Thursday, 20 February 2014

copy some rules from a file to all .htaccess files


find /home/*/public_html -name ".htaccess" -exec cp {} "{}_$(date "+%F")_bak" \;

for i in `cat htsearch.txt`; do echo $i; rsync -avzr --append /htaccess $i; sleep 1; done;

Thursday, 13 February 2014

Remote smtp setup in exim

 - Copied default exim.conf from other cpanel server and added the below entries as client updated and restarted exim. Mails started working fine.

In exim.conf:
--------------
begin authenticators
mailjet_login:
driver = plaintext
public_name = LOGIN
client_send = : APIKey : APISecret [ Corrsponding key values here ]

* Only include the begin authenticators if it does not exist already, if it does just paste the rest below it.

2) Add a route in the Router Configuration:
send_via_mailjet:
driver = manualroute
domains = ! +local_domains
transport = mailjet_smtp
route_list = "* in.mailjet.com::587 byname"
host_find_failed = defer
no_more

3) Add a transport to the Transport Configuration:
mailjet_smtp:
driver = smtp
hosts = in.mailjet.com
hosts_require_auth = in.mailjet.com
hosts_require_tls = in.mailjet.com

Saturday, 8 February 2014

Trouble shoot Apache segmentation fault issues

Server restarted gracefully.

Graceful restart requested, doing restart

[Thu Apr 26 02:17:26 2012] [notice] seg fault or similar nasty error detected in the parent process

We found the problem by using strace to watch httpd activity during failure. I had found that a /etc/init.d/httpd stop and /etc/init.d/httpd start worked fine, but /etc/init.d/httpd graceful or apachectl graceful brought the system down.

we find the parent process to all other httpd processes, the one with ‘1’ as the parent process, and strace it to watch activity using ps,

ps -aef | grep httpd

Go to screen & run,

strace -aef -p 8021 2>&1 | tee /tmp/strace.out

issue the command apachectl graceful

-Watch the file strace.out,
We see access for ioncube_loader_lin_5.3.so, which succeeds with a file handle (20), and access for an ffmpeg.so module, which fails with ENOENT (-1). The process then logs to the error log, and a segfault occurs.

Commenting out the ffmpeg.so line (insert a semicolon at the beginning of the line) and re-running the test gave another seg fault, but this time on rar.so. So, out that goes too, comment that out and start httpd and gracefully restart it and… no error! The server stays up, strace output continues and operation is uninterrupted.