Log rotatation in
some compressed files some files which ends with
The location of log rotation configs is in
Explanation of some parameters:
- weekly: weekly says that you want to
- rotate 4: it says that how many rotated files should be kept, here I keep 4 rotated files (one month).
- compress: well you tell me what this parameter does.
- delaycompress: some programs do not close file handlers immediately, here we tell log rotate to delay the compression.
- missingok: don't return error if the log file is missing
OK, the list goes on. Take a look at the manual yourself and see its options.
#linux #logrotate #rotate
Linux
is so handy as its name implies, it rotates log files. If you have a look at the /var/log
path you can seesome compressed files some files which ends with
.1
/var/log/my-app.log {
weekly
rotate 4
compress
delaycompress
missingok
notifempty
create 644 root root
}
The location of log rotation configs is in
/etc/logrotate.d/
. I have created a file in it with the config above.Explanation of some parameters:
- weekly: weekly says that you want to
Linux
to rotate your log files weekly, you can also set daily, monthly, yearly.- rotate 4: it says that how many rotated files should be kept, here I keep 4 rotated files (one month).
- compress: well you tell me what this parameter does.
- delaycompress: some programs do not close file handlers immediately, here we tell log rotate to delay the compression.
- missingok: don't return error if the log file is missing
OK, the list goes on. Take a look at the manual yourself and see its options.
#linux #logrotate #rotate
I have a script that checks a source folder for new files in case there are files in the source folder, it will move those files to destination.
The problem I encountered recently was that files are huge and it may be in the middle of the copying into source by another process so my script tries to move an incomplete file to a destination. Let's say the file is 4GB in size and just only 1GB of the file has been copied. I have to wait until file is 4GB and other handler using that file, then I should safely move the file.
You can use
#linux #sysadmin #lsof #grep
The problem I encountered recently was that files are huge and it may be in the middle of the copying into source by another process so my script tries to move an incomplete file to a destination. Let's say the file is 4GB in size and just only 1GB of the file has been copied. I have to wait until file is 4GB and other handler using that file, then I should safely move the file.
You can use
lsof
command in order to check which processes are using the source file:if [[ `lsof -- /var/my-folder/my-big-file.tar.gz` ]]
then
echo "File is being used by a process."
exit 1
fi
NOTE:
you can give file directly to lsof
using --
or you can use grep command as follow:lsof | grep /var/my-folder/my-big-file.tar.gz
NOTE2:
if you are in a loop use break
instead of exit
.NOTE3:
if you get command not found
, install it using apt-get install lsof
#linux #sysadmin #lsof #grep
How to limit bandwidth of
far better in terms of features and incremental copy mechanism. To limit bandwidth use
The general form:
An example of usage with 2MB limit per second transfer:
#linux #sysadmin #rsync #bandwidth
rsync
linux command?rsync
is an awesome tool in order to move files via ssh
into another server or from server to local system like what scp does butfar better in terms of features and incremental copy mechanism. To limit bandwidth use
bwlimit
like below:The general form:
rsync --bwlimit=<kb/second> <source> <dest>
An example of usage with 2MB limit per second transfer:
rsync --bwlimit=2000 /backup/folder user@example-host:/remote/backup/folder/
#linux #sysadmin #rsync #bandwidth
Does that happen for you too, to
Let's say you are in a long path like
#linux #cd
CD
into a wrong directory and need to get back to the previous directory?Let's say you are in a long path like
/mnt/new_volume/backup/files/archive
, now you switch to home of your directory. In order to get back to the previous directory, you just need to issue the below command:cd -
#linux #cd
If you forget to pull your projects from git in a regular interval and many users working on the same projects, then there is a solution for you!
Create a bash script file as follow and make it executable by
Now as a final step, put it in your crontab:
#linux #git #pull #cronjob #crontab #cron #bash
Create a bash script file as follow and make it executable by
chmod +x puller.sh
:puller.sh
file content:#!/bin/bash
echo 'Iterating over folders...'
for dir in *
do
test -d "$dir" && {
cd ${dir}
echo "git pull $dir"
git pull
cd ".."
} || {
echo "------> $dir is not a directory <-------"
}
done
NOTE:
this file should reside in your folder's project root. In my case it is in /Your/Projects/Folder
.Now as a final step, put it in your crontab:
10 * * * * bash -c "cd /Your/Projects/Folder; bash puller.sh >> /var/log/git_pull_output.log"
#linux #git #pull #cronjob #crontab #cron #bash
We have talked before about how to get current month using the below line of code:
It prints out 01, 02, etc.
As per the
So you can remove leading zero by hyphen as below:
It prints out 1, 2, etc.
#linux #bash #date
echo $(date +%m)
It prints out 01, 02, etc.
As per the
GNU date manpage
:By default, date pads numeric fields with zeroes. The following
optional flags may follow '%':
- (hyphen) do not pad the field
So you can remove leading zero by hyphen as below:
echo $(date +%-m)
It prints out 1, 2, etc.
#linux #bash #date
https://xiaoxiaoke.wordpress.com/2015/10/06/changing-java-security-restriction-for-network-connect-error-issue-in-kvm/
#linux #devops #sysadmin #kvm #hp
#linux #devops #sysadmin #kvm #hp
Ke Xu | Geek World
Changing java security restriction for “Network connect error” issue in KVM
I am using KVM to manage the servers in a rack. When launching the session jnlp files with javaws, I saw the “Network connect error” message. This is due to the default java security re…
How to SSH login without password?
You want to use Linux and OpenSSH to automate your tasks. Therefore you need an automatic login from host A / user a to Host B / user b. You don't want to enter any passwords, because you want to call ssh from a within a shell script.
First log in on A as user a and generate a pair of authentication keys. Do not enter a passphrase:
Now use ssh to create a directory
Finally append a's new public key to
From now on you can log into B as b from A as a without password:
#linux #sysadmin #ssh #password_less #ssh_login
You want to use Linux and OpenSSH to automate your tasks. Therefore you need an automatic login from host A / user a to Host B / user b. You don't want to enter any passwords, because you want to call ssh from a within a shell script.
How to do it?
First log in on A as user a and generate a pair of authentication keys. Do not enter a passphrase:
a@A:~> ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/a/.ssh/id_rsa):
Created directory '/home/a/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/a/.ssh/id_rsa.
Your public key has been saved in /home/a/.ssh/id_rsa.pub.
The key fingerprint is:
3e:4f:05:79:3a:9f:96:7c:3b:ad:e9:58:37:bc:37:e4 a@A
Now use ssh to create a directory
~/.ssh
as user b on B. (The directory may already exist, which is fine):a@A:~> ssh b@B mkdir -p .ssh
b@B's password:
Finally append a's new public key to
b@B:.ssh/authorized_keys
and enter b's password one last time:a@A:~> cat .ssh/id_rsa.pub | ssh b@B 'cat >> .ssh/authorized_keys'
b@B's password:
From now on you can log into B as b from A as a without password:
a@A:~> ssh b@B
#linux #sysadmin #ssh #password_less #ssh_login
Virt-builder
is a tool for quickly building new virtual machines. You can build a variety of VMs for local or cloud use, usually within a few minutes or less. Virt-builder
also has many ways to customize these VMs. Everything is run from the command line and nothing requires root privileges, so automation and scripting is simple.To see available virtual machines:
virt-builder --list
Sample command to create a
debian-9
image:sudo virt-builder debian-9 --size=50G --hostname prod.example.com --network --install network-manager --root-password password:YOUR_PASS
The above command creates a debian 9 image with disk size of 50GB and sets the hostname to
prod.example.com
. --network
enables the networking on guest and --install
installs packages on the target OS. The last parameter sets the root password to
YOUR_PASS
.To read more about the axtra parameters:
- http://libguestfs.org/virt-builder.1.html
#linux #sysadmin #virt_builder #debian #image
You can login to a server without entering a password by a simple command as below:
By issuing the above command it puts your public key content on server
#linux #sysadmin #ssh #passwordless_login #ssh_copy_id #authorized_keys #public_key
ssh-copy-id USERNAME@YOUR_HOST_IP -p 22
By issuing the above command it puts your public key content on server
~/.ssh/authorized_keys
and prompts you to enter the password. You are all done by this.#linux #sysadmin #ssh #passwordless_login #ssh_copy_id #authorized_keys #public_key
How I store & manage passwords in Linux for servers and other credentials? gopass
Password management should be simple and follow Unix philosophy. With
- https://github.com/gopasspw/gopass
#unix #linux #sysadmin #pass #gopass #password_management #golang #github
Password management should be simple and follow Unix philosophy. With
pass
, each secret lives inside of a gpg
encrypted file whose filename is the title of the website or resource that requires the secret. These encrypted files may be organized into meaningful folder hierarchies, copied from computer to computer, and, in general, manipulated using standard command line file management utilities. gopass
is a rewrite of the pass
password manager in Go
with the aim of making it cross-platform and adding additional features. Our target audience are professional developers and sysadmins
(and especially teams of those) who are well versed with a command line interface. One explicit goal for this project is to make it more approachable to non-technical users. We go by the UNIX philosophy and try to do one thing and do it well, providing a stellar user experience and a sane, simple interface:- https://github.com/gopasspw/gopass
#unix #linux #sysadmin #pass #gopass #password_management #golang #github
GitHub
GitHub - gopasspw/gopass: The slightly more awesome standard unix password manager for teams
The slightly more awesome standard unix password manager for teams - gopasspw/gopass
https://superuser.com/questions/453988/whats-the-difference-between-su-with-and-without-hyphen
#linux #su
#linux #su
Super User
What's the difference between "su" with and without hyphen?
I'm quite new to Linux terminal and I'm not quite sure what the difference between su with a hyphen and su without a hyphen is, for example: su - username vs. su username.
I looked into the documen...
I looked into the documen...
https://stackoverflow.com/questions/13032409/ssh-remote-variable-assignment
#linux #sysadmin #ssh #local_variable #variable_expansion #bashrc #export
#linux #sysadmin #ssh #local_variable #variable_expansion #bashrc #export
Stack Overflow
ssh remote variable assignment?
The following does not work for me:
ssh user@remote.server "k=5; echo $k;"
it just returns an empty line.
How can I assign a variable on a remote session (ssh)?
Note: My question is not about ...
ssh user@remote.server "k=5; echo $k;"
it just returns an empty line.
How can I assign a variable on a remote session (ssh)?
Note: My question is not about ...
In order to enable bash completion in Kubernetes you can usee the below command in linux bash:
Now to test this enter the below command and you should see the completion:
It should be expanded to
#linux #bash #shell #kubernetes #kubectl
source <(kubectl completion bash)
Now to test this enter the below command and you should see the completion:
kubectl cl<TAB>
It should be expanded to
kubectl cluster-info
.#linux #bash #shell #kubernetes #kubectl