Tag Archives: sh

uzbl_tabbed.py: commands to FIFO

The list is on line 782 (ATM) of uzbl_tabbed.py. The FIFO location is determined by your settings (top of file for defaults, possibly overridden from config). It’s like this:

782     def parse_command(self, cmd):
783         '''Parse instructions from uzbl child processes.'''
784
785         # Commands ( [] = optional, {} = required )
786         # new [uri]
787         #   open new tab and head to optional uri.
788         # close [tab-num]
789         #   close current tab or close via tab id.
790         # next [n-tabs]
791         #   open next tab or n tabs down. Supports negative indexing.
...

So, to open a new tab in uzbl_tabbed from newsbeuter, you need a script like newtab.sh:

#!/bin/sh
echo "new $1" > `ls -1 /tmp/uzbltabbed_*`

Then call it from newsbeuter – put this in ~.newsbeuter/config:

browser "~/.local/share/uzbl/scripts/newtab.sh %u"

Lousy jailed-lighttpd scripts

Now, jailed has its own automated scripts to generate its own proper fully-contained jails (as far as “jails” on GNU/Linux go, that is; they’re chroots, actually).

The following scripts are leftovers from me trying to do the same, before finding out that the utilities are already there. They have been lying around for quite some time. I’m just copying them here so I can delete them from the home dir.

=====

jailed-lighttpd-install
—–

#!/bin/sh
# Create a jail for lighttpd

jail=/jail/lighttpd

mkdir -p $jail
cd $jail

mkdir tmp
chmod 1777 tmp

mkdir -p        var/log/lighttpd var/run/lighttpd home/http
chown http:http var/log/lighttpd var/run/lighttpd home/http
chmod a+rx      var/log/lighttpd var/run/lighttpd home/http

mkdir etc
cp -avr /etc/php etc/
cp -v /etc/hosts /etc/nsswitch.conf /etc/resolv.conf /etc/services /etc/localtime etc/
cp -v /etc/group /etc/host.conf /etc/passwd /etc/protocols etc/

mkdir -p usr/bin
cp /usr/bin/php /usr/bin/php-cgi usr/bin/

# read l2chroot before use
./l2chroot /usr/bin/php
./l2chroot /usr/bin/php-cgi

# just in case some permissions were forgotten...
chmod a+rx $jail

=====

jailed-lighttpd.rc
—–

#!/bin/bash

# general config
. /etc/rc.conf
. /etc/rc.d/functions

jailroot=/jail/lighttpd
function jailcmd () {
su http -c "$*"
}

PID=`pidof -o %PPID /usr/sbin/lighttpd`

case "$1" in
start)
stat_busy "Starting jailed lighttpd Daemon"
[ -z "$PID" ] && jk_chrootlaunch -j $jailroot -x /usr/sbin/lighttpd -- -f /etc/lighttpd/lighttpd.conf 2>&1
if [ $? -gt 0 ]; then
stat_fail
else
add_daemon lighttpd
stat_done
fi
;;
stop)
stat_busy "Stopping jailed lighttpd Daemon"
[ ! -z "$PID" ] && jailcmd kill $PID &>/dev/null
if [ $? -gt 0 ]; then
stat_fail
else
rm_daemon lighttpd
rm -f $jailroot/var/run/lighttpd/lighttpd.pid
stat_done
fi
;;
restart)
$0 stop
sleep 1
$0 start
;;
*)
echo "usage: $0 {start|stop|restart}"
esac

=====

l2chroot
—–

#!/bin/bash
# Use this script to copy shared (libs) files to Apache/Lighttpd chrooted
# jail server.
# ----------------------------------------------------------------------------
# Written by nixCraft <http://www.cyberciti.biz/tips/>
# (c) 2006 nixCraft under GNU GPL v2.0+
# + Added ld-linux support
# + Added error checking support
# ------------------------------------------------------------------------------
# See url for usage:
# http://www.cyberciti.biz/tips/howto-setup-lighttpd-php-mysql-chrooted-jail.html
# -------------------------------------------------------------------------------
# Set CHROOT directory name
BASE="/jail/lighttpd"

if [ $# -eq 0 ]; then
echo "Syntax : $0 /path/to/executable"
echo "Example: $0 /usr/bin/php5-cgi"
exit 1
fi

[ ! $BASE ] && mkdir -p $BASE || :

# iggy ld-linux* file as it is not shared one
FILES="$(ldd $1 | awk '{ print $3 }' |egrep -v ^'\(')"

echo "Copying shared files/libs to $BASE..."
for i in $FILES
do
d="$(dirname $i)"
[ ! -d $BASE$d ] && mkdir -p $BASE$d || :
/bin/cp $i $BASE$d
done

# copy /lib/ld-linux* or /lib64/ld-linux* to $BASE/$sldlsubdir
# get ld-linux full file location
sldl="$(ldd $1 | grep 'ld-linux' | awk '{ print $1}')"
# now get sub-dir
sldlsubdir="$(dirname $sldl)"

if [ ! -f $BASE$sldl ];
then
echo "Copying $sldl $BASE$sldlsubdir..."
/bin/cp $sldl $BASE$sldlsubdir
else
:
fi

=====

There. Sorry for the tabbing, it went AWOL.

Making a movie from image files using ffmpeg

There’s quite a lot of tutorials on the net, search for the title.

I had an issue, though: the images were taken with a web camera, and some of the images were garbled (wrong header, bad data, etc.). So ffmpeg choked on those silently, and the movie got cut off in the middle.

To find those, use something like

file * | grep

Also, to rename the images from the camera:

#!/bin/sh
#

n=1

for i in 122*; do
    echo $n
    cp $i processed/$n.jpg
    n=`expr $n + 1`
done

wpi-monitor: simple script to keep the wireless link up

I’m using a rum device in Host AP mode, so every time I try to send a large file or open many connections, the wireless link breaks down (gets “no carrier” instead of “associated”). To get it back up, I have to pull the interface on the station computer (wpi) down and then back up.

To automate the process, I’ve written this simple script. To be run with root/operator permissions.

#!/bin/sh
# Stop wpi from falling off.

if=wpi0 # interface name

while true
do
        # see if it has "no carrier" status, by looking for "no"
        status=`ifconfig $if | grep status | cut -d ":" -f 2 | cut -d " " -f 2`

        # bourne shell string comparison... you can has it
        if [ "$status" = "no" ] ; then
                ifconfig $if down
                ifconfig $if up
#               echo down
        else
#               echo up
        fi

        sleep 1
done

Copying music to USB flash from command line, fast

Thanks to this post.

EDIT: This doesn’t work well.

#!/bin/sh
# Script to copy music to media player (USB).

# remove the last character
var=`echo $*|sed s/.$//`

echo "Copying: $var"

# now copy
cp -R "$var" /mnt/player/ &

Grab’n’drop

Here’s something annoying: when you have to copy/move some files to another directory, and then cd there yourself. Written scripts to do that faster: grab:

#!/bin/sh

dir=`pwd`

for item in `echo $@`; do
	echo $dir/$item >> ~/tmp/grab
done

And drop:

#!/bin/sh

grabfile=~/tmp/grab
tempfile=~/tmp/grab.tmp

echo "" > $tempfile				# create if missing

for item in `cat ~/tmp/grab`; do
	mv $item . 2> /dev/null
	if [ $? -ne 0 ]; then			# was some trouble
		echo $item >> $tempfile
		echo "Cannot move: $item"
	fi
done

mv $tempfile $grabfile

Also, added a lose script, which merely deletes ~/tmp/grab for now.

awesome: launch custom commands from menu

The menu in the awesome wiki is a good one, yet it has some drawbacks:

1) It’s written in bash. Not all systems have bash. Not all systems have bash in /bin/bash.
2) The menu is stored inside the script itself, which makes it hard to edit.

My solution: write a menu file with choices:

% pwd
/usr/home/cy/.config/awesome
% cat menu
firefox
thunderbird
transmission
linuxdcpp
sunbird
eclipse

Add a command to .awesomerc, like this one:

key
{
modkey = {"Mod4"} key = "F2" command = "spawn"
arg = "cat /usr/home/cy/.config/awesome/menu | awesome-menu -e 'sh ~/bin/awesome-exec ' 'Execute:' &"
}

Finally, write ~/bin/awesome-exec (or elsewhere, if you fancy):

#!/bin/sh

case $1 in
        sunbird)
                exec linux-sunbird & ;;
        *)
                exec $1 & ;;
esac

As you can see, this solution is a lot more simple than the one in the awesome Wiki. Also, you can edit the menu easily, like this:

echo mutt >> ~/.config/awesome/menu // add
cat ~/.config/awesome/menu | grep -v mutt > ~/.config/awesome/menu //remove

I’m saying “easily”, because you can add these commands as an alias.