Skip to content

Instantly share code, notes, and snippets.

View 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
View 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
View iphost
#!/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 Feb 22, 2018
PHP last 5 lines of log file
View 5lineslog.php
<?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 Feb 22, 2018
search for host in string PHP
View searchstring.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 Feb 22, 2018
search for host in string 2 PHP
View searchstring2.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 / loadnewarray.php
Created Feb 22, 2018
push last x lines of open file to new array
View loadnewarray.php
<?php
$lines=array();
$fp = fopen("../log/simplelogger.log", "r");
//tail off last x lines of the log file
while(!feof($fp))
{
$line = fgets($fp);
array_push($lines, $line);
if (count($lines)>10)
@simbalinux
simbalinux / selinux disable
Created Feb 22, 2018
disabling selinux before and after reboot
View selinux disable
#disable selinux on next reboot
sed -i 's/enforcing/disabled/g' /etc/selinux/config /etc/selinux/config
sestatus
#put in permissive mode
setenforce 0
View 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
View strap_lamp7_ssl
#!/usr/bin/bash
set -x
# check hostname
hostname -f
# update and install Apache
yum -y update
yum -y install vim httpd
systemctl restart httpd
# backup of the httpd.conf file