Skip to content

Instantly share code, notes, and snippets.

@simbalinux
simbalinux / grep_replace
Last active July 13, 2018 00:00
find and replace all occurences of " ." IF gt 3 and replace with "+"
[ $(grep -o '\.' file|wc -l) -gt 3 ] && sed -i file -e 's/\./+/g'
@simbalinux
simbalinux / scp_xfers
Created July 13, 2018 00:07
Shell Program to manage scp xfers
#!/bin/bash
#GLOBAL VARS
set -x
DATE=`date +%Y-%m-%d.%H:%M:%S`
RECIPIENTS="user@domain.com"
STAGING=/nas/tbdata/.encrypted_file
EXTRACT=/nas/tbdata2
ARCHIVE=/nas/tbdata/.encrypted_file/md5
MD5="user@obfuscated.domain.com:/erp.tar.gpg.md5"
DATA="user@obfuscated.domain.com:/erp.tar.gpg"
@simbalinux
simbalinux / ssh_agent
Created February 22, 2018 20:27
ssh agent
#!/bin/bash
#Invoke this once, run again after a restart of the system.
set -x
SSH_ENV=$HOME/.ssh/environment
function start_agent {
echo "Initialising new SSH agent..."
/usr/bin/ssh-agent | sed 's/^echo/#echo/' > ${SSH_ENV}
echo succeeded
chmod 600 ${SSH_ENV}
. ${SSH_ENV} > /dev/null
@simbalinux
simbalinux / restart_check
Last active July 13, 2018 00:11
restart_check
#!/bin/bash
#this is a coment for the code
set -x
sleep 60
IP=$(hostname -i)
HOSTNAME=$(hostname -f)
echo "$HOSTNAME online. IP address: $IP" > ./email.txt
date >> ./email.txt
@simbalinux
simbalinux / ssh_agent
Last active July 13, 2018 00:11
ssh_agent
#!/bin/bash
#Invoke this once, run again after a restart of the system.
set -x
SSH_ENV=$HOME/.ssh/environment
function start_agent {
echo "Initialising new SSH agent..."
/usr/bin/ssh-agent | sed 's/^echo/#echo/' > ${SSH_ENV}
echo succeeded
chmod 600 ${SSH_ENV}
. ${SSH_ENV} > /dev/null
@simbalinux
simbalinux / backup_script
Created July 13, 2018 00:14
backup_script
#!/bin/bash
#set -x
shopt -s nullglob
data=(/nas/csi/*)
key="$HOME"/.ssh/csi
url=user@secureftp.com:/Drop
archive=/nas/data/.data_archive
now=$(date +"%Y%m%d-%T")
sftp_copy () {
@simbalinux
simbalinux / iphost
Created January 25, 2018 15:37
ip-hostname
#!/bin/bash
set -x
#ip vars
ip=$(hostname -I | cut -f2 -d' ')
#use this when in private newtwork to avoid network issues.
ip2="0.0.0.0"
this_host=$(hostname -f)
@simbalinux
simbalinux / 5lineslog.php
Created February 22, 2018 18:50
PHP last 5 lines of log file
<?php
$file = file("../log/simplelogger.log");
for ($i = max(0, count($file)-5); $i < count($file); $i++) {
var_dump($line);
echo $file[$i] . "\n";
}
@simbalinux
simbalinux / searchstring.php
Created February 22, 2018 18:53
search for host in string PHP
<?php
//simulating the array from string:
$s = '
[2018-02-19 14:08:32] [info] status=GOOD&unit_status=GOOD&hostname=acme
[2018-02-19 14:08:32] [alert] Wrong status! (Not "DEGRADED")
[2018-02-19 14:08:37] [info] Request with params {"status":"GOOD","unit_status":"GOOD","hostname":"joe"}
[2018-02-19 14:08:37] [info] status=GOOD&unit_status=GOOD&hostname=joe
[2018-02-19 14:08:37] [alert] Wrong status! (Not "DEGRADED")
';
@simbalinux
simbalinux / searchstring2.php
Created February 22, 2018 18:55
search for host in string 2 PHP
<?php
//simulating the array from string:
$s = '
[2018-02-19 14:08:32] [info] status=GOOD&unit_status=GOOD&hostname=acme
[2018-02-19 14:08:32] [alert] Wrong status! (Not "DEGRADED")
[2018-02-19 14:08:37] [info] Request with params {"status":"GOOD","unit_status":"GOOD","hostname":"joe"}
[2018-02-19 14:08:37] [info] status=GOOD&unit_status=GOOD&hostname=joe
[2018-02-19 14:08:37] [alert] Wrong status! (Not "DEGRADED")
';