Crontab every seconds

Welcome again!

Today I will post a quick tip, something useful with a “clever” solution. Crontab every X seconds, let’s see the script.

Your script
Just modify the run function of what you want to do it every $SECLAUNCH seconds. This will be lauched once, even if the run functions needs more than $SECLAUNCH seconds. If it take less than, the function run will be launched at $SECLAUNCH – timeelapsed.

#!/bin/bash
# USING runScriptEverySeconds.sh
# Load defaults config
. /scripts/config # Loading defaults configurations
 
##########################
# Seconds between launch #
##########################
SECLAUNCH=5
     
###################
# FUNCTION TO RUN #
###################
     
function run {
   runYourScriptEvery5seconds.sh
}
     
. /scripts/runScriptEverySecond.sh #Script who make it possible running every seconds

Here is the script you have to set as /scripts/runScriptEverySecond.sh

#!/bin/bash

########### SCRIPT RUN COMMAND EVERY $SECLAUNCH SECONDS #################
#									#
# This scripts will launch function run() every SECLAUNCH seconds. 	#
# If the scripts need more than SECLAUNCH will be launched as soon 	#
# as the last ends.							#
#									#
# 			-- IMPORTANT --					#
#									#
# User needs to add .defaultScripts/runScriptEverySeconds.sh at the 	#
# end and define SECLAUNCH and run funcion.				#
#									#
#########################################################################

##########################
# Seconds between launch #
##########################
# SECLAUNCH=5

#######################
# FUNCTION TO DEFINE  #
#######################

# function run {
# 	date
# 	sleep $(($RANDOM%5+1))
# }



###############################################
#		DO NOT EDIT		      #
###############################################

DATE=`date +%s`

# Launch command

for (( ; ; ))
do
	NOW=`date +%s`
	RES=$(($NOW - $DATE))
	#echo $RES $SECLAUNCH
	if [ $RES -ge $SECLAUNCH ]
	then
		#echo "INSIDE"
		DATE=`date +%s`
		run
	else
		sleep 1
	fi
done

If you have questions, don’t worry! ask me here or at twitter @becloudin

Stay cloud!

Generate SSH keys

Hi cloud!

Today I explain how to generate public/private keys. This is very useful for a lot of services that require something more secure than a typed password. The most common usage for private Key is the ssh connection. If we use private key we will never need to type password again, saving hundreds of hours and more than one security problem.

How we can create our new key?

 $ ssh-keygen 

Generating public/private rsa key pair.
Enter file in which to save the key (/home/ubuntu/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/ubuntu/.ssh/id_rsa.
Your public key has been saved in /home/ubuntu/.ssh/id_rsa.pub.
The key fingerprint is:
a1:04:aa:73:5a:8f:24:14:70:24:ca:30:37:ca:92:c1 ubuntu@ip-10-22-22-22
The key's randomart image is:
+--[ RSA 2048]----+
|Oo= .            |
|=E.o .           |
|=+.   . .        |
|o.   . . .       |
|+ +   . S        |
| B o             |
|. . .            |
|                 |
|                 |
+-----------------+

That’s it! We will have our key generated. We can find them at ~/.ssh/id_rsa.pub (Public key) and ~/.ssh/id_rsa (Private key). The private key is the file you NEVER provide to anyone. And remember to get correct permisions (600). If not, you will be noticed of incorrect permissions.

To change that permissions:

 $ chmod 600 ~/.ssh/id_rsa 

In next posts we will explain new techniques to save even more time in your normal commands.

But this will be in a few days!

Stay cloud!

Shell – How to Bookmark your commands ( ctrl + r )

Hi!

This is my first real post related with something useful. I hope this blog will be provably not a reference, but somewhere to find interesting things, more o less a “tips & tricks” of hundreds of different themes.

I will explain something useful, a few tips that save me hundreds of hours.

Search into your bash history file with command line.

 

$ ssh devel@yourserver.com #develop
$ (reverse-i-search)`dev': ssh devel@myserver.com #develop

 

What you have to do is to add #bookmark word. Every time you want to launch this command you just need to press ctrl + r and start typing the keyword. The shell will try to find in bash history any command containing this words. So once you start writing dev you will get the command containing dev word, in this case the ssh command to connect to your server.

Ctrl + r

If you have for example #develop and #develop2 you just need to press 2 times ctrl + r and you will get the occurrences of this words.

I promise if you try to use this frequently  you will save hundreds of hours typing the same command once, twice, …

 

Stay tuned!

Uso de cookies

Este sitio web utiliza cookies para que usted tenga la mejor experiencia de usuario. Si continúa navegando está dando su consentimiento para la aceptación de las mencionadas cookies y la aceptación de nuestra política de cookies, pinche el enlace para mayor información.plugin cookies