Installing node on old version of Ubuntu 10.04

 curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh | bash

logoff and log on

nvm ls-remote
nvm install v7.9.0
npm -v
node -v

Caveat : Β  Lots of node stuff fails to compile and run on such an oldΒ version of linux be warned…
Thats it you now have node and npm installed. nJoy πŸ˜‰

Saving a million documents in Mongo using Nodejs and mongodb module

/**
* Created by davidsaliba on 13/03/2017.
*/
var MongoClient = require('mongodb').MongoClient
, format = require('util').format;

var url = 'mongodb://localhost:27017/test';
var async = require ('async');

var entry = {
data : "skdlfjsdf",
array : [ {id:"arr_obj1"} , {id:"arr_obj2"} ]
};

var entries = [];

var total_entries = 1000000

for (var j = 0 ; j <= total_entries ; j ++){
console.log (j);
entries.push({"_id":j ,entry:entry});
}

console.log ("Number of entries", entries.length);

MongoClient.connect(url, function(err, db) {
// Get the collection
var col = db.collection('articles');
//

var bulk = col.initializeOrderedBulkOp();
var counter = 0;

async.whilst(
// Iterator condition
function() { return counter < total_entries },

// Do this in the iterator
function(callback) {
counter++;

bulk.insert(entries[counter] );

if ( counter % 1000 == 0 ) {
bulk.execute(function(err,result) {
bulk = col.initializeOrderedBulkOp();
callback(err);
});
} else {
callback();
}
},

// When all is done
function(err) {
if ( counter % 1000 != 0 )
bulk.execute(function(err,result) {
console.log( "inserted some more" );
});
console.log( "I'm finished now" );
db.close();
}
);
});

nJoy πŸ˜‰

Installing git on Debian 8.x

You should edit your sources.list , by adding the following line:

deb http://ftp.ca.debian.org/debian/ jessie main contrib

Then upgrade your package and install git:

apt-get update &amp;&amp; apt-get upgrade &amp;&amp; apt-get dist-upgrade
apt-get -f install
apt-get install git

nJoy ;-)

(more…)

send video from local device to a slave computer with ffmpeg

setup service listener on viewer machine :

while : ; do ffplay -i tcp://192.168.xx.xx:1234?listen ; done

send video to it :

ffmpeg -re -i /dev/video1 -vcodec mpeg2video -f alsa -i hw:2,0 -ac 2 -s 1920×1080 -r 25 -strict -2 -f mpegts tcp://192.168.xx.xx:1234

where

192.168.xx.xx is the IP of the viewer where the ffplay is running.

1234 is the port used.

nJoy πŸ˜‰

 

Sending mp4 to a wowza with ffmpeg

ffmpeg -re -i  video.mp4  -vcodec libx264  -vb 1500000 -g 60 -vprofile main  -f flv rtmp://ingest.cix.domain.com:1935/live/231232

 

nJoy πŸ˜‰

Create windows 10 boot disk on almost any linux host

Mount the ISO:

sudo mount -t udf -o loop,ro,unhide /path/to/file.iso /mnt

Insert the USB drive.
Run fdisk and specify the device name of the USB drive; for example:

sudo fdisk /dev/sdc

Delete any existing partition table and create a new one.
Create a new partition of at least 4.5 GB. Mark it bootable and set its type to 7 (HPFS/NTFS/ExFAT).
Write changes and exit fdisk.
Create a FAT-32 file system in the new partition; for example:

sudo mkfs.vfat -F 32 /dev/sdc1

Mount this partition to an existing subdirectory; for example:

sudo mount /dev/sdc1 /media/usbstick

Copy all of the files from the mounted ISO into this directory:

sudo cp -rv /mnt/* /media/usbstick

Sync the file systems just to be sure:

sudo sync

Unmount both items previously mounted:

sudo umount /media/usbstick
sudo umount /mnt

nJoy πŸ˜‰

 

test Graylog GELF UDP input from Bash

for i in {1..100} ; do echo '{"version": "1.1","host":"david.org","short_message":"A short message that helps you identify what is going on","full_message":"Backtrace here\n\nmore stuff","level":1,"_user_id":9001,"_some_info":"foo","_some_env_var":"bar"}' | nc -w 1 -u graylog.mydomain.com 12201  ; done

 

nJoy πŸ˜‰

Script to verify that a path is synchronized across multiple machines via ssh

This is a script I wrote for work to look through a number of remote servers via ssh (shared keys or include a .pem (id_rsa) file to compare a paths and all it’s subfolders.

The result is a report of which files are out of synch and if duplicates found they are listed separately.

#!/bin/bash
## Parameters  sync_check [-i id.pem] [-u <user for ssh>] -p <path_to_diff>  <target-system-IP1> <target-system-IP2> ...

# David Saliba [dx@sudoall.com]

RED='\033[0;31m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color


PEMFILE=""
SSH_USER="root"

function usage {
	echo 
	echo -e "\t$0 usage as follows :"
	echo -e "\t$0 [-i <pem_file>] [-u <ssh_user_name>] -p <path_to_diff> <ref-system-IPADDR1> <target-system-IP1> <target-system-IP2>..."
	echo 
}


[ $# -le 2 ] && echo && echo -e "${RED}Incorrect number of parameters ${NC}" && usage && exit 128


while getopts "i:u:p:" opt; do
echo $opt $OPTARG
  case $opt in
  	i ) PEMFILE=$OPTARG; shift $((OPTIND-1)); OPTIND=1 ; 
          if [[ -f "$PEMFILE" ]]; then 
              PEMFILE="-i ""$PEMFILE" 
          else
          	  echo "Pemfile : $PEMFILE not found. Quitting .. " 
          	  exit 1  
          fi
          ;;
	u ) SSH_USER=$OPTARG ; shift $((OPTIND-1)); OPTIND=1 ;;
	p ) PATH_TO_CHECK=$OPTARG ; shift $((OPTIND-1)); OPTIND=1 ;;
    * ) usage
       exit 128
  esac
done



extfile="_target.md5.sync_check"

		echo; echo

rm -f /tmp/*.sync_check
for i in $* ; do
	ipcalc -cs $i
	if [ $? == 0 ] ; then
		echo -n "Retrieving Signature List from ..  :[$i] : " 
		ssh $PEMFILE $SSH_USER@$i "hostname"

		COMMAND="ssh $PEMFILE $SSH_USER@$i \"find  $PATH_TO_CHECK -type f -exec md5sum {} \\; | sed -e 's/^/$i\t/'| sort -k 2 \""
		#echo "Running : $COMMAND  /tmp/$i""_target.md5.sync_check"
		bash -c "$COMMAND" > /tmp/$i$extfile
		
	else
		echo "Parameter $i not a valid IP skipping .."
	fi
done

echo ;echo; echo "Comparing data ... "; echo

 OLDIFS=$IFS; 
 IFS=$'\n'; 

 for i in `cat /tmp/*.sync_check  | sort -k3 | uniq -f 1 -c | sort | egrep -v "^[\ \t]*$#" | sort -k4 ` ;do 
 	
 	NUMBER_OF_HITS=`echo "$i" | awk '{print ($1)}'`

 	echo $i

 	if [ $NUMBER_OF_HITS -gt 1 ] ; then
 		
 		MD5Onward=`echo "$i" | awk '{print substr($0, index($0,$3))}'`
		echo -e -n "${YELLOW}"	
			grep -h "$MD5Onward" /tmp/*.sync_check  | awk '{print "\t\t",NR, $0}'
		echo -e -n "${NC}"	


 	fi


 done ;

 IFS=$OLDIFS


echo
echo




link to file here:Β http://jist.sudoall.com/sync_check/sync_check.sh

nJoy πŸ˜‰

Reviving dead Centos 4 repos

Edit
/etc/yum.repos.d/CentOS-Base.repo

Comment out the “mirrorlist” entries.
Uncomment the “baseurl” entries and change them to

http://vault.centos.org/4.9/os/$basearch

nJoy πŸ˜‰