You are not logged in.

#726 2009-12-06 23:38:02

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

Re: Post your handy self made command line utilities

pacman -Ql only works on packages that are installed.

Offline

#727 2009-12-07 01:13:21

tomd123
Developer
Registered: 2008-08-12
Posts: 565

Re: Post your handy self made command line utilities

#!/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

#728 2009-12-07 08:24:37

goran'agar
Member
From: Nothern Italy
Registered: 2009-05-19
Posts: 167

Re: Post your handy self made command line utilities

Daenyth wrote:

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 - ZFS - Syslinux - XFCE .
Samsung SGS - CM10.1 - Semaphore 2.8.0 .

Offline

#729 2009-12-07 12:09:40

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

Re: Post your handy self made command line utilities

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.

Offline

#730 2009-12-08 05:29:50

tomd123
Developer
Registered: 2008-08-12
Posts: 565

Re: Post your handy self made command line utilities

#!/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 smile

Offline

#731 2009-12-08 15:52:00

Gen2ly
Member
From: Sevierville, TN
Registered: 2009-03-06
Posts: 1,529
Website

Re: Post your handy self made command line utilities

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

#732 2009-12-18 20:16:25

Cyrusm
Member
From: Bozeman, MT
Registered: 2007-11-15
Posts: 1,052

Re: Post your handy self made command line utilities

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

#733 2009-12-18 22:39:30

Cyrusm
Member
From: Bozeman, MT
Registered: 2007-11-15
Posts: 1,052

Re: Post your handy self made command line utilities

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

#734 2009-12-18 22:45:28

jdarnold
Member
From: Medford MA USA
Registered: 2009-12-15
Posts: 462
Website

Re: Post your handy self made command line utilities

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

#735 2009-12-19 00:01:49

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

Re: Post your handy self made command line utilities

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

#736 2009-12-20 23:16:07

tomd123
Developer
Registered: 2008-08-12
Posts: 565

Re: Post your handy self made command line utilities

markp1989 wrote:

i attached a screnie for you lot to see lol.

http://i246.photobucket.com/albums/gg10 … shot-5.png

That screenie is proof alone that Ubuntu's destiny is to become windows. tongue

Offline

#737 2009-12-21 07:53:42

vik_k
Member
From: Pune, India
Registered: 2009-07-12
Posts: 227
Website

Re: Post your handy self made command line utilities

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

#738 2009-12-21 14:00:44

mikesd
Member
From: Australia
Registered: 2008-02-01
Posts: 785
Website

Re: Post your handy self made command line utilities

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. smile

Offline

#739 2009-12-21 14:54:30

Cyrusm
Member
From: Bozeman, MT
Registered: 2007-11-15
Posts: 1,052

Re: Post your handy self made command line utilities

mikesd wrote:

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 cool

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

#740 2009-12-22 08:34:29

mikesd
Member
From: Australia
Registered: 2008-02-01
Posts: 785
Website

Re: Post your handy self made command line utilities

Cool! I hadn't planned on using anything more than vim to edit the .bookmarks file but this is nice. Might have to try it.

Offline

#741 2009-12-22 08:41:31

lolilolicon
Member
Registered: 2009-03-05
Posts: 1,716

Re: Post your handy self made command line utilities

Cyrusm wrote:

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

#742 2009-12-23 04:57:48

ataraxia
Member
From: Pittsburgh
Registered: 2007-05-06
Posts: 1,545

Re: Post your handy self made command line utilities

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

#743 2009-12-23 17:50:55

munkyeetr
Member
From: Merritt, BC
Registered: 2008-08-07
Posts: 83

Re: Post your handy self made command line utilities

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

#744 2009-12-23 21:38:50

tlvb
Member
From: Sweden
Registered: 2008-10-06
Posts: 297
Website

Re: Post your handy self made command line utilities

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

#745 2009-12-24 07:24:32

mikesd
Member
From: Australia
Registered: 2008-02-01
Posts: 785
Website

Re: Post your handy self made command line utilities

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

#746 2009-12-27 21:13:02

shpelda
Member
Registered: 2008-08-07
Posts: 59

Re: Post your handy self made command line utilities

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

#747 2009-12-27 23:38:24

_AA_
Member
From: Maidstone, UK
Registered: 2008-07-14
Posts: 19
Website

Re: Post your handy self made command line utilities

#!/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

#748 2009-12-28 00:37:26

Barrucadu
Member
From: York, England
Registered: 2008-03-30
Posts: 1,158
Website

Re: Post your handy self made command line utilities

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

#749 2009-12-28 02:04:04

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

Re: Post your handy self made command line utilities

Post deleted.

Last edited by Wintervenom (2009-12-30 03:18:55)


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

Offline

#750 2009-12-28 04:49:49

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

Re: Post your handy self made command line utilities

barrudacu, "man comm". You can cut out those fugly sed blocks.

Offline

Board footer

Powered by FluxBB