Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Thursday, May 28, 2020

Wednesday, March 18, 2020

Linux: sum numbers

Source: Shell command to sum integers, one per line?
$ grep ussd\. MBQTUSG_20200302_001.csv | head -5
ussd.mt,8,02/03/2020 00:00:00,02/03/2020 23:59:59,88060
ussd.mo,576,02/03/2020 00:00:00,02/03/2020 23:59:59,172099
ussd.mt,576,02/03/2020 00:00:00,02/03/2020 23:59:59,172099
ussd.mo,1,02/03/2020 00:00:00,02/03/2020 23:59:59,254078
ussd.mt,34,02/03/2020 00:00:00,02/03/2020 23:59:59,254078

$ grep ussd\.m MBQTUSG_20200302_001.csv | cut -d, -f2 | perl -lpe '$c+=$_}{$_=$c'
243648

Wednesday, April 11, 2018

Linux: Find Out What Process Are Using Swap Space

Source : Linux: Find Out What Process Are Using Swap Space
for file in /proc/*/status ; do awk '/VmSwap|Name/{printf $2 " " $3}END{ print ""}' $file; done | sort -k 2 -n -r | less

Friday, November 3, 2017

Linux: Alert when running process finishes

Source: Alert when running process finishes
(while kill -0 $pid; do sleep 1; done) && echo "finished"

Wednesday, October 11, 2017

Delete files older than file

Source: Delete files older than specific file
find __dir__ -type f ! -newer __file__ -delete

Monday, March 20, 2017

Linux: top ten biggest files

du -a /var | sort -n -r | head -n 10

Wednesday, February 1, 2017

Wednesday, June 1, 2016

grep extract

Suppose you want 150 lines after the line containing "2016-05-31 11:06:39.265" from file postgresql-31.csv:
grep -A150 '2016-05-31 11:06:39.265' postgresql-31.csv > /tmp/postgresql-31.csv.extract

Friday, April 1, 2016

Wednesday, February 17, 2016

Remove  from the beginning of a file

This is the BOM.
vi my_file
set nobomb
wq

Monday, May 18, 2015

Friday, March 20, 2015

Linux: remove files older than x days

E.g. Remove files older than 90 days
find . -mtime +90 -exec rm {} \;

Thursday, March 12, 2015

SSH with keep alive option

ssh -o "ServerAliveInterval 600" yapit

Disable Strict SSH Checking on Source Peer

By appending the following to your ~/.ssh/config file you can disable SSH prompts which ask to add new hosts to the “known hosts file.” Note that the ${DESTPEERHOST} should be the name of the host machine running the destination peer:

Host ${DESTPEERHOST}
CheckHostIP no
StrictHostKeyChecking no
BatchMode yes

SSH to tondu as omnitest without password

  • As gallinar, in .ssh/config, comment “Batchmode yes” so as to temporarily get a password question when sshing:
 #BatchMode yes
  • As gallinar, in .ssh/config, add the following lines in order to log to tondu as omnitest:
 Host tndu
 HostName tondu
 User omnitest
  • As gallinar, if not already done, generate a public key:
 ssh-keygen -t rsa
  • As gallinar, copy the public key to the target:
 scp ~/.ssh/id_rsa.pub tondu:/tmp
  • As omnitest, on tondu:
 cat /tmp/id_rsa.pub >> ~/.ssh/authorized_keys
  • As gallinar, in .ssh/config, uncomment “Batchmode yes”, and remove /tmp/id_rsa.pub on tondu.

Configured ssh on host for no password but still asked

Check $HOME/.ssh and $HOME rights. If writeable for group or world, a password will be asked.
> chmod 700 $HOME/.ssh 
> chmod 600 $HOME/.ssh/authorized_keys

Friday, November 21, 2014

Friday, September 19, 2014

Bash: delete last n lines of a file

head -n -100000 FILE > NEWFILE