converting webm to mp3s ffmpeg

for FILE in *.webm; do
    echo -e "Processing file '\e[32m$FILE\e[0m'";
    ffmpeg -i "${FILE}" -vn -ab 128k -ar 44100 -y "${FILE%.webm}.mp3";
done;

nJoy 😉

Snapshot backup using cp -al and rsync

This script requires genuine cp -al capable gnu and rsync commands together with a hardlink capable FS + OS.

 

 

#!/bin/bash

[ $# -ne 2 ] && echo "Incorrect usage : $0 <source path> <target path>" && exit 128 ;

SOURCEFOLDER=$1
TARGETFOLDER=$2

SF_LEN=${#SOURCEFOLDER}-1
TF_LEN=${#TARGETFOLDER}-1

#echo "Last character in source folder is ${SOURCEFOLDER:SF_LEN}"
if [ "${SOURCEFOLDER:SF_LEN}" != "/" ] ; then
   echo "Adding trailing slash"
  SOURCEFOLDER=$SOURCEFOLDER"/"
fi



#echo "Last character in target folder is ${TARGETFOLDER:TF_LEN}"
if [ "${TARGETFOLDER:TF_LEN}" != "/" ] ; then
   echo "Adding trailing slash"
  TARGETFOLDER=$TARGETFOLDER"/"
fi



echo $SOURCEFOLDER
echo $TARGETFOLDER

LOCKFILE=/tmp/`echo $0 $SOURCEFOLDER $TARGETFOLDER | sed "s/[^[:alnum:]]/_/g"`.lck
echo "Lockfile : $LOCKFILE"



[ ! -d $SOURCEFOLDER ] && echo "Source does not exist !! $SOURCEFOLDER exitting with error" && exit 1;

TIMESTAMP=$(date --utc +%Y%m%d%H%M )
#echo $TIMESTAMP



if [ ! -d $TARGETFOLDER ]; then 

mkdir $TARGETFOLDER

rsync -av --delete  $SOURCEFOLDER $TARGETFOLDER/$TIMESTAMP/

else 

[ -d $TARGETFOLDER/$TIMESTAMP/ ] && echo "Folder already there !! Leaving.. " && exit 0;  

 LASTBACKUP=$(ls $TARGETFOLDER | sort -rn | head -1)
 echo "Link copying $TARGETFOLDER/$LASTBACKUP to $TARGETFOLDER/$TIMESTAMP/"
 cp -al $TARGETFOLDER/$LASTBACKUP $TARGETFOLDER/$TIMESTAMP/
 rsync -av $SOURCEFOLDER $TARGETFOLDER/$TIMESTAMP/

fi

echo " OK !! Done"

 

 

 

Run a local script on remote machine with parameters

So you have a script on the local machine and you want to run it remotely and pass arguments to it :


ssh user@remote 'cat | bash /dev/stdin param1 param2 .. paramN' < /usr/scripts/localscript.sh

😉 nJoy

 

Recording a session for a user when he / she logs in ssh

 

To start recording each session add this to the users .profile file

DATE=$(date +”%Y%m%d%H%M”)
mkdir /log/$DATE
script -t 2>/log/$DATE/bashlogs.timing -aqf /log/$DATE/bashlogs.script

 

to playback go to

/log/<timestamp>

and run

scriptreplay  bashlogs.timing bashlogs.script 3

where the 3 is the speed up factor.

nJoy;

 

Quick script to get path to latest nagios version

If you need to automate the retrieval of the latest Nagios version path to download this is how I do it.

Nothing fancy and it breaks if they change the sourceforge site but we can fix when that happens 🙂

 

curl -v http://www.nagios.org/download/core/thanks/ 2>&1 | grep tar\.gz | cut -d \” -f 2 | sort -r | head -n 1

Result:

http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.4.1.tar.gz

Of course this comes in handy when pulling for the clients being monitored so by extension:

 curl -v http://www.nagios.org/download/plugins/ 2>&1 | grep tar\.gz | cut -d \” -f 2 | sort -r | head -n 1

Result:

http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.16.tar.gz

Getting the files in a script is as easy as :

curl -v http://www.nagios.org/download/plugins/ 2>&1 | grep tar\.gz | cut -d \” -f 2 | sort -r | head -n 1 | xargs wget

Ping me if this stops working for you.

Enjoy.