You are not logged in.

#126 2008-12-11 18:41:31

initbox
Member
Registered: 2008-09-27
Posts: 168

Re: Post your handy self made command line utilities

pamhhaabg.jpg

#!/bin/bash
printf '********************\n';
printf 'SYSTEM STATUS:\n \n';
printf 'OS: '; uname -sr | awk '{print $1,$2}';
printf 'Platform: '; uname -m;
printf 'Time: '; date +'%H:%M:%S (%d/%m/%Y)';
printf 'Uptime: '; uptime | awk '{print $3,$4,$5}';
printf 'IP '; ifconfig eth0 | grep 'inet addr:' | awk '{print $2}';
printf 'Hostname: '; uname -n;
printf '\n********************\n';
printf 'SYSTEM USAGE:\n \n';
printf 'Load: '; uptime | awk '{print $10,$11,$12}';
printf 'Memory: '; free -m | grep 'cache:' | awk '{print $3,"mb used,",$4,"mb free"}'; 
printf 'Tasks: '; ps -A | wc -l;
printf '\n********************\n';
printf 'HARDWARE:\n \n';
printf 'CPU: '; cat /proc/cpuinfo | grep 'model name' | head -1;
printf 'Cores/Processors: '; cat /proc/cpuinfo | grep processor | tail -1 | awk '{print $3+1}';
printf 'RAM: '; free -m | grep Mem: | awk '{print $2,"mb"}';
printf '********************\n';

Heh, I just wanted to make a simple script that gives as much information about the running system as possible. Too bad I can't figure out any more non-system specific commands for even more info.

Offline

#127 2008-12-11 18:57:03

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

Re: Post your handy self made command line utilities

I cleaned your script for you.

#!/bin/bash
IFACE=eth0

OS=$(uname -sr)
ARCH=$(uname -m)
CURTIME=$(date +'%H:%M:%S (%d/%m/%Y)')
UPTIME=$(uptime | awk '{print $3,$4,$5}')
LOCALIP=$(ifconfig $IFACE | awk '/inet addr:/ {print $2}')
HOSTNAME=$(uname -n)
LOAD=$(uptime | awk '{print $10,$11,$12}')
MEM=$(free -m | awk '/cache:/ {print $s,"mb used,",$4,"mb free"}')
PROCS=$(ps -A | wc -l)
CPUMODEL=$(grep -m1 'model name' /proc/cpuinfo)
CPUS=$(grep -c processor: /proc/cpuinfo)
TOTALRAM=$(free -m | awk '/Mem:/ {print $2,"mb"}')

CAT << _EOM
********************
SYSTEM STATUS:

OS: $OS
Platform: $ARCH
Time: $CURTIME
Uptime: $UPTIME
IP: $LOCALIP
Hostname: $HOSTNAME

********************
SYSTEM USAGE:

Load: $LOAD
Memory: $MEM
Tasks: $PROCS

********************
HARDWARE:

CPU: $CPUMODEL
Cores/Processors: $CPUS
RAM: $TOTALRAM
'********************
_EOM

Offline

#128 2008-12-11 19:03:16

initbox
Member
Registered: 2008-09-27
Posts: 168

Re: Post your handy self made command line utilities

Daenyth wrote:

I cleaned your script for you.

yikes thanks, I wasn't trying to do anything fancy and I was mainly practicising with awk and whatnot..

I wonder if there would be decent commands to find out everything about the hardware, but I figured that there isn't any command that has portable output...

Offline

#129 2008-12-11 22:45:49

ijanos
Member
From: Budapest, Hungary
Registered: 2008-03-30
Posts: 434

Re: Post your handy self made command line utilities

Check a website every 5 minutes and warn if something changed.
Waiting for exam results is so much fun with this script smile
Depends on figlet and cowsay!

#!/bin/bash

URL='http://someurlcomes.here'
MSG='Moooo'

wget $URL -O /tmp/original

while true;do
    wget $URL -O /tmp/new
    diff -i -b -B -q /tmp/original /tmp/new
    if [ ! $? -eq 0 ]; then
        figlet $MSG|cowsay -n|xmessage -file - -center
        exit
    fi
    sleep 300
done

Offline

#130 2008-12-13 10:16:48

dusanx
Member
Registered: 2008-11-28
Posts: 132

Re: Post your handy self made command line utilities

Openbox pipe menu, mplayer radio and the monkey...

I am using mplayer to listen to the radio stations, don't want anything heavy and no visible player (well except one optional conky line).

radiomeny.py:

#!/usr/bin/env python

import os, sys, fnmatch, fileinput, re

class radiolist:

    def get_list(self):
        radio_list=[]
        filepath=os.path.split( os.path.realpath( sys.argv[0] ) )[0] + "/playlist.txt"
        for line in fileinput.input(filepath):
            patt = re.compile(r'(.+)\|')
            radio = patt.search(line).group(1)
            patt = re.compile(r'\|(.+)')
            url = patt.search(line).group(1)
            radio_list.append([radio,url])
           
        return radio_list

    def __init__(self):
        radiolist = self.get_list()
        print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
        print "<openbox_pipe_menu>"
        for name,url in radiolist:
            print " <item label=\"%s\">" % name
            print "  <action name=\"Execute\"><execute>%s</execute></action>" % ("~/.scripts/radio/radioexec.sh " + name + " " + url)
            print " </item>"

        print " <separator />"
        print " <item label=\"%s\">" % "Stop radio"
        print "  <action name=\"Execute\"><execute>%s</execute></action>" % ("~/.scripts/radio/radioexec.sh " + "---")
        print " </item>"
        print "</openbox_pipe_menu>"

if __name__=="__main__":
    app = radiolist()

radioexec.sh:

# /bin/bash

pkill mplayer
echo "$1" > ~/.scripts/radio/radiolog.txt
if [ -n "$2" ]; then
    mplayer "$2"
fi

playlist.txt:

Absolute|http://network.absoluteradio.co.uk/core/audio/mp3/live.pls?service=vrbb
Magic|http://earth.radica.com/magic1054-70
Kerrang|http://earth.radica.com/kerrang-70

All three files are in my ~/.scripts/radio dir.

Add pipe menu somewhere in openbox menu.xml:

<menu execute="~/.scripts/radio/radiomenu.py" id="ID" label="Radio"/>

Add optional conky info line to see what are you playing and current volume:

Radio: ${alignr}${execi 1 cat ~/.scripts/radio/radiolog.txt} ${execi 5 amixer sget PCM,0 |grep "Front Left:"|cut -d "[" -f2|cut -d "%" -f1}%

...and the monkey?

There is no monkey, I just enjoy Lucas Arts Monkey Island adventures smile
Can you imagine that one month ago I was using Ubuntu and did no scripting at all???


Gnome -> Openbox -> Awesome -> XMonad -> dwm .
http://github.com/dusanx/uzbl/

Offline

#131 2008-12-14 06:46:16

GraveyardPC
Member
Registered: 2008-11-29
Posts: 99

Re: Post your handy self made command line utilities

Here's a two for one. First this is a simple update script I made for Arch.

#!/bin/bash
# Arch Update

# Colors
blue="\033[1;34m"
green="\033[1;32m"
red="\033[1;31m"
bold="\033[1;37m"
reset="\033[0m"

# Check for root
if [ $(whoami) != "root" ]; then
    echo -e $red"error:$reset you cannot perform this operation unless you are root."
    exit 1
fi

# Update
echo -e "$blue::$bold Syncing ABS...$reset"
abs > /dev/null
pacman-color -Syy
pacman-color -Su
echo -e "$blue::$bold Updating mlocate database...$reset"
updatedb
echo -e "$green::$bold System update complete.$reset"
exit 0

Looks like this:
screenshotgu2.png

_____________________________________________________________________________

Now, this is something I actually put time into. It uses EncFS to mount an encrypted volume in a temporary manner. It will prompt for a password and then open the destination folder with nautilus. However, when you close the browser window it automatically unmounts. Since I don't ever logoff my desktop this is a better method of accessing an encrypted drive/folder...for me at least.

Main script "encmnt":

#!/usr/bin/python
# EncMnt v1.0 (EncFS Mounting System)
# GraveyardPC - 2008

# Usage:
# ./encmnt <root_dir> <mount_dir>
#
# Note:
# All directory paths must be absolute.

# Required:
# "wmctrl," "xwininfo," "encfs" and "fusermount"

import sys, time, os, subprocess
try:
     import pygtk
      pygtk.require("2.0")
except:
      pass
try:
    import gtk
      import gtk.glade
except:
    sys.exit(1)

Popen    = subprocess.Popen
PIPE    = subprocess.PIPE
path    = os.path.dirname(sys.argv[0])
app    = os.path.abspath(sys.argv[0])

def windowList():
    wlist = []
    ret = Popen(["wmctrl", "-l"], stdout=PIPE).stdout
    for line in ret:
        wlist.append(line.split()[0])
    return wlist

if len(sys.argv) == 3:
    root    = str(sys.argv[1])
    mount    = str(sys.argv[2])

    # Unmount any existing volume at the same location:
    Popen(["fusermount", "-uz", mount])

    # Mount new archive using password prompt (exit on failure):
    ret = Popen(["encfs", "--extpass=" + app, root, mount], stdout=PIPE).stdout
    if ret.readline(): sys.exit(1)

    # Grab previous window list:
    pre_wlist = windowList()

    # Launch file browser window:
    Popen(["nautilus", mount])
    time.sleep(1.5)

    # Grab post window list:
    pst_wlist = windowList()

    # Locate file browser window:
    wid = False
    for pst_id in pst_wlist:
        new = True
        for pre_id in pre_wlist:
            if pst_id == pre_id: new = False
        if new:
            wid = pst_id
            break

    # Block while window is active:
    if wid:
        active = True
        while active:
            time.sleep(2)
            ret = Popen(["xwininfo", "-id", wid], stdout=PIPE, stderr=PIPE).stderr
            if ret.readline(): active = False

    # Unmount current archive:
    Popen(["fusermount", "-uz", mount])
    exit()

# Password Prompt
class EncMountGTK:
    def __init__(self):
        self.gladefile    = path + "/encmnt.glade" 
            self.wTree    = gtk.glade.XML(self.gladefile)
        self.password    = self.wTree.get_widget("password")

        dic = { "on_password_activate"    : self.output,
            "on_decrypt"        : self.output,
            "on_cancel"        : gtk.main_quit,
            "on_window_destroy"    : gtk.main_quit }
        self.wTree.signal_autoconnect(dic)

    def output(self, widget):
        key = self.password.get_text()
        if key:
            print key
            gtk.main_quit()

if __name__ == "__main__":
    hwg = EncMountGTK()
    gtk.main()

"encmnt.glade":

<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">

<glade-interface>

<widget class="GtkWindow" id="window">
  <property name="width_request">345</property>
  <property name="height_request">102</property>
  <property name="visible">True</property>
  <property name="title" translatable="yes"></property>
  <property name="type">GTK_WINDOW_TOPLEVEL</property>
  <property name="window_position">GTK_WIN_POS_CENTER</property>
  <property name="modal">False</property>
  <property name="resizable">False</property>
  <property name="destroy_with_parent">False</property>
  <property name="icon_name"></property>
  <property name="decorated">True</property>
  <property name="skip_taskbar_hint">True</property>
  <property name="skip_pager_hint">True</property>
  <property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
  <property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
  <property name="focus_on_map">True</property>
  <property name="urgency_hint">True</property>
  <signal name="destroy" handler="on_window_destroy" last_modification_time="Sun, 28 Sep 2008 17:36:55 GMT"/>

  <child>
    <widget class="GtkVBox" id="container">
      <property name="border_width">6</property>
      <property name="visible">True</property>
      <property name="homogeneous">False</property>
      <property name="spacing">8</property>

      <child>
    <widget class="GtkLabel" id="title">
      <property name="visible">True</property>
      <property name="label" translatable="yes"><span font_desc="16"><b>Restricted Access</b></span>
This volume is encrypted, a passkey is required to proceed.</property>
      <property name="use_underline">False</property>
      <property name="use_markup">True</property>
      <property name="justify">GTK_JUSTIFY_LEFT</property>
      <property name="wrap">False</property>
      <property name="selectable">False</property>
      <property name="xalign">0.5</property>
      <property name="yalign">0.5</property>
      <property name="xpad">0</property>
      <property name="ypad">0</property>
      <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
      <property name="width_chars">-1</property>
      <property name="single_line_mode">False</property>
      <property name="angle">0</property>
    </widget>
    <packing>
      <property name="padding">0</property>
      <property name="expand">False</property>
      <property name="fill">False</property>
    </packing>
      </child>

      <child>
    <widget class="GtkHBox" id="entrybox">
      <property name="height_request">15</property>
      <property name="visible">True</property>
      <property name="homogeneous">False</property>
      <property name="spacing">8</property>

      <child>
        <widget class="GtkImage" id="icon2">
          <property name="visible">True</property>
          <property name="stock">gtk-dialog-authentication</property>
          <property name="icon_size">1</property>
          <property name="xalign">0.5</property>
          <property name="yalign">0.5</property>
          <property name="xpad">0</property>
          <property name="ypad">0</property>
        </widget>
        <packing>
          <property name="padding">0</property>
          <property name="expand">False</property>
          <property name="fill">False</property>
        </packing>
      </child>

      <child>
        <widget class="GtkEntry" id="password">
          <property name="visible">True</property>
          <property name="can_focus">True</property>
          <property name="editable">True</property>
          <property name="visibility">False</property>
          <property name="max_length">0</property>
          <property name="text" translatable="yes"></property>
          <property name="has_frame">False</property>
          <property name="invisible_char">●</property>
          <property name="activates_default">False</property>
          <signal name="activate" handler="on_password_activate" last_modification_time="Sun, 28 Sep 2008 18:55:05 GMT"/>
        </widget>
        <packing>
          <property name="padding">0</property>
          <property name="expand">True</property>
          <property name="fill">True</property>
        </packing>
      </child>
    </widget>
    <packing>
      <property name="padding">0</property>
      <property name="expand">True</property>
      <property name="fill">True</property>
    </packing>
      </child>

      <child>
    <widget class="GtkHBox" id="controlbox">
      <property name="visible">True</property>
      <property name="homogeneous">False</property>
      <property name="spacing">4</property>

      <child>
        <widget class="GtkLabel" id="spacer">
          <property name="width_request">175</property>
          <property name="visible">True</property>
          <property name="label" translatable="yes"></property>
          <property name="use_underline">False</property>
          <property name="use_markup">False</property>
          <property name="justify">GTK_JUSTIFY_LEFT</property>
          <property name="wrap">False</property>
          <property name="selectable">False</property>
          <property name="xalign">0</property>
          <property name="yalign">0</property>
          <property name="xpad">0</property>
          <property name="ypad">0</property>
          <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
          <property name="width_chars">-1</property>
          <property name="single_line_mode">False</property>
          <property name="angle">0</property>
        </widget>
        <packing>
          <property name="padding">0</property>
          <property name="expand">False</property>
          <property name="fill">False</property>
        </packing>
      </child>

      <child>
        <widget class="GtkButton" id="cancel">
          <property name="width_request">75</property>
          <property name="visible">True</property>
          <property name="can_focus">True</property>
          <property name="relief">GTK_RELIEF_NORMAL</property>
          <property name="focus_on_click">True</property>
          <signal name="clicked" handler="on_cancel" last_modification_time="Mon, 29 Sep 2008 17:44:23 GMT"/>

          <child>
        <widget class="GtkAlignment" id="alignment2">
          <property name="visible">True</property>
          <property name="xalign">0.5</property>
          <property name="yalign">0.5</property>
          <property name="xscale">0</property>
          <property name="yscale">0</property>
          <property name="top_padding">0</property>
          <property name="bottom_padding">0</property>
          <property name="left_padding">0</property>
          <property name="right_padding">0</property>

          <child>
            <widget class="GtkHBox" id="hbox3">
              <property name="visible">True</property>
              <property name="homogeneous">False</property>
              <property name="spacing">2</property>

              <child>
            <widget class="GtkImage" id="image2">
              <property name="visible">True</property>
              <property name="stock">gtk-remove</property>
              <property name="icon_size">4</property>
              <property name="xalign">0.5</property>
              <property name="yalign">0.5</property>
              <property name="xpad">0</property>
              <property name="ypad">0</property>
            </widget>
            <packing>
              <property name="padding">0</property>
              <property name="expand">False</property>
              <property name="fill">False</property>
            </packing>
              </child>

              <child>
            <widget class="GtkLabel" id="label8">
              <property name="visible">True</property>
              <property name="label">_Cancel</property>
              <property name="use_underline">True</property>
              <property name="use_markup">False</property>
              <property name="justify">GTK_JUSTIFY_LEFT</property>
              <property name="wrap">False</property>
              <property name="selectable">False</property>
              <property name="xalign">0.5</property>
              <property name="yalign">0.5</property>
              <property name="xpad">0</property>
              <property name="ypad">0</property>
              <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
              <property name="width_chars">-1</property>
              <property name="single_line_mode">False</property>
              <property name="angle">0</property>
            </widget>
            <packing>
              <property name="padding">0</property>
              <property name="expand">False</property>
              <property name="fill">False</property>
            </packing>
              </child>
            </widget>
          </child>
        </widget>
          </child>
        </widget>
        <packing>
          <property name="padding">0</property>
          <property name="expand">False</property>
          <property name="fill">False</property>
        </packing>
      </child>

      <child>
        <widget class="GtkButton" id="decrypt">
          <property name="width_request">75</property>
          <property name="visible">True</property>
          <property name="can_focus">True</property>
          <property name="relief">GTK_RELIEF_NORMAL</property>
          <property name="focus_on_click">False</property>
          <signal name="clicked" handler="on_decrypt" last_modification_time="Mon, 29 Sep 2008 17:44:08 GMT"/>

          <child>
        <widget class="GtkAlignment" id="alignment1">
          <property name="visible">True</property>
          <property name="xalign">0.5</property>
          <property name="yalign">0.5</property>
          <property name="xscale">0</property>
          <property name="yscale">0</property>
          <property name="top_padding">0</property>
          <property name="bottom_padding">0</property>
          <property name="left_padding">0</property>
          <property name="right_padding">0</property>

          <child>
            <widget class="GtkHBox" id="hbox2">
              <property name="visible">True</property>
              <property name="homogeneous">False</property>
              <property name="spacing">2</property>

              <child>
            <widget class="GtkImage" id="image1">
              <property name="visible">True</property>
              <property name="stock">gtk-dnd-multiple</property>
              <property name="icon_size">4</property>
              <property name="xalign">0.5</property>
              <property name="yalign">0.5</property>
              <property name="xpad">0</property>
              <property name="ypad">0</property>
            </widget>
            <packing>
              <property name="padding">0</property>
              <property name="expand">False</property>
              <property name="fill">False</property>
            </packing>
              </child>

              <child>
            <widget class="GtkLabel" id="label7">
              <property name="visible">True</property>
              <property name="label">_Decrypt</property>
              <property name="use_underline">True</property>
              <property name="use_markup">False</property>
              <property name="justify">GTK_JUSTIFY_LEFT</property>
              <property name="wrap">False</property>
              <property name="selectable">False</property>
              <property name="xalign">0.5</property>
              <property name="yalign">0.5</property>
              <property name="xpad">0</property>
              <property name="ypad">0</property>
              <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
              <property name="width_chars">-1</property>
              <property name="single_line_mode">False</property>
              <property name="angle">0</property>
            </widget>
            <packing>
              <property name="padding">0</property>
              <property name="expand">False</property>
              <property name="fill">False</property>
            </packing>
              </child>
            </widget>
          </child>
        </widget>
          </child>
        </widget>
        <packing>
          <property name="padding">0</property>
          <property name="expand">False</property>
          <property name="fill">False</property>
        </packing>
      </child>
    </widget>
    <packing>
      <property name="padding">0</property>
      <property name="expand">True</property>
      <property name="fill">True</property>
    </packing>
      </child>
    </widget>
  </child>
</widget>

</glade-interface>

Last edited by GraveyardPC (2008-12-14 07:11:28)

Offline

#132 2008-12-14 09:21:01

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

Re: Post your handy self made command line utilities

Why does your update script do a -Syy instead of just -Sy?

Offline

#133 2008-12-14 09:53:34

GraveyardPC
Member
Registered: 2008-11-29
Posts: 99

Re: Post your handy self made command line utilities

Daenyth wrote:

Why does your update script do a -Syy instead of just -Sy?

Using the double "y" forces a refresh of the package list instead of just checking if it's up-to-date. I use that because I discovered that sometimes with certain repositories the list registers as up-to-date when it really isn't. And since that caused problems for me, I just force it as a safety precaution.

Last edited by GraveyardPC (2008-12-14 09:54:03)

Offline

#134 2008-12-14 09:56:03

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

Re: Post your handy self made command line utilities

I'd use another mirror then, and report a bug for that one. It shouldn't happen often enough to make you use that each time.

Offline

#135 2008-12-14 10:06:20

GraveyardPC
Member
Registered: 2008-11-29
Posts: 99

Re: Post your handy self made command line utilities

I did recently switch mirrors because I was getting issues using "mirror.neotuli.net." But I rather leave the script alone just in case it happens again randomly, and it's not like it adds that much of delay anyway. Besides, I only use the command about once daily. And as far as reporting it as a bug, it seems to be an issue originating at various repositories, not pacman itself. So I don't see the point in reporting every incident.

Last edited by GraveyardPC (2008-12-14 10:07:12)

Offline

#136 2008-12-19 22:30:04

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

Re: Post your handy self made command line utilities

Bump

Offline

#137 2008-12-20 15:03:28

keenerd
Trusted User (TU)
Registered: 2007-02-22
Posts: 647
Website

Re: Post your handy self made command line utilities

I used to be a big time conky-monitor junkie.  Monitors were nice, because I could tell when something was going wrong.  Now they are just distracting during normal operation.  I'll also use the command line more, and I needed a cross CLI/X11 monitor system that would only bother me if something was really wrong.

Throw this into a 5 minute cron job and never worry about OOM, OOHD, dead battery or thermal meltdown.

#! /bin/bash

# System monitor and alert thing.
# Run in a cron job.

# Checks the following:
#     is battery about to die?
#     is ram almost gone?
#     is hd almost gone?
#     is cpu going to melt?

# Makes several alerts:
#     make a noise
#     wall
#     popup
#     wm integration (awesome wm needs a textbox called tb_status)

# configure these globals for trip points
Mem_Lim=95  # percent used
Bat_Lim=15  # minutes remaining 
Drv_Lim=95  # percent used
Tmp_Lim=65  # degrees C

# globals for error logging
Mem_Err=0
Bat_Err=0
Drv_Err=0
Tmp_Err=0

function percent_mem () # None : Int
{
    mem_vals=`free | grep 'Mem: ' | sed 's/.*: *\([0-9]\+\) \+\([0-9]*\).*/\1 \2/'`
    mem_tot=`echo $mem_vals | cut -f1 -d" "`
    #mem_use=`echo $mem_vals | cut -f2 -d" "`
    mem_use=`free | grep 'buffers/cache:' | sed 's/.*: *\([0-9]\+\) .*/\1/'`
    pmem=`echo "100*$mem_use / $mem_tot" | bc`
    echo $pmem
}

function percent_root () # None : Int
{
    root_vals=`df | grep '/$' | sed 's/[ ][ ]*/ /g'`
    root_free=`echo $root_vals | cut -f5 -d" " | sed 's/%//g'`
    echo $root_free
}

function on_battery () # None : Bool
{
    if grep -q "discharging" /proc/acpi/battery/BAT1/state; then
        echo "1"
    else
        echo "0"
    fi
}

function battery_time () # None : Int
{
    bat_rate=`grep 'rate:' /proc/acpi/battery/BAT1/state | sed 's/[ ][ ]*/ /g' | cut -f3 -d" "`
    bat_cap=`grep 'capacity:' /proc/acpi/battery/BAT1/state | sed 's/[ ][ ]*/ /g' | cut -f3 -d" "`
    tbat=`echo "60*$bat_cap / $bat_rate" | bc`
    echo $tbat
}

function temperature () # None : Int
{
    thrm_vals=`sed 's/[ ][ ]*/ /g' /proc/acpi/thermal_zone/THRM/temperature`
    thrm_temp=`echo $thrm_vals | cut -f2 -d" "`
    echo $thrm_temp
}

function inspect_world () # None : None
{
    if [ "$(on_battery)" == "1" ]; then
        if [ $(battery_time) -lt "$Bat_Lim" ]; then
            Bat_Err=1
        fi
    fi

    if [ $(percent_mem) -gt "$Mem_Lim" ]; then
        Mem_Err=1
    fi

    if [ $(percent_root) -gt "$Drv_Lim" ]; then
        Drv_Err=1
    fi

    if [ $(temperature) -gt "$Tmp_Lim" ]; then
        Tmp_Err=1
    fi
}

function report ()
{
    status=""
        
    if [ "$Bat_Err" == "1" ]; then
        status="${status}Running out of battery!   "
    fi
    
    if [ "$Mem_Err" == "1" ]; then
        status="${status}Running out of RAM!   "
    fi
    
    if [ "$Drv_Err" == "1" ]; then
        status="${status}Running out of disk!   "
    fi
    
    if [ "$Tmp_Err" == "1" ]; then
        status="${status}CPU on fire!   "
    fi

    #echo 0 widget_tell mystatusbar tb_status text "" | awesome-client  # old awesome
    echo tb_status.text = "\"\"" | awesome-client  # new awesome
    if [ "$status" ]; then
        status="   ${status}"
        wall "$status"
        # xosd
        # xdialog
        #echo 1 widget_tell mystatusbar tb_status text "$status" | awesome-client  # old awesome
        echo tb_status.text = "\"$status\"" | awesome-client  # new awesome
    fi
    
    # higher rate of testing on error, so we know when emergency is over
    if [ "$status" ]; then
        #echo "recursing"
        sleep 30
        ./$0 &
    fi
}

inspect_world
report

Offline

#138 2008-12-22 19:34:03

dante4d
Member
From: Czech Republic
Registered: 2007-04-14
Posts: 167
Website

Re: Post your handy self made command line utilities

Wifi script that beats all network managers tongue

#!/bin/bash
set -x
killall dhcpcd
sleep 1
rmmod iwl3945
sleep 1
modprobe iwl3945
sleep 1
ifconfig wlan0 up
sleep 1
while [[ ! -z "`iwconfig wlan0 | grep Quality:0`" ]]; do
    iwconfig wlan0 essid linksys key <wep key>
    sleep 3
done
dhcpcd wlan0
set +x

Last edited by dante4d (2008-12-22 19:34:37)

Offline

#139 2008-12-27 04:58:27

dmz
Member
Registered: 2008-08-27
Posts: 866
Website

Re: Post your handy self made command line utilities

Copies the currently playing song in MPD to the specified location (my mounted mp3-player).

mvmpd

TARGET=/mnt/mp3/MUSIC
MUSIC_DIR=/mnt/Music
MPD_PATH=$(mpc --format '[[%file%]]'|head -1)

cp $MUSIC_DIR/$MPD_PATH $TARGET
echo '.: '$MUSIC_DIR/$MPD_PATH '-->' $TARGET

Offline

#140 2008-12-27 05:11:08

Wintervenom
Member
From: /home/wintervenom
Registered: 2008-08-20
Posts: 1,011
Website

Re: Post your handy self made command line utilities

Downloads all CoolText fonts:

#!/bin/sh
wget -O fonts.htm http://cooltext.com/Fonts-All &&
egrep -i '<a[ ^I]+href[ ^I]*=[ ^I]*"?[^">]*"?.*>' fonts.htm |
sed -e 's|.*<[aA][ ^I][ ^I]*[hH][rR][eE][fF][ ^I]*=[ ^I]*"*\([^">][^">]*\)"*[^>]*>.*|http\:\/\/cooltext.com\/\1|g' |
egrep -i "(.zip|.ttf)" "$@" > fonts.txt

if ! [ -e fonts-tmp ]; then mkdir fonts-tmp; fi

cd fonts-tmp
wget -i ../fonts.txt
unzip \*.zip
rm *.zip
cd ..

if ! [ -e fonts ]; then mkdir fonts; fi

find fonts-tmp -iname "*.ttf" -exec cp --no-preserve=mode,ownership "{}" fonts \;
chmod a-x -R fonts
rm -rf fonts-tmp

cd fonts
for f in *.TTF; do mv $f `basename $f .TTF`.ttf; done
cd ..

echo "Done."

Removes duplicate songs in import directory that are already in music library:

#!/bin/bash

LIBRARY="$HOME/Media/Music/Library"
DL_DIR="$HOME/Media/Music/New Music"

echo "Searching for and deleting*"
echo "- Copies of songs in the import folder..."
find "$DL_DIR" -iname "* (*).mp3" -type f |
while read x; do
    if [[ "$x" != "${x/ ([0-9])/}" ]]; then
        mv "$x" "${x/ ([0-9])/}"
    fi
done

echo "- Copies of songs you've already have..."
uniq -d  <(find "$LIBRARY" "$DL_DIR" -type f | sed "s*^$LIBRARY**" | sed "s*^$DL_DIR**" | sort) | sed "s*^/*$DL_DIR/*" | while read x; do rm "$x"; done

for (( x=0; x<2; x++ )); do
    echo "- Empty folders..."
    find "$LIBRARY" "$DL_DIR" -type d -empty -print0 | xargs -0 rmdir &> /dev/null
done

#fdupes -qr "$LIBRARY" "$DL_DIR" | grep "$DL_DIR" | while read x; do rm "$x" &> /dev/null; done
echo "Done."

Podget notifier (it needs more work):

#!/bin/bash

DONE_LOG="$HOME/.podget/logs/done"
FAIL_LOG="$HOME/.podget/logs/errors"

while file=$(basename "$(head -n1 $DONE_LOG)") && [[ $file != "" ]]; do
    notify-send -t 6000 "Recent Podget:  $file"
    sed -i 1d $DONE_LOG
    sleep 1
done
    
while file=$(basename "$(head -n1 $FAIL_LOG)") && [[ $file != "" ]]; do
    notify-send -u critical -t 6000 "Failed Podget:  $file"
    head -n1 $FAIL_LOG >> "$FAIL_LOG.old"
    sed -i 1d $FAIL_LOG
    sleep 1
done

Firefox SafeSession:

#!/bin/sh

TMPFF="/dev/shm/ffss"
FFDIR="$HOME/.mozilla/firefox"
TMPIMG="pxf0rig3.SafeSession"

if ! [ -d $TMPFF/$TMPIMG ]; then
  notify-send "Firefox Safesession" "Creating new session..."
  mkdir $TMPFF
  cp -a $FFDIR/$TMPIMG $TMPFF
else
  notify-send "Firefox Safesession" "Continuing current session..."
fi

if [ -f $FFDIR/profiles.ini.orig ]; then
  rm -f $FFDIR/profiles.ini
  mv $FFDIR/profiles.ini.orig $FFDIR/profiles.ini
fi

mv $FFDIR/profiles.ini $FFDIR/profiles.ini.orig
echo "[Profile0]
Name=default
IsRelative=0
Path=$TMPFF/$TMPIMG
Default=1
" >> $FFDIR/profiles.ini

TZ=UTC firefox -no-remote

rm -f $FFDIR/profiles.ini
mv $FFDIR/profiles.ini.orig $FFDIR/profiles.ini

notify-send "Firefox Safesession" "Deleting session..."
rm -rf $TMPFF
notify-send "Firefox Safesession" "Done."

My [GitHub] and my [artwork].
Data is guaranteed to stay crunchy in milk.
Keep your _✍ hand strong.

Offline

#141 2008-12-28 13:14:43

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

Re: Post your handy self made command line utilities

Downloads all (or updates) your collection of XKCD:

import urllib
import sys, re
import os.path

recent_location_re = re.compile ('Permanent link to this comic: http://xkcd.com/([^<]*)/')
jpg_location_re = re.compile ('\(for hotlinking/embedding\): ([^<]*)</h3>')

def opt ():
    print'#     Welcome to XKMD'
    print'# The XKCD Mass Downloader'
    print'#'
    print'# -m Mass Downloader (In order for -u to work you must run this first)'
    print'# -u Update Your XKCD Collection'
    print'# -g Grab a Specific Comic'
    print'# -o Brings up Options List'
    print'# -q Quit XKMD'
    print'#'
    print''
    
    cmd = raw_input('xkmd: ')

    while 1:
        if cmd == '-q':
            break
        elif cmd == '-o':
            opt()
        elif cmd == '-m':
            mass()
            cmd = raw_input('xkmd: ')
        elif cmd == '-u':
            update()
            cmd = raw_input('xkmd: ')
        elif cmd == '-g':
            grab()
            cmd = raw_input('xkmd: ')
        else:
            print'Invalid Command'
            cmd = raw_input('xkmd: ')
    

#Downloads Every XKCD in existance
def mass ():
        print'XKMD Mass Downloader Function'
        comfirm = raw_input('Would you like to populate your /xkcd/ folder (y/n): ')
        if comfirm == 'y':
            xkcdNum = 0
            downloadControl(xkcdNum)
            print 'Your /xkcd/ Folder Has Been Filled with every XKCD Comic'
        
def update ():
    print'XKMD Update Function'
    comfirm = raw_input('Would you like to update your collection (y/n): ')
    if comfirm == 'y':
        cDir = os.getcwd()
        updFile = open(cDir + '/update', 'r')
        lastDown = updFile.read()
        updFile.close()
        downloadControl(int(lastDown))
        print 'Your /xkcd/ Folder Has Been Updated'

def grab ():
    print'XKMD Grab Function'
    xkcdNum = input('Enter XKCD comic number to download: ')
    download(xkcdNum)
    print 'Comic ' + str(xkcdNum) + ' Has Been Downloaded'

def downloadControl (self):
        xkcdMax = urllib.urlopen('http://www.xkcd.com')
        xkcdMaxNum = xkcdMax.read()
        xkcdMax.close()
        recent = recent_location_re.search(xkcdMaxNum)
        maxNum = int(recent.group(1))
        cDir = os.getcwd()
        updFile = open(cDir + '/update', 'w')
        updFile.write(str(maxNum))
        updFile.close()
        print 'Update File Updated ;)'
        while self < maxNum:
            self = self + 1
            download (self)
            

def download (self):
            if self == 404:
                self = 405
            xkcdStr = str(self)
            xkcdUrl = 'http://www.xkcd.com/' + xkcdStr + '/'
            print xkcdUrl
            url = urllib.urlopen(xkcdUrl)
            urlC = url.read()
            url.close()
            jpg = jpg_location_re.search(urlC)
             print jpg.group(1)
                        exten = os.path.splitext(jpg.group(1))[1]
            title = 'XKCD' + xkcdStr + exten
            cDir = os.getcwd()
            DLLoc = cDir + '/xkcd/' + title
            urllib.urlretrieve(jpg.group(1), DLLoc)
            urllib.urlcleanup()

opt()

Offline

#142 2009-01-01 23:40:11

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: Post your handy self made command line utilities

Convert romaji to kana.
lowercase -> hiragana, uppercase -> katakana
Katakana we/wi/we/wo have doubles, I'm not really sure what to do about that. The tables are from wikipedia.

Example: cd `kana USAGI`

#!/bin/dash
echo $* |
sed '
s_\([ctpbkszhgd]\)\1_っ\1_g
s_\([CTPBKSZHGD]\)\1_ッ\1_g
s_pyo_ぴょ_g
s_pyu_ぴゅ_g
s_pya_ぴゃ_g
s_byo_びょ_g
s_byu_びゅ_g
s_bya_びゃ_g
s_gyo_ぎょ_g
s_gyu_ぎゅ_g
s_gya_ぎゃ_g
s_ryo_りょ_g
s_ryu_りゅ_g
s_rya_りゃ_g
s_myo_みょ_g
s_myu_みゅ_g
s_mya_みゃ_g
s_hyo_ひょ_g
s_hyu_ひゅ_g
s_hya_ひゃ_g
s_nyo_にょ_g
s_nyu_にゅ_g
s_nya_にゃ_g
s_cho_ちょ_g
s_chu_ちゅ_g
s_cha_ちゃ_g
s_tsu_つ_g
s_chi_ち_g
s_sho_しょ_g
s_shu_しゅ_g
s_sha_しゃ_g
s_shi_し_g
s_kyo_きょ_g
s_kyu_きゅ_g
s_kya_きゃ_g
s_dzu_づ_g
s_dji_ぢ_g
s_ka_か_g
s_ki_き_g
s_ku_く_g
s_ke_け_g
s_ko_こ_g
s_sa_さ_g
s_su_す_g
s_se_せ_g
s_so_そ_g
s_ta_た_g
s_te_て_g
s_to_と_g
s_na_な_g
s_ni_に_g
s_nu_ぬ_g
s_ne_ね_g
s_no_の_g
s_ha_は_g
s_hi_ひ_g
s_fu_ふ_g
s_he_へ_g
s_ho_ほ_g
s_ma_ま_g
s_mi_み_g
s_mu_む_g
s_me_め_g
s_mo_も_g
s_[rl]a_ら_g
s_[rl]i_り_g
s_[rl]u_る_g
s_[rl]e_れ_g
s_[rl]o_ろ_g
s_wa_わ_g
s_wi_ゐ_g
s_we_ゑ_g
s_wo_を_g
s_ga_が_g
s_gi_ぎ_g
s_gu_ぐ_g
s_ge_げ_g
s_go_ご_g
s_za_ざ_g
s_ji_じ_g
s_zu_ず_g
s_ze_ぜ_g
s_zo_ぞ_g
s_ja_じゃ_g
s_ju_じゅ_g
s_jo_じょ_g
s_da_だ_g
s_de_で_g
s_do_ど_g
s_ba_ば_g
s_bi_び_g
s_bu_ぶ_g
s_be_べ_g
s_bo_ぼ_g
s_pa_ぱ_g
s_pi_ぴ_g
s_pu_ぷ_g
s_pe_ぺ_g
s_po_ぽ_g
s_ya_や_g
s_yu_ゆ_g
s_yo_よ_g
s_a_あ_g
s_i_い_g
s_u_う_g
s_e_え_g
s_o_お_g
s_n_ん_g
#KATAKANA
s_GWO_グォ_g
s_GWE_グェ_g
s_GWU_グゥ_g
s_GWI_グィ_g
s_GWA_グァ_g
s_KWO_クォ_g
s_KWE_クェ_g
s_KWU_クゥ_g
s_KWI_クィ_g
s_KWA_クァ_g
s_WYO_ウョ_g
s_WYU_ウュ_g
s_WYA_ウャ_g
s_RYE_リェ_g
s_FYO_フョ_g
s_FYU_フュ_g
s_FYA_フャ_g
s_TSO_ツォ_g
s_TSE_ツェ_g
s_TSI_ツィ_g
s_TSA_ツァ_g
s_DYO_デョ_g
s_DYU_デュ_g
s_DYA_デャ_g
s_TYO_テョ_g
s_TYU_テュ_g
s_TYA_テャ_g
s_ZYO_ズョ_g
s_ZYU_ズュ_g
s_ZYA_ズャ_g
s_SYO_スョ_g
s_SYU_スュ_g
s_SYA_スャ_g
s_CHE_チェ_g
s_SHE_シェ_g
s_VYO_ヴョ_g
s_VYU_ヴュ_g
s_VYA_ヴャ_g
s_PYO_ピョ_g
s_PYU_ピュ_g
s_PYA_ピャ_g
s_BYO_ビョ_g
s_BYU_ビュ_g
s_BYA_ビャ_g
s_GYO_ギョ_g
s_GYU_ギュ_g
s_GYA_ギャ_g
s_WYO_ヰョ_g
s_WYU_ヰュ_g
s_WYA_ヰャ_g
s_RYO_リョ_g
s_RYU_リュ_g
s_RYA_リャ_g
s_MYO_ミョ_g
s_MYU_ミュ_g
s_MYA_ミャ_g
s_HYO_ヒョ_g
s_HYU_ヒュ_g
s_HYA_ヒャ_g
s_NYO_ニョ_g
s_NYU_ニュ_g
s_NYA_ニャ_g
s_CHO_チョ_g
s_CHU_チュ_g
s_CHA_チャ_g
s_TSU_ツ_g
s_CHI_チ_g
s_SHO_ショ_g
s_SHU_シュ_g
s_SHA_シャ_g
s_SHI_シ_g
s_KYO_キョ_g
s_KYU_キュ_g
s_KYA_キャ_g
s_DZU_ヅ_g
s_DJI_ヂ_g
s_KA_カ_g
s_KI_キ_g
s_KU_ク_g
s_KE_ケ_g
s_KO_コ_g
s_SA_サ_g
s_SU_ス_g
s_SE_セ_g
s_SO_ソ_g
s_TA_タ_g
s_TE_テ_g
s_TO_ト_g
s_NA_ナ_g
s_NI_ニ_g
s_NU_ヌ_g
s_NE_ネ_g
s_NO_ノ_g
s_HA_ハ_g
s_HI_ヒ_g
s_FU_フ_g
s_HE_ヘ_g
s_HO_ホ_g
s_MA_マ_g
s_MI_ミ_g
s_MU_ム_g
s_ME_メ_g
s_MO_モ_g
s_[RL]A_ラ_g
s_[RL]I_リ_g
s_[RL]U_ル_g
s_[RL]E_レ_g
s_[RL]O_ロ_g
s_WA_ワ_g
s_WI_ヰ_g
s_WE_ヱ_g
s_WO_ヲ_g
s_GA_ガ_g
s_GI_ギ_g
s_GU_グ_g
s_GE_ゲ_g
s_GO_ゴ_g
s_ZA_ザ_g
s_JI_ジ_g
s_ZU_ズ_g
s_ZE_ゼ_g
s_ZO_ゾ_g
s_JA_ジャ_g
s_JU_ジュ_g
s_JO_ジョ_g
s_DA_ダ_g
s_DE_デ_g
s_DO_ド_g
s_BA_バ_g
s_BI_ビ_g
s_BU_ブ_g
s_BE_ベ_g
s_BO_ボ_g
s_PA_パ_g
s_PI_ピ_g
s_PU_プ_g
s_PE_ペ_g
s_PO_ポ_g
s_YE_イェ_g
s_VA_ヴァ_g
s_VI_ヴィ_g
s_VU_ヴ_g
s_VE_ヴェ_g
s_VO_ヴォ_g
s_JE_ジェ_g
s_SI_スィ_g
s_ZI_ズィ_g
s_TI_ティ_g
s_TU_トゥ_g
s_DI_ディ_g
s_DU_ドゥ_g
s_FA_ファ_g
s_FI_フィ_g
s_HU_ホゥ_g
s_FE_フェ_g
s_FO_フォ_g
s_YA_ヤ_g
s_YU_ユ_g
s_YO_ヨ_g
s_WA_ウァ_g
s_WI_ウィ_g
s_WE_ウェ_g
s_WO_ウォ_g
s_A_ア_g
s_I_イ_g
s_U_ウ_g
s_E_エ_g
s_O_オ_g
s_N_ン_g
s_-_ー_g
s_'\''__g'

Offline

#143 2009-01-02 00:06:37

Bionic Apple
Member
Registered: 2008-08-05
Posts: 59

Re: Post your handy self made command line utilities

#!/bin/bash
#
# Thread Search: Finds a word in a forum thread and outputs thread page
# Note: As of now, it just searches Arch Linux threads

if [[ $# != 3 ]]; then
    echo "Usage: thsrch [REG EXPR] [THREAD BASE URL (without &p=...)] [NUM OF PAGES]" 1>&2
    exit 1
fi

regExpr="$1"
baseUrl="$2"
numOfPages=$3
pageNum=1

while [ $pageNum -le $numOfPages ]
    do
        echo -n "Page $pageNum has "
        numOfMatches=$(
            wget -qO - "${baseUrl}&p=$pageNum" |
            gawk '/<div class="postmsg">/ , /<\/div>/' |
            grep -c "$regExpr"
            )
        echo "$numOfMatches occurences."
        ((pageNum++))
    done

This was mainly just a test of my general Bash abilities, as I tend to remember things better through doing, not reading.  If I actually put much thought into it, it wouldn't need the number of pages.

Offline

#144 2009-01-02 00:23:44

skottish
Forum Fellow
From: Here
Registered: 2006-06-16
Posts: 7,931

Re: Post your handy self made command line utilities

Daenyth wrote:

Bump

Stickied.

Offline

#145 2009-01-02 04:44:36

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

Re: Post your handy self made command line utilities

Sweet big_smile

Offline

#146 2009-01-05 19:58:35

jelly
Trusted User (TU)
From: /dev/null
Registered: 2008-06-10
Posts: 711

Re: Post your handy self made command line utilities

The following script isn't made by me, but i want to promote it. If you download series from eztv.it . There is a handy python script pytvshows in AUR. That downloads new *.torrent files of new episodes of your favoriete series. Let your torrent client watch that directory and add a cron job and you are done smile .  I love scripts! Yesterday i found this nice bash backup script on this forum witch i customized to my own setup (original form rine)

I added one rule for this script, so that it first checks if my pc can connect to my NAS. This is great for my laptop wich isn't always at my home:P

if ping -c 1 -w 10.0.0.102 > /dev/null ; then
   echo "could not connect to server"
   exit 1

@arm-the-homeless
I get this error when running your script:

[jelle@p6 test]$ python test.py
  File "test.py", line 94
    print jpg.group(1)
    ^
IndentationError: unexpected indent

Last edited by jelly (2009-01-05 20:05:13)

Offline

#147 2009-01-05 22:33:26

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

Re: Post your handy self made command line utilities

Oh. Try running

mkdir xkcd

tongue

Offline

#148 2009-01-15 00:03:18

Killa B
Member
From: United States
Registered: 2008-10-28
Posts: 42
Website

Re: Post your handy self made command line utilities

Arm-the-Homeless wrote:

Oh. Try running

mkdir xkcd

tongue

You probably also have to remove the unexpected indent.:P There's one on the next line, too.

lamerip
This is a script to rip a CD to WAV, then convert to MP3. I'm pretty sure I wrote this one myself, but it was a couple months ago, so I'm not entirely sure I didn't steal it from somewhere. <_<

#!/bin/bash

# Bitrate, in kbps
br=320

# Rip from CD to *.wav format
cdparanoia -B

# Convert to *.mp3 format
for fname in $(ls *.cdda.wav)
do
    lame -b $br $fname ${fname}.mp3
done

# Clean up *.wav's
rm *.cdda.wav

Afterwards I use easytag to fill the ID3 tags and rename the files. I've yet to find a really decent way to do it.

mpdstream
Sets up mpd to stream to my PSP. Bash gives me a terrible headache sometimes, so I did it in Python, even though it seems silly. The file "mpdstream.diff" is the diff between my config file with icecast enabled and disabled. The PHP interface is pretty sweet, too, but a lot of its code is borrowed from someone else.

#!/usr/bin/env python

import sys
import os

if len(sys.argv) > 1:
    if sys.argv[1] == "on":
        os.system("/etc/rc.d/mpd stop")
        os.system("patch /etc/mpd.conf /usr/local/share/mpdstream/mpdstream.diff")
        os.system("/etc/rc.d/icecast start")
        os.system("/etc/rc.d/mpd start")

    elif sys.argv[1] == "off":
        os.system("/etc/rc.d/icecast stop")
        os.system("/etc/rc.d/mpd stop")
        os.system("patch -R /etc/mpd.conf /usr/local/share/mpdstream/mpdstream.diff")
        os.system("/etc/rc.d/mpd start")

    else:
        print "Possible arguments are `on` or `off`."
else:
    print "Possible arguments are `on` or `off`."

I have another utility that's pretty neat, but it was late when I was writing it, and I was frustrated with both bash and python, so I wrote it in C. I'll rewrite it sometime, though.

Edit:
Well, I just rewrote that utility I was talking about in Python.

imageconv
Uses GIMP to convert images between different formats. It's absurdly slow for some reason, but it gets the job done.

#!/usr/bin/env python

import os
import sys

if len(sys.argv) == 3:
    command = "gimp -d -i -b \"(script-fu-readwrite \\\""
    command += sys.argv[1] +"\\\" \\\"" + sys.argv[2] + "\\\")\" -b \"(gimp-quit 0)\""

    print command
    print sys.argv[1]
    print sys.argv[2]
    os.system(command)
else:
    print "Usage: imageconv <old file> <new file>"

script-fu-readwrite.scm
Scheme makes me want to regurgitate. This is the actual script that the script runs through GIMP.

(define (script-fu-readwrite filename-in filename-out)
    (let* ((image     (car (gimp-file-load RUN-NONINTERACTIVE filename-in "")))
            (drawable (car (gimp-image-active-drawable image)))
    )

        (gimp-file-save    RUN-NONINTERACTIVE image drawable filename-out "")
    )
)

Edit II:

bzip2me
Tells me when my files are done being bzip2'd. This is extremely useful for me. Since my tiny 80GB hard drive is always full, I'm always compressing things. This script should help me to stop checking if the compression is done every five seconds.

#!/bin/bash

NUMFILES=`ls -1 . | wc -l`

bzip2 "$1" &

while [ $NUMFILES -ne `ls -1 . | wc -l` ]
do
        sleep 10
done

zenity --info --text "Done bzipping \"$1\"."

Last edited by Killa B (2009-01-21 02:39:32)

Offline

#149 2009-01-24 18:27:15

fwojciec
Member
Registered: 2007-05-20
Posts: 1,411

Re: Post your handy self made command line utilities

Normally when I need to update the md5sums in a PKGBUILD I need to edit it with a text editor, remove the old md5sums array, and then regenerate md5sums with makepkg -g.  I wrote a simple script that does all this automatically:

#!/bin/sh

if [ ! -f ./PKGBUILD ]; then
    echo No PKGBUILD in `pwd`
    exit 1
fi

sed -i "/^.*'[a-z0-9]\{32\}'.*$/d" PKGBUILD
makepkg -g >> PKGBUILD

Offline

#150 2009-01-26 08:03:09

u_no_hu
Member
Registered: 2008-06-15
Posts: 453

Re: Post your handy self made command line utilities

Stick it in your .xinitrc and you can pick which ever window manager you want when you login... especially if you use autologin from inittab and like using lots of windowmanagers.  Really simple but i find it very useful. you can type the first letter to choose the wm.

#! /bin/bash

PROGRAM=$(zenity --width=0\
           --height=0\
           --list\
           --title "SelectWm"\
            --text "Select Window manager"\
            --column ""\
            "openbox"\
            "pekwm"\
            "fusion-icon"\
            "ion3"\
            "ratpoison"\
            "wmii"\
            "fvwm-crystal"\
            "startxfce4"\
            "awesome"\
                )


case $PROGRAM in 
    (openbox) 
         exec   openbox-session;;
    (pekwm) 
         exec   pekwm;;
    (fusion-icon) 
         exec   fusion-icon;;
    (ion3) 
         exec   ion3;;
    (ratpoison) 
         exec   ratpoison;;
    (wmii) 
         exec   wmii;;
    (fvwm-crystal) 
         exec   fvwm-crystal;;
    (startxfce4) 
         exec   startxfce4;;
    (awesome) 
         exec   awesome ;;
esac

PS Needs zenity


Don't be a HELP VAMPIRE. Please search before you ask.

Subscribe to The Arch Daily News.

Offline

Board footer

Powered by FluxBB