Thanks to antville.org
managing crons

We can use logger command in a crontab.

59 23 * /home/john/bin/backup.sh > /home/john/logs/backup.log | logger -t backup 2>&1

It is also possible to skip the standard error and let mailto send you the errors:

MAILTO=me@domain.com

... Link (0 comments) ... Comment


Saving files in VI

You can save the current file as a new file after making changes,
:w new_file.txt

If you want only 50 lines starting from line number 100, use...
:100,150w! new_file.txt

... Link (0 comments) ... Comment


IP addresses from access log

generate a list of IP address along with the number of times each was encountered and sort

cat access_log | awk '{print $1}' | sort | uniq -c | sort -nr

... Link (0 comments) ... Comment


Backup a directory

!/bin/sh

tar czvf $1.$(date +%Y%m%d-%H%M%S).tgz $1
exit $?

The arc script accepts a single file or directory name as a parameter and creates a compressed archive file with the current date embedded into the resulting archive file's name.

... Link (0 comments) ... Comment


read .csv file

!/bin/sh

awk -F"," '{print $1,$2}' read1.txt | while read var1 var2
do
echo $var1 $var2
done

... Link (0 comments) ... Comment


findtable shell script

vi /bin/findtable

!bin/sh

mysql -e"select TABLE_SCHEMA, TABLE_NAME, ENGINE, TABLE_ROWS, CREATE_TIME FROM information_schema.TABLES where TABLE_NAME LIKE '%$1%';"

chmod 777 /bin/findtable

sh findtable test

... Link (0 comments) ... Comment


Unix cheatsheets

Cheat sheet act as a reference tool which provides cut and paste kind of commands to complete a specific task. I often recommend following set of best cheat sheets to students and IT professionals. It include Linux / UNIX command and shell scripting.

Read more: Top 10 Best Cheat Sheets and Tutorials for Linux / UNIX Commands

... Link (0 comments) ... Comment


compress and send

scp is the standard command to copy a folder or files. You can also compress the files before sending it as shown below. In this test I am using a folder with 4 files of 3.5 MB size. The time is reduced to 5 seconds from 40 seconds.

time scp /root/shantanu/* root@172.29.0.131:/root/

root@172.29.0.131's password:
iostat0111.log 100% 46KB 46.3KB/s 00:00
mystats.txt 100% 201KB 201.5KB/s 00:00
top0111.log 100% 3219KB 100.6KB/s 00:32
vmstat0111.log 100% 21KB 20.7KB/s 00:00

real 0m39.844s
user 0m0.053s
sys 0m0.021s

time tar zcf - shantanu | ssh 172.29.0.131 "cd /root/shantanu/; tar zpxvf -"

root@172.29.0.131's password:
shantanu/
shantanu/top0111.log
shantanu/mystats.txt
shantanu/vmstat0111.log
shantanu/iostat0111.log

real 0m5.326s
user 0m0.068s
sys 0m0.015s

If you type the full path to the folder /root/shantanu/ then a new folder in the destination folder will be created with the same path.

... Link (0 comments) ... Comment


Online for 6050 days
Last modified: 3/17/19 3:22 PM
Status
Youre not logged in ... Login
Menu
... Home
... Tags

Search
Calendar
March 2019
SunMonTueWedThuFriSat
12
3456789
10111213141516
17181920212223
24252627282930
31
January
Recent updates
python itertools module from itertools
import groupby s = 'abcccccbba' for w, v in groupby(s):...
by shantanuo (3/17/19 3:22 PM)
audio visual modules for Machine
Learning Here is the list of some of the modules...
by shantanuo (3/16/19 1:08 PM)
google module module for google
search !pip install google from googlesearch import search for url...
by shantanuo (1/8/19 10:38 AM)
Python date and time from
datetime import datetime date_string = "21 June, 2018" date_object =...
by shantanuo (12/26/18 12:14 PM)
Infer types in pandas This
will return the mixed datatypes but this can be slow....
by shantanuo (12/16/18 3:50 PM)
Extract words from Marathi wikipedia
1) Download the polyglot pickled marathi model wget http://bit.ly/12FI1xV mv...
by shantanuo (11/4/18 10:06 AM)
Google Input tools Google suddenly
stopped download of Input Tools package without giving any reason....
by shantanuo (9/10/18 7:44 AM)
Python objects and methods Here
are important python objects and their methods int __mul__, __add__,...
by shantanuo (8/18/18 3:11 PM)
JSON to DF Here is
how to read a JSON file into pandas dataframe. import...
by shantanuo (8/8/18 1:12 PM)
managing servers using python Fabric
is a high level Python library designed to execute shell...
by shantanuo (8/4/18 10:01 AM)
backup mysql users It is
easy to backup mysql users - wget percona.com/get/pt-show-grants; perl pt-show-grants
by shantanuo (5/20/18 3:42 PM)
About python 1 everything is
an object (class instances) 2 methods depends upon class of...
by shantanuo (5/20/18 2:52 PM)
mysql and shell command date
-d"-1 day ago" +'%b%d' equals to mysql -Bse"select date_format(date(date_add(now() ,...
by shantanuo (5/16/18 7:47 AM)
Preserving comments in Stored Procedure
You can write multi line comments in a stored procedure...
by shantanuo (5/12/18 12:56 PM)
Custom slack command Here are
5 steps to add any API to your slack channel....
by shantanuo (4/25/18 6:59 AM)
stack bookmarklet This bookmarklet will
help to quickly access stack pages linking to current page...
by shantanuo (1/10/18 10:47 AM)
Manage S3 like rsync ####
create bucket aws s3 mb s3://johntest123/ #### rsync all files...
by shantanuo (12/22/17 12:04 PM)
apache docker container issues If
apache docker container does not start then make these changes......
by shantanuo (11/10/17 3:00 PM)
Install aws client on centos
If pip is not installed, then the following command will...
by shantanuo (10/26/17 9:51 AM)
Managing Amazon keys Use this
command to convert private key to public key. ssh-keygen -y...
by shantanuo (10/9/17 7:04 AM)
percona utility We can re-create
mysql users using the percona utility. wget percona.com/get/pt-show-grants chmod 777...
by shantanuo (9/6/17 8:22 AM)
mail merge separate file per
record Microsoft Word has an excellent feature called Mail-Merge. If...
by shantanuo (7/6/17 12:09 PM)
find dead processes The 8th
column of ps aux command will list the status of...
by shantanuo (5/28/17 7:39 AM)
Amazon Web Services Here are
some of the important Amazon products to use. cloudTrail...
by shantanuo (5/10/17 11:35 AM)
Self signed security certificate http://www.thegeekstuff.com/2009/07/linux-apache-mod-ssl-generate-key-csr-crt-file/
openssl genrsa -out 34.195.94.88.key 1024 openssl req -new -key 34.195.94.88.key...
by shantanuo (1/16/17 8:02 AM)

RSS feed

Made with Antville
Helma Object Publisher