You are not logged in.

#276 2009-04-08 12:49:03

rson451
Member
From: Annapolis, MD USA
Registered: 2007-04-15
Posts: 1,233
Website

Re: Post your handy self made command line utilities

b3n wrote:

dmenu application launcher, with your most used applications listed first and you can append a ";" to start the program in a terminal.

Nice and simple.  Very nice.


archlinux - please read this and this — twice — then ask questions.
--
http://rsontech.net | http://github.com/rson

Offline

#277 2009-04-08 13:19:55

Paper Lawyer
Member
Registered: 2008-12-11
Posts: 13

Re: Post your handy self made command line utilities

markp1989 wrote:

this 1 checks the weather from the bbc site, then uses feh to change the wallpaper accordiingly. i have this set to run every hour in cron.

#!/bin/bash
curl http://feeds.bbc.co.uk/weather/feeds/rss/obs/world/0008.xml  >/dev/null 2>&1 > .weatherfeedrs
##Set wallpaper depending on current conditions. 
if grep -qw  rain .weatherfeedrs  ; then 
feh --bg-scale /home/mark/weatherwallpapers/rain.jpg
elif grep -qw cloudy .weatherfeedrs ; then
feh --bg-scale /home/mark/weatherwallpapers/cloudy.jpg
elif grep -qw clear .weatherfeedrs  ; then 
feh --bg-scale /home/mark/weatherwallpapers/clear.jpg
elif grep -qw sunny .weatherfeedrs  ; then 
feh --bg-scale /home/mark/weatherwallpapers/sunny.jpg
else
echo other 
fi

echo `date` `cat .weatherfeedrs | tail -n 13 | head -n 1 |cut -f1 -d'.'` >> ~/weatherhistory

there is probably a lot better way to do this, but this is working for me atm. i have it  keep a list of previous weather stats, so i know what syntax bbc use, so i can update the greps accordingly .

This sounds great - I'll give it a go (and ditch nitrogen).  Thank you.


LXDE installed on an Intel E5200 (oc to 3.25ghz), Gigabyte GA-73PVM-S2 motherboard (GEForce 7100 graphics), 2GB 800mhz RAM & a 320GB WD SATA HD.

Offline

#278 2009-04-09 01:47:23

rson451
Member
From: Annapolis, MD USA
Registered: 2007-04-15
Posts: 1,233
Website

Re: Post your handy self made command line utilities

b3n wrote:

dmenu application launcher, with your most used applications listed first and you can append a ";" to start the program in a terminal.

Thanks for this.  I took out the cache part, but i have a suggestion.  Add $@ behind $DMENU so you can pass it the same options as you would natively.


archlinux - please read this and this — twice — then ask questions.
--
http://rsontech.net | http://github.com/rson

Offline

#279 2009-04-09 10:24:12

b3n
Member
Registered: 2008-11-12
Posts: 20

Re: Post your handy self made command line utilities

rson451 wrote:
b3n wrote:

dmenu application launcher, with your most used applications listed first and you can append a ";" to start the program in a terminal.

Thanks for this.  I took out the cache part, but i have a suggestion.  Add $@ behind $DMENU so you can pass it the same options as you would natively.

#!/bin/sh

TERMI="urxvt -e sh -c"
CACHE="$HOME/.dmenu_cache_recent"

MOST_USED=`sort $CACHE | uniq -c | sort -rn | colrm 1 8`
RUN=`(echo "$MOST_USED"; dmenu_path | grep -vxF "$MOST_USED") | dmenu "$@"` &&
(echo $RUN; head -n 99 $CACHE) > $CACHE.$$ && mv $CACHE.$$ $CACHE
case $RUN in
    *\;) exec $TERMI "$RUN";;
    *) exec $RUN;;
esac

Last edited by b3n (2009-04-10 17:34:31)

Offline

#280 2009-04-10 17:14:53

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: Post your handy self made command line utilities

so i have my custom aurget script in this thread somewhere that just automates wget/tar/pacman -U to quickly get an aur package. 

well, this is a companion script that will check the version of your currently aur-installed packages (pacman -Qm) against the PKGBUILDs' pkgver/pkgrel from aur.archlinux.org. 

it prints a nicely formatted list of your aur packages, green for matching version/release (up to date) and red for mismatches (out of date).

#!/bin/bash
#
# AurCheck V 0.1
#
# pbrisbin 2009
#
# script parses aur.archlinux PKGBUILDs and compares
# it to `pacman -Qm` outputs to find out if you've
# got the latest aur package installed
#
###

# Set up a working directory
WD="/tmp/aurcheck"
[ -d $WD ] || mkdir $WD

# print a header row
echo ""
line="$(echo Package Available Installed | \
  awk '{printf "%-30s %20s %20s\n", $1, $2, $3}')"
echo -e "\e[1;37m$line\e[0m"

# list out foreign packages and check the versions
pacman -Qm | while read pack; do
  name="$(echo $pack | awk '{print $1}')"
  pkgver="$(echo $pack | awk '{print $2}' | cut -d "-" -f 1)"
  pkgrel="$(echo $pack | awk '{print $2}' | cut -d "-" -f 2)"
  URL="http://aur.archlinux.org/packages/${name}/${name}/PKGBUILD"
  wget -q -O $WD/PKGBUILD "$URL"

  pkgverN="$(grep ^pkgver $WD/PKGBUILD | cut -d "=" -f 2 | tr -d '"')"
  pkgrelN="$(grep ^pkgrel $WD/PKGBUILD | cut -d "=" -f 2 | tr -d '"')"
  line="$(echo $name ${pkgverN}-${pkgrelN} ${pkgver}-${pkgrel} | awk '{printf "%-30s %20s %20s\n", $1, $2, $3}')"
  
  if [ "${pkgver}-${pkgrel}" = "${pkgverN}-${pkgrelN}" ]; then
    echo -e "\e[0;32m$line\e[0m"
  else
    echo -e "\e[1;31m$line\e[0m"
  fi
done

echo ""

# cleanup
[ -d $WD ] && rm -rf $WD

exit 0

edit: slight optimization.

Last edited by brisbin33 (2009-04-10 17:21:42)

Offline

#281 2009-04-10 18:46:08

colbert
Member
Registered: 2007-12-16
Posts: 809

Re: Post your handy self made command line utilities

Can someone help me make an alias/script that will check if a partition is mounted, and if not it will mount it and vice versa (if it is mounted, it will unmount it)?? My path is /media/tera. It's an external drive connected via eSata and many automounting solutions haven't worked consistently thus far, and I'd probably rather do it via shell anyhow.

Offline

#282 2009-04-10 18:55:16

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: Post your handy self made command line utilities

colbert wrote:

Can someone help me make an alias/script that will check if a partition is mounted, and if not it will mount it and vice versa (if it is mounted, it will unmount it)?? My path is /media/tera. It's an external drive connected via eSata and many automounting solutions haven't worked consistently thus far, and I'd probably rather do it via shell anyhow.

i have a check like this in my backup scripts.  just make a lock file on the drive (touch /media/tera/.lock). then use this:

#!/bin/bash

DRIVE="/media/tera"

if [ -z $DRIVE/.lock ]; then
  mount $DRIVE
else
  umount $DRIVE
fi

this is if there's an fstab line for it.  being root may be required depending on your setup as well.

Offline

#283 2009-04-10 20:09:03

colbert
Member
Registered: 2007-12-16
Posts: 809

Re: Post your handy self made command line utilities

Thanks a lot brisbin33, that looks awesome. I do have a line for it in fstab (w/noauto). I just tried the script however and it seems to only umount. If the .lock file is there, then it should be unmounted, if it's not there then it should be mounted, no? I tried reversing them and it mounted but then didn't umount. Ack, I'm still a scripting noob so bare with me lol smile

Offline

#284 2009-04-10 20:36:59

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: Post your handy self made command line utilities

no worries, sometimes i have issues wrapping my head around when -z (if does not exist) works or not when it's acting on files ($DRIVE/.lock).  try this version instead:

#!/bin/bash

DRIVE="/media/tera"

if [ -f $DRIVE/.lock ]; then
  umount $DRIVE
else
  mount $DRIVE
fi

Last edited by brisbin33 (2009-04-10 20:37:25)

Offline

#285 2009-04-10 20:49:03

colbert
Member
Registered: 2007-12-16
Posts: 809

Re: Post your handy self made command line utilities

Egg-sealant! smile Works like a charm, thanks a ton big_smile smile

Offline

#286 2009-04-10 22:27:30

rine
Member
From: Germany
Registered: 2008-03-04
Posts: 217

Re: Post your handy self made command line utilities

Why the extra file?

#!/bin/bash

DRIVE="/media/tera"

if mount | grep -q $DRIVE; then
  umount $DRIVE
else
  mount $DRIVE
fi

Offline

#287 2009-04-10 22:38:17

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: Post your handy self made command line utilities

rine wrote:

Why the extra file?

#!/bin/bash

DRIVE="/media/tera"

if mount | grep -q $DRIVE; then
  umount $DRIVE
else
  mount $DRIVE
fi

fair enough.

Offline

#288 2009-04-11 00:05:20

colbert
Member
Registered: 2007-12-16
Posts: 809

Re: Post your handy self made command line utilities

Always many ways to skin a cat huh smile I added it as function to bash, works great dudes.

I am also trying to add a function that uses find for a string, then copies all results to a specified dir. I have this but it's not working:

findcp() {
    find -iname "$1" -exec cp '{}' $2/ \;
}

So I'd like to use it as "find invoices backup/".

Last edited by colbert (2009-04-11 00:06:05)

Offline

#289 2009-04-11 02:50:58

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: Post your handy self made command line utilities

colbert,

1) find needs a directory to look in

2) i don't think you need the "/" after "$2" there

`man find` should help you further.

Offline

#290 2009-04-11 05:16:52

colbert
Member
Registered: 2007-12-16
Posts: 809

Re: Post your handy self made command line utilities

Thanks brisbin33 smile I realized I wasn't telling find where to look, and also the -iname string was missing the asterisks. This works now:

find $1 -iname "*$2*" -exec cp '{}' $3 \;

Now however I am trying to get it to print the results of the files that have been found and copied over, however I tried -print0 and -printf after checking man find but neither worked.

Offline

#291 2009-04-11 23:34:19

Varreon
Member
Registered: 2008-07-03
Posts: 95

Re: Post your handy self made command line utilities

Here's a small script to use on these forums to search for text references. When you search, it'll provide you the forum, but not the page with the keyword. On long threads, this is annoying.

#!/usr/bin/python
# FindPost.py
# Forum Search

import urllib

url = raw_input("Enter url: ");  #like http://bbs.archlinux.org/viewtopic.php?id=[THREADID]&p=
pages = raw_input("How many pages is the thread? ");
user = raw_input("String to search: ");

for i in range(1,int(pages)+1):
    page = urllib.urlopen(url+str(i)).read()
    if(page.find(user)!=-1):
        print url+str(i)

Offline

#292 2009-04-12 09:43:10

halhen
Member
From: Gothenburg, Sweden
Registered: 2009-04-08
Posts: 56
Website

Re: Post your handy self made command line utilities

In my .bashrc - to start a random shoutcast stream, optionally after searching for content.

radio() {
    killall mpg123; shoutcast-search -n 1 -t mpeg -b ">63" --sort=ln10r $* | xargs mpg123 -q -@ &
}

To start a station playing chill:

$ radio chill

See http://bbs.archlinux.org/viewtopic.php?id=69399 or http://code.k2h.se for more info.

Last edited by halhen (2009-04-12 09:57:01)


statnot - status text manager and notification-daemon for dwm, wmii and the like
shic - SHellscript Irc Client

Offline

#293 2009-04-12 12:34:17

Arm-the-Homeless
Member
Registered: 2008-12-22
Posts: 273

Re: Post your handy self made command line utilities

Builds from the ABS. I made it when I started getting into Gentoo. tongue

#!/bin/bash
# Archaeon -- Small ABS Building Script
# By Vithon <ratm@archlinux.us>
if [ "$1" = "" ] ; then
    echo "Archaeon v0.3"
    echo "USAGE:"
    echo "`basename $0` [PACKAGE NAME]"
    echo
    exit 0
fi
ABS_PKG_DIR=`find /var/abs -name "$1"`
ROOT_BUILD_DIR="/tmp/archaeon_build"
PKG_DIR="$ROOT_BUILD_DIR/$1/"
echo "[-] Archaeon starting."
if [ "ABS_PKG_DIR" = "" ] ; then
    echo "[-] ERROR: No packages exist with the name '$1'."
    exit 1
fi
echo "[+] Making build directory..."
mkdir -p "$PKG_DIR"
cd "$PKG_DIR"
echo "[+] Copying files..."
rsync -r "$ABS_PKG_DIR/" "$PKG_DIR/"
echo "[+] Building package..."
makepkg &>build.log
if [ ! -e *.pkg.tar.gz ] ; then
    echo "[-] ERROR: $1 package not built. Check $PKG_DIR/build.log."
    exit 1
fi
echo "[+] Installing $1..."
sudo pacman -U *.pkg.tar.gz &>/dev/null
echo "[+] Cleaning up..."
rm -rf $PKG_DIR
echo "[-] Archaeon finished."

Offline

#294 2009-04-12 12:54:38

markp1989
Member
Registered: 2008-10-05
Posts: 431

Re: Post your handy self made command line utilities

Arm-the-Homeless wrote:

Builds from the ABS. I made it when I started getting into Gentoo. tongue

#!/bin/bash
# Archaeon -- Small ABS Building Script
# By Vithon <ratm@archlinux.us>
if [ "$1" = "" ] ; then
    echo "Archaeon v0.3"
    echo "USAGE:"
    echo "`basename $0` [PACKAGE NAME]"
    echo
    exit 0
fi
ABS_PKG_DIR=`find /var/abs -name "$1"`
ROOT_BUILD_DIR="/tmp/archaeon_build"
PKG_DIR="$ROOT_BUILD_DIR/$1/"
echo "[-] Archaeon starting."
if [ "ABS_PKG_DIR" = "" ] ; then
    echo "[-] ERROR: No packages exist with the name '$1'."
    exit 1
fi
echo "[+] Making build directory..."
mkdir -p "$PKG_DIR"
cd "$PKG_DIR"
echo "[+] Copying files..."
rsync -r "$ABS_PKG_DIR/" "$PKG_DIR/"
echo "[+] Building package..."
makepkg &>build.log
if [ ! -e *.pkg.tar.gz ] ; then
    echo "[-] ERROR: $1 package not built. Check $PKG_DIR/build.log."
    exit 1
fi
echo "[+] Installing $1..."
sudo pacman -U *.pkg.tar.gz &>/dev/null
echo "[+] Cleaning up..."
rm -rf $PKG_DIR
echo "[-] Archaeon finished."

thats cool, thanks for this big_smile


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

#295 2009-04-12 13:25:14

Arm-the-Homeless
Member
Registered: 2008-12-22
Posts: 273

Re: Post your handy self made command line utilities

It's barely a "Thank you" thing. It can only install one app at a time and messes up when something like this happens:

┌─[andy @ vithon]-[9:28:18]
└─[~]-[$]> find /var/abs -name "vim"
/var/abs/local/vim
/var/abs/extra/vim

Offline

#296 2009-04-12 14:16:31

markp1989
Member
Registered: 2008-10-05
Posts: 431

Re: Post your handy self made command line utilities

Wintervenom wrote:

dmenu launcher that displays the friendly names instead of the executable names for applications.

#!/bin/sh
apps='/usr/share/applications'
dmen="dmenu -i -b -fn '-*-terminus-*-r-normal-*-*-120-*-*-*-*-iso8859-*' -nb #000000 -nf #9999CC -sb #000066"
name=$(grep -h "^Name=" $apps/*.desktop | sed 's:Name=::' | $dmen)

if [[ "$name" != "" ]]; then
    dfile=$(grep -l "^Name=$name$" $apps/*.desktop)
    if [[ $(echo "$dfile" | wc -l) > 1 ]]; then
        dfile="$apps/$(echo -e "$dfile" | sed "s:${apps}/::" | $dmen -p "Which $name?")"
    fi
    xdg-open $dfile
fi

Here's another version that combines both friendly and executable names:

#!/bin/sh
apps='/usr/share/applications'
dmen="dmenu -i -b -fn '-*-terminus-*-r-normal-*-*-120-*-*-*-*-iso8859-*' -nb #000000 -nf #9999CC -sb #000066"
name=$(echo -e "$(grep -h "^Name=" $apps/*.desktop | sed 's:Name=::')\n$(dmenu_path)" | $dmen)

if [[ "$name" != "" ]]; then
    dfile=$(grep -l "^Name=$name$" $apps/*.desktop)
    if [ $dfile ]; then
        if [[ $(echo "$dfile" | wc -l) > 1 ]]; then
            dfile="$apps/$(echo -e "$dfile" | sed "s:${apps}/::" | $dmen -p "Which $name?")"
        fi
        xdg-open "$dfile"
    else
        which "$name" &> /dev/null && exec "$name" &
    fi
fi

My shell script skills aren't that clean, so if there's a more efficient way to write those, I'd like to hear the corrections.  tongue

in trying to use the top one , and when i run it i get error saying that xdg-open command not found, what package is this part of ?


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

#297 2009-04-12 14:23:20

marxav
Member
From: Gatineau, PQ, Canada
Registered: 2006-09-24
Posts: 386

Re: Post your handy self made command line utilities

[marst@xeon afc]$ pacman -Qo `which xdg-open`
/usr/bin/xdg-open is owned by xdg-utils 1.0.2-1

Offline

#298 2009-04-12 15:24:43

Daenyth
Forum Fellow
From: Boston, MA
Registered: 2008-02-24
Posts: 1,244

Re: Post your handy self made command line utilities

You should also check out pkgfile, available in community/pkgtools. It can help you find what package owns a file, among other things.

Offline

#299 2009-04-12 19:17:33

madeye
Member
From: Denmark
Registered: 2006-07-19
Posts: 331
Website

Re: Post your handy self made command line utilities

I made this little script to extract and convert the audio from flv videos to mp3, so I can use it in my car CD player.

Maybe something like this already exists, but I took the opportunity to practice a little at bash scripting smile

#! /bin/bash

# ************************************
# ** flv to mp3 converter script    **
# ************************************

# If no filename specified. Print error message and exit
if [ $# != 1 ]
then
  echo Usage: $0 inputfile >&2
  exit 1
fi

# If wrong filetype specified. Print error message and exit
if [[ $1 != *.flv ]]
then
  echo FLV file expected!
  echo Usage: $0 inputfile >&2
  exit 1
fi

# Create variable with filename extension removed
FILNAME=${1%.[^.]*}

# Extract audio from flv file using mplayer (placed in same folder as the original file)
mplayer "$1" -vo null -ao pcm:file="$FILNAME.wav"

# Compress extracted file to mp3 using lame (placed in same folder as original file)
lame --preset standard "$FILNAME.wav" "$FILNAME.mp3"

# Remove wav file
rm "$FILNAME.wav"

MadEye | Registered Linux user #167944 since 2000-02-28 | Homepage

Offline

#300 2009-04-12 20:19:26

jumzi
Member
Registered: 2009-02-20
Posts: 69

Re: Post your handy self made command line utilities

Mine is fucking awsome! (I'm sure someone else must have post this)

while true
do 
mpc | grep - | wmiir create /rbar/mpd
sleep 2 
done

You start it trough ~/mpdScript.sh (if you have saved it to mpdScript.sh in your homefolder) and you close by rebooting(?)

It display the song playing in mpd on the wmii statusbar, omg this is awesome, altough i'll be back with improvement laters wink


EDIT: i had forgotten the "create" after wmiir... fixed now

Last edited by jumzi (2009-04-13 11:29:43)

Offline

Board footer

Powered by FluxBB