Archive for the ‘Arch-Linux’ Category

Xrandr - turn off one of your multiple monitors

Monday, February 6th, 2012

Xrandr is not just for setting up resolutions and multiple monitors, it will do all sorts of other stuff too, but one thing I need for my carpc project was to be able to programmatically turn off the screen on the netbook (carpc) once it was up and running on the main screen on the car dash. I couldn’t play with X because both screens were running from “one display”. Xrandr to the rescue:

xrandr -q

will give you the names of the screens you have running. Once you know this you can issue a command to turn off which ever screen you like:

xrandr –output LVDS1 –off

where LVDS1 is the name of my netbook display (there are two double hyphens in the above code!)

xrandr –output LVDS1 –auto or  xrandr –output LVDS1 –on will bring it back on

HTML Auto Slideshow using Javascript and php with dynamically generated array of Images

Friday, October 14th, 2011

Another holy grail for me, to be able to just add images to a directory and have the slideshow automatically pick them up and display them withoput having to edit html /javascript code. Most scripts I had found for an html slideshow required the array created inside the script, this way you use php to generate the array and then the javascript runs with it. Only downside is you will need php up and running, but most web servers online have this by default now.

My blog is a bit broken at the moment so will have to link the files to Ubuntuforums

http://ubuntuforums.org/showpost.php?p=11339174&postcount=2

  1. Images will be shown at their actual size, so you may need to add some html code to the tag in the to restrict the images size.
  2. On your server, go to the place where you want the html file to be and upload the index.html file there, then create a sub-directory called pics and upload the getimages.php file to the pics directory.
  3. Next upload all your images to the pics directory.
  4. Done.

Acknowledgements to all the clever people who wrote the original scripts and files

Auto Web Page Changer using iframe

Monday, May 23rd, 2011

Oh I like this. In seeking to setup a rolling web browser display display at work, I came upon this small but very clever bit of javascript, which on a timer will change the web page being viewed inside an iframe. Just edit the defaults to you preferred pages and timings and away you go:

 <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>Changing Pages… Please Wait</title>
<script type=”text/javascript”>
var frames = Array(’http://www.google.com/’, 15,
‘http://www.yahoo.com/’, 15,
‘http://www.ask.com/’, 15,
‘http://www.dogpile.com/’, 15);
var i = 0, len = frames.length;
function ChangeSrc()
{
if (i >= len) { i = 0; } // start over
document.getElementById(’frame’).src = frames[i++];
setTimeout(’ChangeSrc()’, (frames[i++]*1000));
}
window.onload = ChangeSrc;
</script>
</head>
<body>
<iframe src=”" name=”frame” id=”frame” width=”100%” height=”100%”></iframe>
</body>
</html>

I had to put a fixed height in there as 100% wasn’t giving 100% just 10% at the top of the page. This script repeats adinfinitum. If you only want it to run once, use this one:

 <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>Changing Pages… Please Wait</title>
<script type=”text/javascript”>
var frames = Array(’http://www.google.com/’, 15,
‘http://yahoo.com/’, 15,
‘http://www.ask.com/’, 15,
‘http://dogpile.com/’);
var i = 0, len = frames.length;
function ChangeSrc()
{
document.getElementById(’frame’).src = frames[i++];
if (i >= len) return; // no more changing
setTimeout(’ChangeSrc()’, (frames[i++]*1000));
}
window.onload = ChangeSrc;
</script>
</head>
<body>
<iframe src=”" name=”frame” id=”frame” width=”100%” height=”100%”></iframe>
</body>
</html>

and it gets better! Now the next set of code does the rolling web pages, with no border on the iframe, no scrollbar on the iframe, and with a fix for full height and width in Firefox:

 <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>Changing Pages… Please Wait</title>
<style type=”text/css”>
html, body, div, iframe { margin:0; padding:0; height:100%; }
iframe { display:block; width:100%; border:none; }
</style>
<script type=”text/javascript”>
var frames = Array(’http://www.google.com/’, 15,
‘http://www.yahoo.com/’, 37,
‘http://www.ask.com/’, 12,
‘http://www.dogpile.com/’, 14);
var i = 0, len = frames.length;
function ChangeSrc()
{
if (i >= len) { i = 0; } // start over
document.getElementById(’frame’).src = frames[i++];
setTimeout(’ChangeSrc()’, (frames[i++]*1000));
}
window.onload = ChangeSrc;
</script>
</head>
<body>
<div>
<iframe src=”" name=”frame” id=”frame” width=”100%” height=”100%” border=”0″ scrolling=”no”></iframe>
</div>
</body>
</html>

Run programs without sudo ?

Saturday, May 7th, 2011

Wouldn’t normally do this, or recommend it, but for occasional and considered use this is a useful tip.You need to run a program normally requiring sudo, but as a normal user. The usual way of fixing this is to put a line in /etc/sudoers, but you still need to type sudo.The problem I had was with a custom iso I have been putting together. because my WM was openbox I was using a bash script with zenity to provide reboot and shutdown. This was all set up fine, but on installing the distro from the live cd, the installation needed to add a line to the bottom of /etc/sudoers, thereby negating my previously entered line.A long trawl through google provided an answer on ubuntuforums, which was to change the set uid bit for the shutdown command, so that all users could run shutdown with needing sudo. As you can see, doing this to a more important command would create security holes, but in this instance there is not much a hacker can do with shutdown, other than shutdown…AFAIK !!So here is the command I used:

sudo chmod a+s /sbin/shutdown

which gives the following permission:

 645 -rwsr-sr-x  1 root root    46864 2011-01-22 01:58 shutdown

I edited out the sudo shutdown in my script and replaced it with /sbin/shutdown and all is well

Run Once Only Bash Scripts

Thursday, April 21st, 2011

I am constantly amazed by what can be achieved with a simple bash script or two. I had a situation where I needed a script to run only once, and to not get any errors spat out at me from the cli. I needed a second script to call the run once script to go into rc.local, a file I didn’t want to mess with, so the call in rc.local would just be a quick file check after the first run. for me, the clever bit is that the scriptI have to do the work can “move” (rename) itself once it has done its business, thereby ensuring it is not called upon again, but is still there if needed.

Here’s the script that does the work (called once.sh):

#!/bin/bash
Do the work

echo “I am now going to back myself up :)!”
sleep 2
mv once.sh once.sh.bak
echo file backed up
sleep 2
exit 0

The key line is the mv command, running on itself! I’ll remove the comments for the production setting

Here’s is the script that calls the one above (called runitonce.sh):

 #!/bin/bash
if [ -f ~/once.sh ]
then
echo the file exists
sleep 2
~/once.sh
else
echo the file does not exist
sleep 2
fi

Basically, if once.sh is there, this script, runitonce.sh, runs once.sh, which when finished, renames itself. If once.sh is not there, the script just finishes. Subsequent runs of the script runitonce.sh called in rc.local just run through as there is no file to run. Simples :)

Play your entire music collection - Mplayer One Liner

Saturday, April 16th, 2011

Sometimes just plain lazy, and want just to play music. Run this command in the background (ALT+F2) or in a terminal for playback of all your mp3/ogg/m4a/wma, shuffled, looped, normalised. What’s nice about this is that the shuffle algorithym does a good job and with a large collection of music you don’t get repeats. I found that trying the same thing with vlc meant the shuffle was  always the same, and so you always started with the same music. :( Anyway the one-liner:

find ~/Music \( -iname “*\.mp3″ -o -iname “*.m4a” -o -iname “*.ogg” -o -iname “*.wma” \) -exec mplayer -nocache -af volnorm -shuffle -loop 0 ‘{}’ + &

Change “~/Music” to suit.

Even better put this in a script, and link to a keyboard shortcut, or add to your startup?

Now running the one liner from a terminal takes a bit of stopping, you’ll need to CTRL+C a couple of times in quick succession to close find then mplayer. Or you can run another one-liner:

killall -15 find mplayer

If you run the command from a script, you’ll have to shut down the script first, and then kill off the running instances of find and mplayer. Best to also do this from a script as well. Say the script you use to run is called singles.sh, let’s create another called endsingles.sh which contains:

#!/bin/bash

killall -15 singles.sh
killall -15 find
killall -15 mplayer

I am sure someone clever could bind this all together in one script, based upon a keyboard shortcut toggle or something…

Prevent Screen Blanking on Xubuntu CLI / Slim / Openbox Install on Asus EB1012 nettop

Wednesday, April 6th, 2011

Normally I am able to take care of screen blanking through the gui powersaving options in Xubuntu, however my command line install followed by installing openbox and using slim as a login manager presented me with real problems. teh screen would blank and half kill the x server, leaving a reboot as the only option. I found some xset options which I put into a script and added this to autostart.sh, which seemed to take care of X issues, but the terminal blanking was still going on. Using setterm I was able to stop terminal blanking but had to find a place to put it on startup. This turned out to be in /etc/profile (for all users). So now writing this post from my non blanking setup :)

sudo nano ~/.config/openbox/noblankx.sh

#!/bin/bash

xset s blank

xset s 0 0

xset -dpms

I was able to test this by outputting xset -q > test.txt at the end of the script, which produced

Keyboard Control:
auto repeat:  on    key click percent:  0    LED mask:  00000000
XKB indicators:
00: Caps Lock:   off    01: Num Lock:    off    02: Scroll Lock: off
03: Compose:     off    04: Kana:        off    05: Sleep:       off
06: Suspend:     off    07: Mute:        off    08: Misc:        off
09: Mail:        off    10: Charging:    off    11: Shift Lock:  off
12: Group 2:     off    13: Mouse Keys:  off
auto repeat delay:  660    repeat rate:  25
auto repeating keys:  00ffffffdffffbbf
fadfffefffedffff
9fffffffffffffff
fff7ffffffffffff
bell percent:  50    bell pitch:  400    bell duration:  100
Pointer Control:
acceleration:  2/1    threshold:  4
Screen Saver:
prefer blanking:  yes    allow exposures:  yes
timeout:  0    cycle:  0
Colors:
default colormap:  0×20    BlackPixel:  0    WhitePixel:  16777215
Font Path:
/usr/share/fonts/X11/misc,/usr/share/fonts/X11/100dpi/:unscaled,/usr/share/fonts/X11/75dpi/:unscaled,/usr/share/fonts/X11/100dpi,/usr/share/fonts/X11/75dpi,/var/lib/defoma/x-ttcidfont-conf.d/dirs/TrueType,built-ins
DPMS (Energy Star):
Standby: 600    Suspend: 600    Off: 600
DPMS is Disabled

The important bits for this are in bold.

Now add the script to autostart.sh

nano ~/.config/openbox/autostart.sh

and add the line:

~/.config/openbox/noblankx.sh &

Now for terminal blanking

sudo nano /etc/profile

scroll to the bottom and add

setterm -blank 0 -powersave off -powerdown 0

[EDIT] You can also put this command in /etc/rc.local, it works just the same :)

A reboot is necessary to test it out.

More information is available from man xset and man setterm but google is better to get real examples of usage.

Looking for a way to view the current settings for setterm, to see what is in place……

Simple Linux Slideshows

Sunday, March 6th, 2011

For running in X:

Use feh

sudo apt-get install feh

Set up a directory with photos in it, e.g. ~/photos or ~/Pictures and then run this command:

feh -zZxF -D 10 ~/photos

(-z for random, -Z for autozoom, -x for borderless windows, -F for fullscreen, -D for time on screen)

You might try using unclutter to get rid of the mouse cursor, but on some setups this doesn’t work well with feh, alternatively just move the mouse down into a corner somewhere

For framebuffer: (assumes you have your framebuffer up and running OK, see here for how)

Use fbi

sudo apt-get install fbi

Set up a directory with photos in it, e.g. ~/photos or ~/Pictures and then run this command (n.b. you might need sudo depending on your setup):

(sudo)fbi -ua -t 10 ~/photos/*

(-u for random, -a for autozoom, -t for time on screen)

Press V on the keyboard to hid the status line (although its a nice added feature)

(A nod in the direction of KMandla for getting me going on this :) )

Meld - saved me from myself!

Friday, March 4th, 2011

Meld is a file/directory differencing programming (with GUI). (in the repos)

I was under orders to put together a new website for my work, and didn’t want to pay out for web designers, so I turned to Drupal 7 for the first time and had a play. Over the last couple of months, in bits of spare time, I tinkered and fiddled, setting up home pages, news pages, forums, sidebars and menus, getting the theme right. Lots of good help from the community, but ignoring all guidance about not fiddling with the “core”.

Anyway I got to a position where I could go “live”, so reorganised the domain forwardings, adjusted a few absolute link references and we were off. At this point my sysadmin brain kicked in (it’s very small :)). Back it up? What if Drupal updates overwrite all my work so far?

So I ftp’d a copy of the drupal folders down to my machine, and saved out a copy of the MySQL database using phpmyadmin. A good start, but what about all the changes I had made? Introducing Meld.

Just open it up, point it at the two directories you want to compare, and let it rip. Amazing. It identifies and highlights all the differences between the two folders (including sub directories) or files.

A folder view

Meld Directory Compare

A file view

Meld File Compare

So with this tool I am now able to document all the changes I made to the “core”, and recover if and when I update Drupal or any installed modules. By the way, Drupal is a huge leap forward and a great website/blog/forum website builder.

Jinamp Party Piece

Saturday, February 26th, 2011

Jinamp Party Piece

Ok, daughter having birthday party, kicking us out of the house for the evening. Last year, I set her up with Audacious on the htpc so that she and her guests could chose music to play, with a couple of backup options of using xbmc or a DVD full of mp3s. This year we have a new machine running as htpc, no DVD drive. Also, daughter just wants a shuffled playlist to run, with no intervention.

A few weeks ago I was mooching about on KMandla’s new wiki of CLI apps, and came across jinamp , which is a sort of background player. What it does is takes the feed of a directory or playlist, shuffles it, then sequences it to a player of its or your choice, then disappears off into the background.

So I built up a playlist using audacious, called it pop.m3u and saved it to a shared place on the network. I needed to tidy up this list to just have file paths and names so:

sort pop.m3u > pop.lst

*.lst is the default file format for playlists with jinamp. Next I just opened up pop.lst and deleted all the EXTINF lines, which were now nicely sorted to the top. So now the playlist contents looked like this:

/path/to/song1.mp3
/path/to/song2.mp3
/path/to/song3.mp3

Order doesn’t matter because it is going to get shuffled anyway ;)

So downloaded and installed the latest (and pretty old) version of jinamp

sudo dpkg -i jinamp_1.0-1.i386.deb

I also had to install mplayer, as I was going to use this as my player:

sudo apt-get install mplayer

Added just one line to mplayer’s ~/.mplayer/config file for now:

af=volnorm

in the hope that this would help to normalise sound levels (seems to do something)

Right ready to test now, here is the basic command to get it running:

jinamp -p /usr/bin/mpayer /path/to/pop.lst

There is a little pause, and then music starts playing, you are back at the command prompt, and can no longer interact with the program. If you look in htop, you will see an entry for jinamp and also one for mplayer playing the file.

I set up the htpc with a fullscreen terminal, which would just serve to confuse (no fiddling) and amaze (how cool and geeky!) 17 year olds :) Had to run this with X, as for some reason I can’t get a VT over hdmi.

But of course you need to be able to interact with jinamp, to stop it (it will just keep on going!) or to skip to the next song. You might also want to display the title and artist of the current playing song as well. This is where jinamp-ctl comes in.

jinamp-ctl stop

will stop the thing running and close the player.

jinamp-ctl next

will move you to the next song on “jinamps” list.

jinamp-ctl query

will show you the name of the currently playing song (along with its full path!)

So I set about figuring out how to start the player, and then show the name of the currently playing song in the middle of the screen, without the mp3 extension, no cursor or mouse cursor, in a lovely cyan colour with a black background. I needed a script!

To remove the terminal cursor you have to type:

setterm -cursor off

To remove the mouse cursor, the easiest solution I found was to install “unclutter” and then run it, removes the idle cursor from the screen after 5 seconds by default. Further usage and investigation shows that unclutter runs at start up so if you like having it in your session, you don’t need the command. If you want to choose when to start unclutter, then edit the /etc/default/unclutter file and change true to false.

sudo apt-get install unclutter

unclutter

To change the colour of the screen text I needed “tput” which is already installed by default.

tput setaf 6

makes text cyan

tput setab 0

makes the background black (already is but useful to know)

tput bold adds

bold to the text to make it stand out more.
More on this here

Next was to strip the filename back to you the Artist and Title from the output of jinamp-ctl query. I did this by piping jinamp’s output into xargs and basename as follows:

jinamp-ctl query | xargs -0 -n1 -imp3 basename mp3 | cut -d”.”

It took a fair bit of googling to find all the elements required for this :)

Then I needed this output to update regularly. Too tricky for me to figure out what was required when the song actually changed, so I just went for a routine that fired every five seconds:

sleep 5

Finally, the solution to centre the text output on the screen. This takes a bit of trial and error, I am sure it can be figured out programatically rather than adjusting numbers, but for my purposes, this worked. The htpc screen is running at 800×600 (because the htpc is also linked to another older TV that can’t cope with more) so a terminal at full screen has @ 80 columns and 30 lines. I found that:

perl -e ‘print “\n”x10′;

added enough blank lines, and then piping all the output through to:

sed  -e :a -e ’s/^.\{1,57\}$/ & /;ta’

put the text more or less in the centre. ( I also set terminal font size to 16 ). Life is too short for me to learn and understand sed :)

So the final script called jinamp.sh looks like this:

#! /bin/bash#hides cursor
setterm -cursor off &

#hides mouse cursor after 5 seconds
unclutter & # (only needed if you haven’t rebooted)

#starts jinamp with named playlist

jinamp -p /usr/bin/mplayer “/media/music/burn/pop.lst”

#displays playing file every five seconds when jinamp is running

tput setaf 6;
tput setab 0;
tput bold;
while [ 1 ]; do
jinamp-ctl query | xargs -0 -n1 -imp3 basename mp3 | cut -d”.” -f1 && perl -e ‘print “\n”x10′; sleep 5; done | sed  -e :a -e ’s/^.\{1,57\}$/ & /;ta’

This is all fine, but daughter might wish to move to the next song. To save her fiddling about at the htpc with wireless mini keyboards and remotes, I simply set her up with a putty ssh session into the htpc so that she could type jinamp-ctl next.

Party is tonight, so we’ll see how well it goes. Had the thing running all morning without a hitch, but will have to write instructions in case of power failure, or some oik unplugs the htpc, etc…..