Wednesday, February 15, 2017

Check CPU Details of any any Linux server

Check CPU Details of any any Linux server


 Use below command to check the CPU details of any linux server

show all cores (virtual)
grep -c processor /proc/cpuinfo
64

show physical cpu
grep 'physical id' /proc/cpuinfo | sort -u | wc -l
4

show physical core per cpu
grep 'cpu cores' /proc/cpuinfo | tail -1
cpu cores    : 8



so the final result is 
physical cpu: 4
physical core per physical cpu: 8
whole physical core: 32
whole virtual core: 64

Monday, February 6, 2017

Ping any domain with Real time (Timestamp)

I needed a command which can ping any server & show timestamp as well

ping google.com | awk '/^[0-9]+ bytes from / { "date" | getline pong; close("date"); print pong":",$0; }'

If you’re interested in all types of replies (unreachable, no route to host, etc), the following should work on most systems;

ping google.com | while read pong; do echo "$(date): $pong"; done


Tuesday, January 31, 2017

How to Upload Files on Google Drive from Linux Console

Follow below steps to use google drive from linux termial

Download google drive version for linux
wget https://docs.google.com/uc?id=0B3X9GlR6EmbnWksyTEtCM0VfaFE&export=download

yum install wget
wget https://docs.google.com/uc?id=0B3X9GlR6EmbnWksyTEtCM0VfaFE&export=download

You will see a file like above. Rename it with gdrive
mv uc\?id\=0B3X9GlR6EmbnWksyTEtCM0VfaFE gdrive

chmod +x gdrive

install gdrive /usr/local/bin/gdrive

Run below command to check

[root@bhagwat home]# gdrive list
Authentication needed
Go to the following url in your browser:
https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id=367116221053-7n0vf5akejinrecpdoe99eg.apps.googleusercontent.com&redirect_uri=urn%3Aiet%3Awg%3oau%3A2.0%3Asponse_type=code&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive&state=state

Enter verification code:

Just copy the above url & paster in your browser. Copy verification code here & you are done. Now you can use your google drive directly from terminal.

Upload any file with below command
[root@bhagwat home]# gdrive upload my_photos.zip

Use gdrive help command for more options
[root@bhagwat home]# gdrive help

Wednesday, January 25, 2017

Find files with specific extensions in current directory

Find files with specific extensions in current directory (you can add multiple extensions as per syntax

find . -type f \( -name "*.sh" -o -name "*.txt" \)
find /home/bhsingh/ -type f \( -name "*.png" -o -name "*.jpg" -o -name "*.deb" -o -name ".pdf" \)

Find file & redirec the result to a file

find /home/www/html -type f \( -name "*.php"\) -print0 | xargs -0 stat --format '%Z :%z %n' | sort -nr > /home/bhsingh/php_files.txt
find / -type f -print0 | xargs -0 stat --format '%Z :%z %n' | sort -nr > /root/all_files.txt

Tuesday, January 24, 2017

Not able to install googleads-php-lib on Centos

[bhagwat@server1 googleads-php-lib-25.1.0]$ php composer.phar require googleads/googleads-php-lib

Using version ^25.1 for googleads/googleads-php-lib
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

Problem 1
- The requested package googleads/googleads-php-lib No version set (parsed as 1.0.0) is satisfiable by googleads/googleads-php-lib[No version set (parsed as 1.0.0)] but these conflict with your requirements or minimum-stability.


Solution

Issue was resolved after upgrading composer with below command

php composer.phar update

(Composer seems not to be able to detect the version of the library and thus cannot install the library of v25.1 as requested.)

Test hard disk performace on Linux Server


Performance testing was done on /dev/sda drive with cache enable & disable mode of hard drive

cache enable/disable syntax is below
hdparm -W(value) /dec/sda

Value 0 means cache disable
Value 1 means cache enable

One gigabyte was written for the test, first with the cache activated (hdparm -W1 /dev/sda):

root@bhagwat~# dd if=/dev/zero of=/root/testfile bs=1G count=1 oflag=direct
1+0 records in
1+0 records out
1073741824 bytes (1.1 GB) copied, 32.474 s, 33.1 MB/s
root@bhagwat~#


Then, with the cache deactivated (hdparm -W0 /dev/sda):

root@bhagwat~# dd if=/dev/zero of=/root/testfile bs=1G count=1 oflag=direct   
1+0 records in
1+0 records out
1073741824 bytes (1.1 GB) copied, 123.37 s, 8.7 MB/s

Friday, January 20, 2017

Cron need to run on every Monday of the Month


Need to add a cron entry which should execute on every Monday of month.
Or
You can use it for any other day (changing "Mon" with other days")


00 04 1-7 * * [ "$(date '+\%a')" == "Mon" ] && perl /home/bhagwat/cron/my_script.pl
00 04 8-15 * * [ "$(date '+\%a')" == "Mon" ] && perl /home/bhagwat/cron/my_script.pl
00 04 24-31 * * [ "$(date '+\%a')" == "Mon" ] && perl /home/bhagwat/cron/my_script.pl