Sunday, April 6th, 2008

Openbox Pipe Menu for xcompmgr

I have been playing around with and writing a Bash script pipe menu for xcompmgr under Openbox. The script has dual functionality; firstly, it acts as on/off toggle for xcompmgr; secondly, it produces a conditional menu depending on whether or not xcompmgr is running — if xcompmgr is not running, an "Enable Compositing" menu item will appear; if xcompmgr is running, a "Disable Compositing" menu item will be offered along with a list of "Set Target Window Transparency to XX%" items.

It is a simple Bash script, but quite effective. Please feel free to modify/improve as you see fit.

#!/bin/bash
# Openbox Pipe Menu for xcompmgr
################################

# Set xcompmgr command options
EXEC='xcompmgr -c -t-5 -l-5 -r4.2 -o.55' #basic compositing
#EXEC='xcompmgr -cCfF -t-5 -l-5 -r4.2 -o.55 -D6' #more effects

# Toggle compositing. Call with "myxcompmgr --startstop"
if [ "$1" = "--startstop" ]; then 
    if [ ! "$(pidof xcompmgr)" ]; then
      $EXEC
    else
      killall xcompmgr
    fi
    exit 0
fi
# Output Openbox menu
if [ ! "$(pidof xcompmgr)" ]; then
    cat << _EOF_
    <openbox_pipe_menu>
        <item label="Enable Compositing">
            <action name="Execute">
                <execute>myxcompmgr --startstop</execute>
            </action>
        </item>
    </openbox_pipe_menu>
_EOF_
else
    cat << _EOF_
    <openbox_pipe_menu>
        <item label="Remove Transparency from Target Window">
            <action name="Execute">
                <execute>transset 1</execute>
            </action>
        </item>
        <item label="Set Target Window Transparency to 10%">
            <action name="Execute">
                <execute>transset .90</execute>
            </action>
        </item>
        <item label="Set Target Window Transparency to 20%">
            <action name="Execute">
                <execute>transset .80</execute>
            </action>
        </item>
        <item label="Set Target Window Transparency to 30%">
            <action name="Execute">
                <execute>transset .70</execute>
            </action>
        </item>
        <item label="Set Target Window Transparency to 40%">
            <action name="Execute">
                <execute>transset .60</execute>
            </action>
        </item>
        <item label="Set Target Window Transparency to 50%">
            <action name="Execute">
                <execute>transset .50</execute>
            </action>
        </item>
        <item label="Set Target Window Transparency to 60%">
            <action name="Execute">
                <execute>transset .40</execute>
            </action>
        </item>
        <item label="Set Target Window Transparency to 70%">
            <action name="Execute">
                <execute>transset .30</execute>
            </action>
        </item>
        <item label="Set Target Window Transparency to 80%">
            <action name="Execute">
                <execute>transset .20</execute>
            </action>
        </item>
        <item label="Set Target Window Transparency to 90%">
            <action name="Execute">
                <execute>transset .10</execute>
            </action>
        </item>
        <separator/>
        <item label="Disable Compositing">
            <action name="Execute">
                <execute>myxcompmgr --startstop</execute>
            </action>
        </item>
    </openbox_pipe_menu>
_EOF_
fi
exit 0

How to use the script

Follow the instructions below to install the script and set-up the Openbox pipe menu:

1. Open a terminal and download the script with the following command:

wget http://crunchbang.org/misc/myxcompmgr

2. Move the script to your "bin" directory and make executable:

mv myxcompmgr ~/bin/myxcompmgr && chmod +x ~/bin/myxcompmgr

3. Open your Openbox menu.xml file for editing:

gedit ~/.config/openbox/menu.xml

4. Insert the following code where you would like the menu to appear, save and exit:

<menu execute="myxcompmgr" id="CompositingPipeMenu" label="Compositing"/>

5. Issue the following command to update/reconfigure Openbox:

openbox --reconfigure

Optional: You could also place the following entry in ~/.config/openbox/autostart.sh to start xcompmgr on boot:

# Enable Eyecandy, see ~/bin/myxcompmgr for more info
myxcompmgr --startstop &

Sunday, February 17th, 2008

Wicked Cool Shell Scripts

I've not read the book, but the Wicked Cool Shell Scripts site and its example shell scripts are, erm, wicked cool. The site offers a whole host of scripts, some of which could quite easily be adapted/hacked into useful tools. If you're remotely interested in Shell scripting, you should take a look, even people with scripting experience might learn a thing or two.

URL: http://www.intuitive.com/wicked/index.shtml

Download the script library: wicked-cool-shell-scripts.tgz


Sunday, November 18th, 2007

Bash Script: MySQL Backup

I thought that it might be a good idea to start posting a few of my scripts; it'll be handy to have them on my site for future reference. Also, I learn a lot by reading example scripts — I guess others might be able to learn from mine.

I wrote the following Bash script to perform a backup of a remote MySQL database. The script first connects via SSH and performs a MySQL dump, saving the results to file. It then connects via SFTP and downloads the file. Once the file has been downloaded, it restores the database to my local MySQL server.

It is quite a simple Bash script and it should be fairly straightforward to follow.

#!/bin/sh
# Settings
#############################
REMOTEHOST="example.com"
REMOTEBACKUPDIR="backup/sql"
SQLHOST="localhost"
SQLDB="database_name"
SQLUSER="username"
SQLPASS="password"
SQLFILE="database_name.sql"
LOCALBACKUPDIR="backup/sql"
#############################
# Start main
echo "* Connecting via SSH..."
ssh $REMOTEHOST <<**
echo "* Performing SQL dump..."
if [ -d $REMOTEBACKUPDIR ]; then
    cd $REMOTEBACKUPDIR
else
    mkdir $REMOTEBACKUPDIR
    cd $REMOTEBACKUPDIR
fi
mysqldump -h $SQLHOST --user="$SQLUSER" --password="$SQLPASS" $SQLDB > $SQLFILE
echo "* Closing SSH connection..."
exit
**
cd ~
if [ -d $LOCALBACKUPDIR ]; then
    cd $LOCALBACKUPDIR
else
    mkdir $LOCALBACKUPDIR
    cd $LOCALBACKUPDIR
fi
echo "* Connecting via SFTP..."
sftp $REMOTEHOST <<**
cd $REMOTEBACKUPDIR
get $SQLFILE
exit
**
echo "* Restoring SQL dump to local server..."
mysql --user "$SQLUSER" --password="$SQLPASS" $SQLDB < $SQLFILE
echo "* SQL backup complete."
cd ~
exit 0

Notes

  1. For automation purposes, this script assumes that SSH and SFTP have been configured for automatic login. See "Creating Private/Public SSH Keys"
  2. It also assumes there is a mirrored MySQL server and user account running on the local machine.
  3. The script can be automated using Crontab.
  4. Lacks any error handling and/or logging!?
  5. I've worked with some commercial hosting providers who do not grant table locking privileges to their MySQL users — table locking can be bypassed by adding the "--skip-lock-tables" option to the "mysqldump" command. Use with caution.

Friday, October 19th, 2007

Creating Private/Public SSH Keys

13th May 2008 Update: I have removed the original contents of this post. Normally I would not remove the contents of any blog post; however, due to security reasons I did not want anyone to follow the instructions that were contained within the post. I have updated the information about creating passwordless SSH keys and moved it to my wiki, it is probably better off there anyway ;) See:

Sorry for any inconvenience this may have caused.

Tagged with: bash, linux, ssh, ubuntu | Comments [5]


Browse Posts by Tag

13th advocacy antispam artwork bash bbc bcs bittorrent bloggers blogs boobs bookmarklets cli code colour commands comments conduit crontab crunchbanglinux debian design development email fluxbuntu fonts fun gedit gimp gnome google gos hack hacks hardware hosting images javascript language launchpad licenses life lincslug linux lugradio madness meme memes microsoft mint misc monkeys motu muppets mysql n95 networking nokia openbox openoffice opensuse packaging penguins php phpmyadmin podcast ppa printer progbox programming projects puppy python random rants realplayer revu scripts security shell software ssh terminal terminator themes tools twitter typography ubuntu ubuntucse unitedhosting video virtualisation webcam webdesign whird wiki windows woot xfce4 zombies