You are not logged in.
pacman -Ql only works on packages that are installed.
[git] | [AURpkgs] | [arch-games]
Offline
#!/usr/bin/python
# Author: mr_dot_t
# File: requesticle.py
# Description: Makes a song request to 'siradio.fm'.
import urllib
params = {}
params['in_name'] = raw_input('user:')
params['in_song'] = raw_input('song:')
data = urllib.urlencode(params)
url = 'http://siradio.fm/submit_request.php'
f = urllib.urlopen(url, data)
f.close()
If you're a fan of siradio, then you'll get the name XD
Offline
pacman -Ql only works on packages that are installed.
the use pacman -Qpl
Last edited by goran'agar (2009-12-07 08:24:55)
Sony Vaio VPCM13M1E - Arch Linux - LXDE
Offline
That involves downloading the package from a mirror. It still needs to be on your system... I don't think you get the point here.
[git] | [AURpkgs] | [arch-games]
Offline
#!/usr/bin/python
# chandl.py
# author: Thomas Dziedzic
# description: downloads all pictures on a 4chan board
from HTMLParser import HTMLParser
import urllib
import sys
import os
url = 'http://www.4chan.org/'
board = 'wg'
if len(sys.argv) > 1:
board = sys.argv[1]
path = os.path.join('4chan', board)
if not os.path.exists (path):
os.makedirs(path)
# parse html for boards
boards = {}
f = urllib.urlopen(url)
s = f.read()
f.close()
class BoardParser(HTMLParser):
def handle_starttag(self, tag, attrs):
classTag = [pair for pair in attrs if pair[0] == 'class']
if tag == 'a' and len(classTag) == 1 and classTag[0][1] == 'boardlink':
hrefTag = [pair for pair in attrs if pair[0] == 'href']
titleTag = [pair for pair in attrs if pair[0] == 'title']
href = hrefTag[0][1]
title = titleTag[0][1]
if len(title) > 0:
boards[href.split('/')[-2]] = (title, href)
try:
parser = BoardParser()
parser.feed(s)
parser.close()
except:
# stupid malformed tags
pass
# retrieves html content
f = urllib.urlopen(boards[board][1])
s = f.read()
f.close()
# parse html for board numbers
count = 0
class Parser(HTMLParser):
encouteredBurichan = False
def handle_starttag(self, tag, attrs):
global count
if tag == "a" and self.encouteredBurichan == True:
count += 1
if tag == 'form':
self.encouteredBurichan = False
def handle_data(self, data):
if data == "Burichan":
self.encouteredBurichan = True
parser = Parser()
parser.feed(s)
parser.close()
print '%i pages' % count
# create a list with current pages in board
pages = ['imgboard.html']
for i in range(1, count + 1):
pages.append(str(i) + '.html')
for page in pages:
# retrieve html content
link = boards[board][1].split('imgboard.html')[0] + page
print link
f = urllib.urlopen(link)
s = f.read()
f.close()
class ImageParser(HTMLParser):
skipNext = False #4chan includes 2 consecutive links to the same image.
def handle_starttag(self, tag, attrs):
if tag == "a" and not self.skipNext:
link = attrs[0][1]
filename = link.split('/')[-1]
fileext = filename.split('.')[-1]
if (fileext == 'jpg' or fileext == 'png' or fileext == 'gif') and not os.path.exists(os.path.join(path, filename)):
f = urllib.urlopen(link)
print link
s = f.read()
f.close()
f = open(os.path.join(path, filename), 'wb')
f.write(s)
f.close()
self.skipNext = True
else:
self.skipNext = False
parser = ImageParser()
parser.feed(s)
parser.close()
Updated: Added ability to download png and gif files
Offline
Found out about kdm-theme-generator and and ksplash-theme-generator that create themes based on your current desktop. Created this script to do everything at once.
#!/bin/bash
# kde-login-themes - create KDM and Ksplash themes based on current theme
user=todd
userdir=/home/$user
kdmgendir="$userdir/.kde4/share/apps/kdm/themes/MyKdmTheme/"
kdmrootdir="/usr/share/apps/kdm/themes/"
# Text color variables
txtbld=$(tput bold) # Bold
bldred=${txtbld}$(tput setaf 1) # red
bldwht=${txtbld}$(tput setaf 7) # white
txtrst=$(tput sgr0) # Reset
info=${bldwht}*${txtrst} # Feedback
warn=${bldred}!${txtrst}
# Must be root
if [ $(whoami) != root ]; then
echo "$warn Need to be root"
exit
fi
echo "$info Generating KDM Theme"
su $user -c "KdmThemeGenerator"
echo "$info Generating Ksplash Theme"
su $user -c "KsplashThemeGenerator"
echo "$info Copying KDM theme to root filesystem"
[ -d $kdmrootdir/MyKdmTheme ] && rm -r $kdmrootdir/MyKdmTheme/
mv $kdmgendir $kdmrootdir
echo
echo "$info KDM theme (as regular user):"
echo "kdesu systemsettings"
echo "$info Advanced tab > Login Manager > Theme tab"
echo "$info Ksplash:"
echo "$info System Settings > Appearance > Splash Screen"
Last edited by Gen2ly (2009-12-08 15:55:11)
Setting Up a Scripting Environment | Proud donor to wikipedia - link
Offline
lame but very handy for printing out plain text files
lptxt ()
{
lp -o page-bottom=72 -o page-top=72 -o page-left=72 -o page-right=72 $1
}
I just threw this in my .bashrc and now can print pretty text documents easily.
it may not be long and fancy, but it sure comes in handy!
and I'm currently working on a backup script that
1.) checks to see if my external hard-drive is mounted
2.) if it isn't, tries to mount it and save the backup to the backup directory
3.) if mounting fails, save the backup locally (because why throw out a perfectly good back-up)
4.) and next time the script is run AND the hard-drive is mounted, move all local backups to the hard-drive where they belong.
I should be finished with it by this weekend if I have time.
Last edited by Cyrusm (2009-12-18 20:24:55)
Hofstadter's Law:
It always takes longer than you expect, even when you take into account Hofstadter's Law.
Offline
actually, that was a lot easier than I thought! still have some details to work out but here is is
#!/bin/bash
#########################################
# Title: backup_script.sh #
# Author: Cyrus Metcalf #
# Last Mod: 18Dec2009 #
#########################################
FILE=backup`date +%m%d%y`.tgz
DIR=/home/cyrus
TARGETDIR=/home/cyrus/.backups
echo "Testing for external hard drive"
cat /proc/mounts | grep /media/xhd2 > /dev/null
if [ $? -eq 0 ] ; then
echo "External hard drive found"
TARGETDIR=/media/xhd2/backups
mv /home/cyrus/.backups/backup*.tgz $TARGETDIR
echo "Moved local backups to disk."
else
echo "No external drive found, attempting to mount...."
mount /media/xhd2
if [ $? -eq 0 ]; then
echo "Drive mounted"
TARGETDIR=/media/xhd2/backups
mv /home/cyrus/.backups/backup*.tgz $TARGETDIR
echo "Moved local backups to disk."
else
echo "Mount failed, saving backup locally."
fi
fi
echo "Commencing backup of config files"
tar cfz $TARGETDIR/$FILE \
/etc \
/var/lib/pacman/local \
$DIR/.bashrc \
$DIR/.xinitrc \
$DIR/.xmonad \
$DIR/.vimrc \
$DIR/.Xmodmap \
$DIR/.Xdefaults
if [ $? -eq 0 ]
then
echo "Backup Complete"
else
echo "BACKUP FAILED!"
fi
I'm still working to make it a little more elegant, but this works well.
Hofstadter's Law:
It always takes longer than you expect, even when you take into account Hofstadter's Law.
Offline
bash alias to post status to Twitter:
function twit() {
curl -s -u username:password -d "status=$*" http://twitter.com/statuses/update.xml >/dev/null
}
Offline
i wrote this for the prank thread on ubuntu forums:
#!/bin/bash
##Specify delays in seconds between events.
maxdelay=100
mindelay=1
wordlist=wordlist.txt
for i in `seq 1 100`;
do
word1=$(sort -R "$wordlist" | head -n 1)
word2=$(sort -R "$wordlist" | head -n 1)
sleeptime=$(seq $mindelay $maxdelay| sort -R | head -n 1)
xmessage $word1 $word2!!!!!! &
echo $sleeptime ##just in during testing, not needed.
sleep $sleeptime
done
you will need a word list, i have 1 if any one wants the wordlist then message me and i will email u it.
what it does is choses 2 words the dictionary list, puts them in an error message using xmessage, then waits a random amount of time i set the max to 100 sec, you can change that in the sleeptime variable at the the top , then it does another message with 2 more random words.
i will only do it 100 times each run. be nive with it.
i attached a screnie for you lot to see lol.
http://i246.photobucket.com/albums/gg10 … shot-5.png
best messages i have seen so far running my self are "Warhead Insomniac!" and "dampening asshole!"
doesnt really server a purpose, but it is amusing.
Desktop: E8400@4ghz - DFI Lanparty JR P45-T2RS - 4gb ddr2 800 - 30gb OCZ Vertex - Geforce 8800 GTS - 2*19" LCD
Server/Media Zotac GeForce 9300-ITX I-E - E5200 - 4gb Ram - 2* ecogreen F2 1.5tb - 1* wd green 500gb - PicoPSU 150xt - rtorrent - xbmc - ipazzport remote - 42" LCD
Offline
i attached a screnie for you lot to see lol.
That screenie is proof alone that Ubuntu's destiny is to become windows.
Offline
not much of a command line utility, it's just a menu entry in midnight commander to set a picture as desktop backgroud if you are not using a DE & are dependent upon external progs for setting wallpapers.
= t r
+ ! t t
b Set as desktop background
feh --bg-scale %f
put the above code in .mc/menu file.
if it's not present then edit it from mc's menu.
now whenever you hit F2 this menu entry will be there
Last edited by vik_k (2009-12-21 07:55:58)
"First learn computer science and all the theory. Next develop a programming style. Then forget all that and just hack." ~ George Carrette
Offline
When coding I often have a couple of websites open relating to the code I'm working on. The first thing I do when starting work on that code is open those web pages in firefox. I wanted a way to associate certain web pages with a project so came up with this tonight. I create a file called .bookmarks in the project folder containing a listing of URLs pertaining to that project. At the moment I am working with sqlite so my .bookmarks file for that project looks like:
http://www.sqlite.org/
http://docs.python.org/library/sqlite3.html
I have a function in my .bashrc:
function bm {
if [ -e .bookmarks ]
then
for URL in $(cat .bookmarks )
do
firefox $URL
done
fi
}
Now I simply enter the project directory, execute bm and my bookmarks open in firefox.
This is not a substitute for bookmarks as the bookmarks in this system can be scattered all over your home directory but for reference websites I think it will work for me. YMMV.
Offline
When coding I often have a couple of websites open relating to the code I'm working on. The first thing I do when starting work on that code is open those web pages in firefox. I wanted a way to associate certain web pages with a project so came up with this tonight. I create a file called .bookmarks in the project folder containing a listing of URLs pertaining to that project.
Smart idea! I'm stealing it
EDIT: I'm going to add some functionality to this as well to add and delete bookmarks w/o having to open the file:
bmadd ()
{
if [ -e .bookmarks ] ; then
echo "$1" >> .bookmarks
else
echo ".bookmarks file not found"
fi
}
bmrm ()
{
if[ -e .bookmarks ] ; then
cat .bookmarks | sed -e '/'$1'/d' > tmp
mv tmp .bookmarks
else
echo ".bookmarks file not found"
fi
}
these are just prototypes, I haven;t tested them out for functionality yet.
Last edited by Cyrusm (2009-12-21 22:44:50)
Hofstadter's Law:
It always takes longer than you expect, even when you take into account Hofstadter's Law.
Offline
cat .bookmarks | sed -e '/'$1'/d' > tmp
mv tmp .bookmarks
You can edit the file in place with the -i switch:
sed -i "/${1//\//\/}/d" .bookmarks
Last edited by lolilolicon (2009-12-22 08:47:07)
This silver ladybug at line 28...
Offline
Here's a small C utility that outputs "URGENT" if there are any windows with the urgent flag set. Useful for conky and such similar things. It's mostly based on "lsw" from suckless.org. (Yes, the license is as long as the code, but that was the easiest was to comply with arg's license.)
/*
* MIT/X Consortium License
*
* (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
* (C)opyright MMIX Ray Kohler <ataraxia937 at gmail dot com>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
static Display *dpy;
static Window root;
int main() {
unsigned int i, num;
Window *wins, d1, d2;
XWindowAttributes wa;
XWMHints *wmh;
if(!(dpy = XOpenDisplay(0))) {
exit(EXIT_FAILURE);
}
root = RootWindow(dpy, DefaultScreen(dpy));
if(XQueryTree(dpy, root, &d1, &d2, &wins, &num)) {
for(i = 0; i < num; i++) {
if(!XGetWindowAttributes(dpy, wins[i], &wa))
continue;
if(wa.override_redirect)
continue;
if(!(wmh = XGetWMHints(dpy, wins[i])))
exit(EXIT_FAILURE);
if(wmh->flags & XUrgencyHint) {
puts("URGENT");
exit(EXIT_SUCCESS);
}
}
}
if(wins)
XFree(wins);
XCloseDisplay(dpy);
return 0;
}
Offline
One of the custom BASH functions I source in my ~/.bashrc; this one quickly opens files for editing in either CLI or GUI (by passing the -g option):
function edit() {
# preferred editors
ED_CLI="nano"
ED_GUI="geany"
if [ -z ${2} ]; then
EDITOR=${ED_CLI} && FILE=${1} && SUCMD="sudo"
else
case ${1} in
'-g') EDITOR=${ED_GUI} && FILE=${2} && SUCMD="gksudo" ;;
*) echo "Unknown option '${1}'" ;;
esac
fi
case ${FILE} in
'fstab') ${SUCMD} ${EDITOR} /etc/fstab ;;
'xorg') ${SUCMD} ${EDITOR} /etc/X11/xorg.conf ;;
'grub') ${SUCMD} ${EDITOR} /boot/grub/grub.cfg ;;
'inittab') ${SUCMD} ${EDITOR} /etc/inittab ;;
'rc.conf') ${SUCMD} ${EDITOR} /etc/rc.conf ;;
'bashrc') ${EDITOR} ~/.bashrc ;;
'conky') ${EDITOR} ~/.conkyrc ;;
'uploads') ${EDITOR} ~/.uploads ;;
'downloads') ${EDITOR} ~/.downloads ;;
'mybashrc') ${EDITOR} /mnt/storage/scripts/mybashrc.sh ;;
*) echo "Unknown file '${FILE}'" ;;
esac
}
EDITED to fix an error.
Last edited by munkyeetr (2009-12-25 02:04:02)
If the advice you're given in this forum solves your issue, please mark the post as [SOLVED] in consideration to others.
"More than any time in history mankind faces a crossroads. One path leads to despair and utter hopelessness, the other to total extinction.
Let us pray that we have the wisdom to choose correctly." -- Woody Allen
Offline
Getting the same colours in the tty framebuffer as in X (tested with xterm, is supposed to work with u\?rxvt too):
#!/bin/bash
for line in $(sed -n "/color/s/.*\*color\([0-9]\{1,2\}\).*#\([0-9A-Fa-f]\)/P\1 \2/;T;s/P1\([0-9]\)/P\1/;Tf;y/012345/abcdef/;:f;s/\(P.\) \(......\)/\\\e]\1\2/;p" ~/.Xdefaults); do echo -en $line; done; clear
I need a sorted list of all random numbers, so that I can retrieve a suitable one later with a binary search instead of having to iterate through the generation process every time.
Offline
An aur helper function based on one f brisbin33's:
function aur {
if (( $# != 1 ))
then
echo "usage: aur <package>"
return
fi
local PKGDIR=$HOME/pkgs
local FILENAME=$1.tar.gz
cd $PKGDIR && rm -f $FILENAME
echo -n "Downloading $FILENAME ... "
wget -q http://aur.archlinux.org/packages/$1/$FILENAME
if (( $? ))
then
echo "[FAIL]"
return
fi
echo "[DONE]"
tar xzf $FILENAME
cd $1
ls -lh
}
It is still a little rough around the edges. I plan to improve it a bit yet.
Offline
An easy device management with hal.
To use it you have to allow sending commands via dbus to volumes to any user..
/etc/dbus-1/system.d/hal.conf:
<policy context="default">
...
<allow send_destination="org.freedesktop.Hal"
send_interface="org.freedesktop.Hal.Device.Volume"/>
...
</policy>
And those scripts:
hal-storage-mount.sh:
#!/bin/sh
#
# Ask Hal to mount device udi passed as first argument, using current user as owner of the device
#
UDI=$1
dbus-send --system --print-reply --dest=org.freedesktop.Hal $UDI org.freedesktop.Hal.Device.Volume.Mount string: string: array:string:uid=`id -u`
hal-storage-unmount.sh
#!/bin/sh
#
# Ask Hal to umount device udi passed as first argument
#
UDI=$1
dbus-send --system --print-reply --dest=org.freedesktop.Hal $UDI org.freedesktop.Hal.Device.Volume.Unmount array:string:
hal-storage-eject
#!/bin/sh
#
# Ask hal to eject device udi passed as first argument
#
UDI=$1
dbus-send --system --print-reply --dest=org.freedesktop.Hal $UDI org.freedesktop.Hal.Device.Volume.Eject array:string:
I'am actually going to distribute those with traydevice, but there are still some people not using that:). And there might be other use cases where this one-liners could do nicely.
Offline
#!/usr/bin/env bash
#
# uptime-check.sh
# Check uptime and mail if uptime is less than it was when script last ran
# http://linux-101.org
#
HOSTNAME=$(hostname)
HDRFROM="From: Uptime Script <devnull@domain.tld>"
HDRTO="To: Sysadmin <alerts@domain.tld>"
HDRSUBJ="Subject: $HOSTNAME has been rebooted"
ENVELTO="alerts@domain.tld" #Match above HDRTO
PWD=$(pwd)
DATE=$(date '+%Y%m%d%H%M%S')
DATAFILE=$PWD/uptime-check.data
UPTIMENEW=$(gawk -F . '{ print $1 }' /proc/uptime)
UPTIMEOLD=$(gawk -F : '{ print $2 }' $DATAFILE)
if [ "$UPTIMENEW" -lt $UPTIMEOLD ] ; then
TMPFILE=/tmp/uptime.tmp
touch $TMPFILE
echo $HDRFROM >> $TMPFILE
echo $HDRTO >> $TMPFILE
echo $HDRSUBJ >> $TMPFILE
echo "uptime | ps aux | netstat -nap" >> $TMPFILE
echo " " >> $TMPFILE
$(uptime >> $TMPFILE)
echo "
" >> $TMPFILE
$(ps aux >> $TMPFILE)
echo "
" >> $TMPFILE
$(netstat -nap >> $TMPFILE)
echo "
" >> $TMPFILE
echo "." >> $TMPFILE
echo "
" >> $TMPFILE
cat $TMPFILE | sendmail "$ENVELTO"
rm -f $TMPFILE
echo "$DATE:$UPTIMENEW" > $DATAFILE
else
echo "$DATE:$UPTIMENEW" > $DATAFILE
fi
EDIT1: Runs on a cronjob every minute.
Last edited by _AA_ (2009-12-27 23:39:47)
Offline
A friend has a completely hosed install (massive filesystem corruption), so I whipped up a short script to reinstall everything for him. I expanded it a little…
#!/bin/zsh
fixmirrors=false
sanitycheck=false
updatefirst=false
fixpacman=false
for arg in "${*[@]}"; do
case $arg in
"-m")
fixmirrors=true;;
"-s")
sanitycheck=true;;
"-u")
updatefirst=true;;
"-p")
fixpacman=true;;
esac
done
if $fixpacman; then
echo "Manually reinstalling pacman..."
wget ftp://ftp.archlinux.org/core/os/`uname -m`/core.db.tar.gz -O /tmp/core.db.tar.gz
pacmanver=`tar tzf /tmp/core.db.tar.gz | grep pacman | head -n1 | sed "s/\///"`
wget ftp://ftp.archlinux.org/core/os/`uname -m`/$pacmanver-`uname -m`.pkg.tar.gz -O /tmp/pacman.pkg.tar.gz
sudo tar xvfz /tmp/pacman.pkg.tar.gz /
sudo pacman -Sy pacman
fi
echo "Generating package lists..."
pacman -Qqe > /tmp/packages1
pacman -Qqem > /tmp/packages2
pacman -Qqd > /tmp/packages3
pacman -Qqdm > /tmp/packages4
while read line; do
sed -i "/$line/d" /tmp/packages1
done < /tmp/packages2
while read line; do
sed -i "/$line/d" /tmp/packages3
done < /tmp/packages4
if $fixmirrors; then
sudo rm -f /etc/pacman.d/mirrorlist
sudo echo "Server = ftp://ftp.archlinux.org/\$repo/os/`uname -m`" > /etc/pacman.d/mirrorlist
fi
if $sanitycheck; then
EDITOR=`[[ $EDITOR == "" ]] && echo "vim" || echo $EDITOR` # As much as I dislike it, vim *is* the one editor guaranteed to be everywhere...
$EDITOR /tmp/packages1
$EDITOR /tmp/packages2
$EDITOR /tmp/packages3
$EDITOR /tmp/packages4
fi
sudo pacman -Syy
if $updatefirst; then
pacman -Suf
fi
sudo pacman -Sf `cat /tmp/packages1`
sudo pacman -Sf --asdeps `cat /tmp/packages3`
yaourt -Sf `cat /tmp/packages2`
yaourt -Sf --asdeps `cat /tmp/packages4`
Last edited by Barrucadu (2009-12-28 00:40:20)
Offline
Post deleted.
Last edited by Wintervenom (2009-12-30 03:18:55)
Offline
barrudacu, "man comm". You can cut out those fugly sed blocks.
[git] | [AURpkgs] | [arch-games]
Offline