Friday, June 23, 2017

Generate Load on Linux server for testing

Generate Load on Linux server for testing (Here 1..8 means 8 core cpu which can be updated as per your requirement)

for i in {1..8}; do while : ; do : ; done & done



You can also type the same with below format (Numbers depends on CPU core)
for i in 1 2 3 4 ; do while : ; do : ; done & done


Kill the above process with below command

for i in {1..8}; do kill %$i; done

ERROR 1819 (HY000): Your password does not satisfy the current policy requirements - Solved

If you are getting below error with mysql 5.7.18 while updating password & can't restart your mysql-server
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

Solution -

Check validate password values with below command 

SHOW VARIABLES LIKE 'validate_password%';

Just set your Validate Password policy to LOW with below command


SET GLOBAL validate_password_policy=LOW; 

Now you can update the password. By default the value is MEDIUM & you can set the same to default once your work is complete


 If you want it permanently, You can simply disable the same with below setting in /etc/my.cnf
validate-password = off

Note- You need to restart mysql server to reflect any changes with my.cnf file

Thursday, April 20, 2017

Track commands of All users in Linux

Log commands executed by all the users in Linux

Add below line in /etc/rsyslog.conf file

local2.info /var/log/commands-track-user

restart rsyslog service

Add below entry in /etc/bashrc

readonly PROMPT_COMMAND='history -a >(logger -p local2.info -t "$USER[$PWD] $SSH_CONNECTION")'

Execute the command 'source /etc/bashrc' or logout and login back to your session.

Now the commands executed by all the users will be logged in /var/log/commands-track-user

Wednesday, March 15, 2017

Record Terminal Session in Linux and Replay

We can record and reply a terminal session with script command and reply it with scriptreply command.

Here is the example to record the session:

$ script -t 2> time.txt -a session1.txt
Output:

Script started, file is session.txt

Now you can start typing some commands.
$ date
$ echo "Hi Linux"
$ time
$ ifconfig
$ ls
To stop recording run exit command.

$ exit
In above session we ran date,echo,time,ifconfig,ls commands, and stored output in time.txt and session1.txt

To replay recorded session use scriptreplay as shown below:

$ scriptreplay time.txt session1.txt
It will replay whole session that we recorded by you.

Wednesday, February 15, 2017

Check CPU Details of any Linux server

Check CPU Details of 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

Tuesday, February 7, 2017

Stop and Continue a Linux Process


Suppose you need to stop any process on Linux server due to high load or low Memory issue on server. Then execute below command

kill -STOP 10007 (10007 is the pid)

Once the load became normal simply continue the process with below command

kill -CONT 10007 (10007 is the pid)

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