Blogception

InAnimate blogged about HackedServer blogging

Advertisements

Listen For Input BASH

Here’s a script I worked out at a Hackathon last weekend to listen for input in BASH without maxing your CPU.

#Listens for input on ttyACM0 (an arduino button) nd 
#output the string to a file. Note this file must 
#already exist and I highly recommend making a ram
#disk for it. It also backgrounds the listening
cat /dev/ttyACM0 >> /tmp/input &

#I had to sleep my script for 5 seconds to get 
#rid of a false trigger. You can probably delete this
sleep 5

#Clears out the file
echo -n "" > /tmp/input

while true; do

	if [ -s /tmp/input ]; then #If temp > 0b
		#do stuff!
		echo -n "" > /tmp/input #Clears the input
	fi
	sleep 1 #This sleep is important! it controls
                #The while loop.



done

Recursive Unrar Script

If you’re looking for a code to recursively unrar files in a sub-directory I made a quick script that can be used!

#!/bin/bash
#This ensures that 2 parameters are passed to the script
if [ $# -ne 2 ]
	then
		echo "Usage is ./script <source> <desination>"
		exit
fi
#Stores the passed parameters
SOURCE=$1
DESTINATION=$2

#For each file in the subdirectory of the source. If they're a directory enter
#them and unrar them. Then move them to the destination.
for x in $SOURCE/*
        do
                if [ -d $x ]
                        then
                                cd $x
                                unrar e *.rar
                                mv *.{avi,mp4,aac,wmv,ogg,mkv,mpg} "$DESTINATION"
                fi
        done

Alarm In Bash

I was looking on the internet for a Bash script to play a tone for use in a bash script and couldn’t come up with anything so here’s what I wrote. ┬áIt will play the Westminster Quarters

#!/bin/bash
E=329.63
Gs=415.30
Fs=369.99
B=246.94
for X in $E $Gs $Fs $B $E $Fs $Gs $E $Gs $E $Fs $B $B $Fs $Gs $E
do
speaker-test -c1 -f$X -t sine -l1 -b5 > /dev/null
done

Simple Journal Script

Hello Readers!

I was looking for a solution the other day to do some journaling. I was considering doing something like Google Drive but I figured that more often than not I just want to scrobble down a few thoughts and call it good. I decided to make a quick bash script to make journaling a one command task!

The only prerequisite for this script is to make a directory called “journal” in your home directory.

#!/bin/bash
NOW=$(date +%Y-%m-%d)
if [ -s ~/journal/$NOW ]
	then echo ""
	else echo $'\nWeight:\nCalories:\nMoney Spent:' >> ~/journal/$NOW
fi
nano ~/prasc/journal/$NOW

This script will make a file with today’s date as the title in the format YYYY-MM-DD so your journal entries will always be in order. It also has a conditional statement to check and see if the file already exists. If the file doesn’t exist it pre-fills in a few headers for me that I want to keep track of. For me this is my Weight, Calorie Intake, and Money Spent. This will later allow me to do some simple analysis on these figures using grep! If you want to be able to run this anywhere remember you can always make an alias that points to it or drop it in your /usr/local/bin folder.