You are not logged in.

#1426 2011-02-24 10:18:14

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Post your handy self made command line utilities

@ PReP
I use

mplayer -af scaletempo -speed 1.8

when listening to lectures and I often similarly speed up or slow down some songs - you can adjust with '[' and ']' keys by default. With 'af scaletempo' the pitch stays the same - I much prefer it this way, not a big fun of Alvin and the Chipmunks am I :-)

Offline

#1427 2011-02-24 13:10:29

PReP
Member
From: Sweden
Registered: 2010-06-13
Posts: 359
Website

Re: Post your handy self made command line utilities

I understand what you mean, and know of the use of that sort of none-pitch changing tempo smile

But the purpose of the script, for me, is to add variation and randomness, but using _sane_ limits

it won't sound like chipmunks, or a drunken stoned dude, but - if there is singing - it will just sound like the singer has a different voice/scale,
and for chiptunes or electronic music, it will just sound like a different version of a song smile

Running it like this, even a few songs sounds a bit more exciting all the time.
But i guess it is up to each person how they feel about it smile

I am thinking about alternating with the scaletempo thing though, to add even more variation than it has now smile
I remembered that it where such a feature, but didn't remember the syntax, through an audio-filter i see by your command smile

-----

On a second note, is there a way too see how many times/if an AUR PKGBUILD has been downloaded?

Last edited by PReP (2011-02-24 13:11:55)


. Main: Intel Core i5 6600k @ 4.4 Ghz, 16 GB DDR4 XMP, Gefore GTX 970 (Gainward Phantom) - Arch Linux 64-Bit
. Server: Intel Core i5 2500k @ 3.9 Ghz, 8 GB DDR2-XMP RAM @ 1600 Mhz, Geforce GTX 570 (Gainward Phantom) - Arch Linux 64-Bit
. Body: Estrogen @ 90%, Testestorone @ 10% (Not scientific just out-of-my-guesstimate-brain)

Offline

#1428 2011-03-06 21:49:53

egan
Member
From: Mountain View, CA
Registered: 2009-08-17
Posts: 273

Re: Post your handy self made command line utilities

Here is the script I use to update my AUR packages, thought it might be useful to some. I have it set up to look for packages in ~/src/aur so change this to your appropriate location.

It checks the versions of the local PKGBUILD vs. those on the AUR at gives the option to download the package if they do not agree. It skips git packages.

EDIT: It now uses RPC.

#!/bin/bash

##
# upaur		-- check arch user repository for updates to foreign packages
#
# usage		-- upaur
#
# notes		-- requires jshon, netbool.sh, and userbool.sh
#
# written	-- 2 October, 2010 by Egan McComb
#
# revised	-- 7 November, 2010 by author
#		-- 6 June, 2011 by author
##

aurl="http://aur.archlinux.org/packages"
qurl="http://aur.archlinux.org/rpc.php?type=info&arg="
pkglist=$(pacman -Qm | tr " " ";")
destdir="$HOME/src/aur"

curl()
{
	command curl -s "$@"
}

wget()
{
	command wget -qP "$@"
}

getversion()
{
	curl -s "${qurl}$pkgname" | jshon -e results -e Version -u 2> /dev/null #|| echo "UNKNOWN"
}

output()
{
	printf "%-30s -- %s\n" $pkgname $status
	if [[ $status = OUTDATED ]]
	then
		echo -ne "\E[01;34m::\033[0m Retrieve tarball? [Y/n] "
		read response
		if userbool.sh $response
		then
			wget $destdir $aurl/$pkgname/$pkgname.tar.gz
		fi
	fi
}

##----MAIN----##
if ! netbool.sh
then
	echo "Error: Internet connectivity poor" >&2
	exit 1
fi

for pkg in $pkglist
do
	pkgname=$(cut -d ";" -f 1 <<< $pkg)
	if grep -q git <<< $pkgname
	then
		status="UNKNOWN"
	else
		localversion=$(cut -d ";" -f 2 <<< $pkg)
		extrnversion=$(getversion)
		if [[ $localversion == $extrnversion ]]
		then
			status="CURRENT"
		elif [[ $localversion < $extrnversion ]]
		then
			status="OUTDATED"
		fi
	fi
	output
done

exit 0
#!/bin/bash

##
# netbool.sh    -- check for proper Internet connectivity
#
# usage         -- netbool.sh
#
# notes         -- designed for use in other scripts
#
# todo          -- more elegant way to do this?
#
# written       -- 29 December, 2011 by Egan McComb
#
# revised       --
##

if ping -c 1 example.com &> /dev/null
then
        exit 0
else
        exit 1
fi
#!/bin/bash

##
# userbool.sh   -- parse boolean user input
#
# usage         -- userbool INPUT
#
# notes         -- designed for use in other scripts
#
# todo          -- add safeguards
#
# written       -- 29 December, 2011 by Egan McComb
#
# revised       --
##

##----MAIN----##
if [[ $1 = "Y" ]] || [[ $1 = "y" ]]
then    
        exit 0
else    
        exit 1
fi

Last edited by egan (2012-01-05 23:48:37)

Offline

#1429 2011-03-07 07:28:59

enzzzy
Member
Registered: 2010-10-09
Posts: 13

Re: Post your handy self made command line utilities

Why dont you use the aur rpc service ? (http://aur.archlinux.org/rpc.php)
Im writing a perl script for this with the use of the rpc service.

Offline

#1430 2011-03-07 14:34:52

egan
Member
From: Mountain View, CA
Registered: 2009-08-17
Posts: 273

Re: Post your handy self made command line utilities

enzzzy wrote:

Why dont you use the aur rpc service ? (http://aur.archlinux.org/rpc.php)
Im writing a perl script for this with the use of the rpc service.

Ah that's interesting. Maybe when I'm bored I'll go back and implement it with that stuff.

Offline

#1431 2011-03-08 03:01:33

prol
Member
Registered: 2008-03-27
Posts: 75

Re: Post your handy self made command line utilities

Pardon me if something like has already been shared. Well, this is a simple way to get the unread mail count of your gmail account


curl -u username:password --silent "https://mail.google.com/mail/feed/atom" | grep  fullcount | echo " Unread Mail: $(tr -d "</fullcount>")"

Offline

#1432 2011-03-12 13:00:46

hbekel
Member
Registered: 2008-10-04
Posts: 311

Re: Post your handy self made command line utilities

Here's a simple method to stream video over the net using gnu-netcat and mplayer:

First, on the server side, run

netcat -l -p 2000 < video.avi

And then on the client side:

netcat <host> 2000 | mplayer -

Where <host> is the server's ip address or hostname.

The first command will make netcat open port 2000 on the server side and send the video file to the first client connecting to it. The second command connects to the server on port 2000 and pipes the input it receives into mplayer, which plays stdin (-).

And here's a simple script called "vidstream" that uses the above method to stream a bunch of video files on the server, or to watch them on the client:

#!/bin/bash

port="2000"

usage() {
   echo "Usage: vidstream <files>..."
   echo "       vidstream <host> [<port>]"
   exit 1
}

if (($# < 1)); then
    usage
fi

if [[ -f "$1" ]]; then

    for video; do
    if [[ ! -d "$video" ]]; then
        echo "Streaming $video on port $port..."
        netcat -l -p $port < "$video"
    fi
    done
else 
    host="$1"
    port="${2:-$port}"
    
    echo -e "Watching streams from $host:$port\n"
    
    while :; do
        echo "Press any key to play or 'q' to quit" 
        read -n1 cmd

        if [[ "$cmd" == "q" ]]; then
            exit 0
        fi
        netcat "$host" "$port" | mplayer -fs -
    done
fi

On the server side, run

vidstream /all/my/videos/*

And then on the client:

vidstream <host>

Voila! The client will pause before every video, allowing you to either play the file or quit.

Note that this method has some drawbacks: You can't seek in the video or skip any videos coming from the server (although you can just quit mplayer to get the next video).

Last edited by hbekel (2011-03-13 18:13:37)

Offline

#1433 2011-03-12 17:12:56

Stebalien
Member
Registered: 2010-04-27
Posts: 1,239
Website

Re: Post your handy self made command line utilities

A small awk script to parse a playlist created by moc, ask a user to select a song with dmenu, and then return the path to the selected song.

BEGIN {
    FS=","
    dmenu="dmenu -l 10 -b -i -nb \"#111111\" -nf \"#aaaaaa\" -sf \"#afd700\" -sb \"#222222\""
}

/^#EXTINF/ {
    sub(/.$/, "", $2)
    title=$2
    print title |& dmenu
}

/^\// {
    sub(/.$/, "", $0)
    playlist[title]=$0
}

END {
    close(dmenu, "to")
    dmenu |& getline
    close(dmenu)
    print playlist[$0]
}

Steven [ web : git ]
GPG:  327B 20CE 21EA 68CF A7748675 7C92 3221 5899 410C

Offline

#1434 2011-03-13 03:54:24

ShadowKyogre
Member
From: Hell! XP No... I'm not telling
Registered: 2008-12-19
Posts: 476
Website

Re: Post your handy self made command line utilities

A small script that prints a list of sessions available based on the desktop files for xsessions to stdout for copypasting into the CDM config. I still need to get rid of duplicate entries that might show:

#!/bin/sh

here="$(ls -d -1 /usr/share/xsessions/*;ls -d -1 /etc/X11/sessions/*)"
session_names=""
session_execs=""

session_names=$(echo "$here"|while read line;
do
file="$(cat $line)"
name=$(echo "$file"|grep "Name="|sed 's/Name=//')
if test -n "$name" ;then
    echo -n "\"$name\" "
fi
done|sed -e "s/ \{1,\}$//")
session_execs=$(echo "$here"|while read line;
do
file="$(cat $line)"
exec="$(echo "$file"|grep "^Exec="|sed 's/Exec=//')"
if test -n "$exec" ;then
    echo -n "$exec "
else
continue;
fi
done|sed -e "s/ \{1,\}$//")

echo "wmbinlist=(${session_execs})"
echo "wmdisplist=(${session_names})"

For every problem, there is a solution that is:
Clean
Simple and most of all...wrong!
Github page

Offline

#1435 2011-03-21 22:12:01

ninian
Member
From: United Kingdom
Registered: 2008-02-24
Posts: 726
Website

Re: Post your handy self made command line utilities

Here's my take on the dreaded xdg-open ... it's a script called Exec which is semi-intelligent about the way it opens files via mime-types and .desktop files. Although Exec can be used like xdg-open to open files in the default associated application, it also has an option to let you choose from a menu of all applications associated with the files. You can also customize the program used to determine a file's MIME type and the program used to provide the menu of associated applications (for example, dmenu or zenity).

Exec will respect a %f, %F, %u or %U field within the command line string specified by a desktop file. Multiple files can be opened by the associated application, either by passing all the files to a single command or spawning the command, once for each file. Also, it handles filenames with embedded spaces properly!

Hope you might find it useful.
wink

Last edited by ninian (2011-03-21 22:12:59)

Offline

#1436 2011-04-01 19:19:01

bootleg
Member
Registered: 2010-12-08
Posts: 38

Re: Post your handy self made command line utilities

Here’s a shell script which deletes all tilde files to clean up a little bit. It can clean recursively all subdirectories.
It’s pretty staight forward and it needs more work (like cleaning several directories at once…).
I don’t know if it can be helpful to anyone… anyway here it is:

#! /bin/sh                                                                                                                                                    


usage()
{
cat << EOF
Usage : `basename $0` [-vrh] <path>

This script removes all “tilde” backup files in the directory <path>.
If no path is specified, it cleans the current directory.
If the specified path does not exist,
    the script assumes it is a file name, deletes it,
    and cleans the current directory.

Options:
 -v verbose
 -r recursive
 -h this help
EOF
    
}


# OPTIONS HANDLE
dir=
group=
while [ $# -gt 0 ]; do
    if [ -z $group ]; then
        opt=$1
    fi  
    case $opt in
        -v|-*v*)
            verbose=on
            if [ $opt = "-v" ]; then
                group=
                shift
            else
                opt=${opt/v/}
                group=yep
            fi  
            ;;  
        -r|-*r*)
            rec=on
            if [ $opt = "-r" ]; then
                group=
                shift
            else
                opt="${opt/r/}"
                group=yep
            fi  
            ;;  
        -*) 
            usage
            exit 0
            ;;  
        *)  
            if [ -z $dir ]; then
                dir=$1
            else
                usage
                exit 0
            fi
            shift
            ;;
    esac
done


# EXRA FILE
plus=
if [ -z "$dir" ]; then
    dir=.
elif ! [ -d "$dir" ]; then
    plus="$dir"
    dir=.
fi


if ! [ -z "$plus" ]; then
    if [ "$verbose" = on ]; then
        echo "rm $plus"
    fi
    rm "$plus"
fi


export verbose
export rec

# DELETION
if [ "$verbose" = on ]; then
    echo "rm -f $dir/.*~" 
    echo "rm -f $dir/*~"
fi

rm -f "$dir"/.*~ "$dir"/*~


# RECURSION
if [ "$rec" = on ]; then
    # show all files,show only directories,keep only names,              allow spaces in names
    ls -lA "$dir"    |grep ^d              |sed 's/^.*[0-9] \(.*\)$/\1/' | while read i; do
        neat "$dir/$i"
    done
fi

Offline

#1437 2011-04-02 11:01:52

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Post your handy self made command line utilities

Have a look at

locate "*~"
find . -name "*~"

And you can tell e.g. vim to keep the ~ files in a specific directory.

Instaed of

ls -lA "$dir"    |grep ^d              |sed 's/^.*[0-9] \(.*\)$/\1/' 

try

find . -type d -maxdepth 1

with a specific '-printf' formatting.


As for verbose output:

[karol@black test]$ ls
00  01    02  03    04  05    06  07    08  09
[karol@black test]$ rm -fv *
removed `00'
removed `01'
removed `02'
removed `03'
removed `04'
removed `05'
removed `06'
removed `07'
removed `08'
removed `09'

Last edited by karol (2011-04-02 11:07:32)

Offline

#1438 2011-04-02 20:31:55

gadamat
Member
Registered: 2010-06-04
Posts: 2

Re: Post your handy self made command line utilities

Added to the ~/.bashrc file: A very, very simple but handy command-line dictionary using curl, dict.org and less:

define() {
    curl -s dict://dict.org/d:$1 | grep -v '^[0-9]' | less
}

Usage:

$ define defenestrate

If you don't want to use less, simply drop it and its pipe from the end of the line.


$ ln -s `pwd`

Offline

#1439 2011-04-02 23:12:01

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

Re: Post your handy self made command line utilities

For editing Vorbis comments:

#!/bin/bash

# A simple tool to edit tags in Vorbis files

# Check a file has been given
if [[ ! -e "$1" ]]; then
    echo "USAGE: vorbtags <file>"
    exit 1
fi

# Check we have an editor
if [[ "$EDITOR" == "" ]]; then
    echo "\$EDITOR is unset!"
    exit 1
fi

# Make a temporary file
tmpfile="/tmp/vorbtags.$UID.`date +s`"

# Edit vorbis tags
vorbiscomment -l "$1" -c $tmpfile
$EDITOR $tmpfile
vorbiscomment -w "$1" -c $tmpfile

# Clean up
rm $tmpfile

Offline

#1440 2011-04-03 13:15:16

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

Re: Post your handy self made command line utilities

first script downloads the latest .torrent files from the ubuntu web site

each unsuccesful download hits the Ubuntu page 2 times, so i only run it every 6 hours on the scheduled Ubuntu release day, I avoid running it too often as I don't want to over load their server.


#!/bin/bash
##markp1989
##script to download torrents of the latest ubuntu release. 


##setting the watch folder of your torrent client 
watch=/watch

##setting where to log any downloads 
log=/home/rtorrent/downloaded.ubuntuget

##cding to the watch folder  
cd $watch 


##scraping part of the releases page to find out the name of the latest version 
newest=$(curl http://releases.ubuntu.com/ | grep ")</a>" | cut -f2 -d'"' | cut -f1 -d'/' | tail -n 1)

##setting the base url  which is http://releases.ubuntu.com/NameOfNewestRelease 
baseurl="http://releases.ubuntu.com/$newest/"


        #running a loop for every torrent link on the latest release page

        for i in $(curl $baseurl | grep iso.torrent | cut -f10 -d'"' ); do

                ##checking weather the torrent file already exists, downloading only if the file doesnt exist 
                if [ -f $i ];
                then
                        #outputing that the file exists
                        echo "file $i already exists"
                else
                        ##downloading the torrentfile
                        wget $baseurl$i
                        ##logging the download
                        echo $i >> $log
                fi

        done


##if a download log exists (will only exist if atleast one .torrent file was downloaded)  then I get an email with the content of the log file sent to me , after that that log file is deleted. 
if  [ -f  $log];
        then
                 mail.sh "myemail@domain.co.uk" "ubuntuget output $(date)" " $(cat $log)"
                rm  $log
fi

this is the mail.sh script called in the script above

#!/bin/bash
##markp1989 
##small email script

##usage
##mail.sh "recipent" "subject" "body"
## eg mail.sh "example@example.com,john@example.com" "Just saying hi" "hey, just emailing you to give you this notification" 


recipent=$1
subject=$2
body=$3

echo -e "$(date) \n\n $body" | mail -s "$subject" $recipent 

still pretty new to scripting and programing in general, so any pointers on those scripts will be appreciated.

Last edited by markp1989 (2011-04-03 13:17:26)


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

#1441 2011-04-03 16:41:05

steve___
Member
Registered: 2008-02-24
Posts: 452

Re: Post your handy self made command line utilities

Here are a few changes.

#!/bin/bash
##markp1989
##script to download torrents of the latest ubuntu release. 


##setting the watch folder of your torrent client 
watch=/watch

##setting where to log any downloads 
log=/home/rtorrent/downloaded.ubuntuget

##cding to the watch folder  
cd "$watch"


##scraping part of the releases page to find out the name of the latest version 
#newest=$(curl http://releases.ubuntu.com/ | grep ")</a>" | cut -f2 -d'"' | cut -f1 -d'/' | tail -n 1)
curl -Ls http://releases.ubuntu.com/ | awk -F'"|/' '/)<\/a>/ {x=$2};END{print x}'

##setting the base url  which is http://releases.ubuntu.com/NameOfNewestRelease 
baseurl="http://releases.ubuntu.com/$newest/"


        #running a loop for every torrent link on the latest release page

        while read -r i; do
        #for i in $(curl $baseurl | grep iso.torrent | cut -f10 -d'"' ); do

                ##checking weather the torrent file already exists, downloading only if the file doesnt exist 
                if [[ -f $i ]]; then
                        #outputing that the file exists
                        echo "file $i already exists"
                else
                        ##downloading the torrentfile
                        wget "$baseurl$i"
                        ##logging the download
                        echo "$i" >> "$log"
                fi

        done < <(curl -Ls "$baseurl" | grep iso.torrent | cut -f10 -d'"' )


##if a download log exists (will only exist if atleast one .torrent file was downloaded)  then I get an email with the content of the log file sent to me , after that that log file is deleted. 
if  [[ -f  $log]]; then
                 mail.sh "myemail@domain.co.uk" "ubuntuget output $(date)" " $(< $log)"
                rm  "$log"
fi

Offline

#1442 2011-04-04 19:27:51

bootleg
Member
Registered: 2010-12-08
Posts: 38

Re: Post your handy self made command line utilities

karol wrote:

Have a look at [...]

Thank you!

Offline

#1443 2011-04-11 04:33:53

yasar11732
Member
Registered: 2010-11-29
Posts: 127

Re: Post your handy self made command line utilities

Here is the one I use to make repository out of an directory:

#!/bin/sh
###### User Defined Settings ######

#The Place where our packages reside. WITHOUT TRAILING SLASH!
PLACE="/media/yasar"

#The name of your repository, e.g my-repo
#you need to use same name in pacman.conf
REPONAME="usb-repo"

#modified less then this amount of minutes ago
#so that we don't add all files to database everytime we run this script
MODTIME="60"

###### End of User Defined Settings ####

DB="${PLACE}/${REPONAME}.db.tar.gz"

find $PLACE -name \*.pkg.tar.xz -cmin -$MODTIME -exec repo-add $DB '{}' ';'

Yo Dawg, I heard you likes patches, so I have created a patch for your patch, so you can patch your patches before you patch.

Offline

#1444 2011-04-21 05:57:02

OrionFyre
Member
Registered: 2008-03-16
Posts: 68

Re: Post your handy self made command line utilities

crashed my system, reinstalled. didn't want to wait for all of xorg* gnome* flashplugin libreoffice gimp etc to pull down one by one since powerpill was dropped sad

pacaria.sh

#!/bin/bash

if [ `whoami` = "root" ]
then
   echo -e "\n\nNo error checking,\nwe don't honor pac.lck\nand you are running this as root\n\n"
   echo -e "if you don't like the sound of that (and you shouldn't)...press ctrl+c NOW"
   sleep 1
   pacman -Syud --print | grep 'ftp\|http' >/tmp/pacaria-list
   aria2c -i /tmp/pacaria-list -d /var/cache/pacman/pkg -j 10
   rm /tmp/pacaria-list
   pacman -Su
else
   echo -e "\n\n(\\___/)   Bunny is not root\n(=o.O=) he tries again with sudo\n(\")_(\")   pac flies like eagle"
fi

Offline

#1445 2011-04-21 16:26:39

bunburya
Member
From: Dublin, Ireland
Registered: 2010-09-06
Posts: 64

Re: Post your handy self made command line utilities

I'm not sure if there is a ready-made tool for this, but here is a simple script which tells you of orphaned packages (those installed as a dependency for another package which is no longer installed) and removes them if you confirm that you want to.

#!/bin/sh

orphs=( $(pacman -Qdtq) )
echo ${orphs[*]}
echo -n "Do you want to remove these packages? [y/N] "
read ans

yn="$(echo "$ans" | cut -c 1)"
if [[ "$yn" == "y" || "$yn" == "Y" ]]; then
    sudo pacman -R --noconfirm ${orphs[*]}
fi

* Edited to take into account advice from lolilolicon.

Last edited by bunburya (2011-04-21 17:07:28)

Offline

#1446 2011-04-21 16:34:58

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

Re: Post your handy self made command line utilities

bunburya wrote:
#!/bin/sh

pacman -Qdt
echo -n "Do you want to remove these packages? [y/N] "
read ans

yn="$(echo "$ans" | cut -c 1)"
if [ $yn == "y" || $yn == "Y" ]; then
    sudo pacman -R $(pacman -Qdt | awk '{print \$1}')
fi

1. You should not call `pacam -Qdt` twice. Use an array instead.
2. `pacman -Qdtq` prints the pkgnames only.
3. The awk command is wrong; no need for the backslash.


This silver ladybug at line 28...

Offline

#1447 2011-04-21 16:50:45

bunburya
Member
From: Dublin, Ireland
Registered: 2010-09-06
Posts: 64

Re: Post your handy self made command line utilities

Thanks for the tips! And yeah, I noticed the backslash thing.

Offline

#1448 2011-04-22 01:45:32

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

Re: Post your handy self made command line utilities

That looks better. A little bit more adjustments:

#!/bin/bash

orphs=($(pacman -Qdtq))
echo ${orphs[*]} >&2

read -p "Do you want to remove these packages? [y/N] " ans
yn=${ans:0:1}

[ "${yn,}" == y ] && sudo pacman -R --noconfirm ${orphs[*]}

Note though, in arch, /bin/sh is a symlink to /bin/bash. When using bashism (like I probably did here), one should put #!/bin/bash as the shebang, instead of #!/bin/sh.


This silver ladybug at line 28...

Offline

#1449 2011-04-22 12:25:01

jac
Member
From: /home/jac
Registered: 2009-05-19
Posts: 431
Website

Re: Post your handy self made command line utilities

I made this script to decode the only file base64 encoded and attached to an email, I'm quite certain it will fail if multiple files were attached

#!/bin/sh

if [ -z "$1" ] || [ ! -f "$1" ]; then
    echo "First argument must be a file"
    exit 1
fi

HEADER="`mktemp`"
sed '/^$/,$d' "$1" > $HEADER
MARKER="`sed -n 's/^ boundary="\([^"]*\)"/\1/p' $HEADER`"
rm $HEADER

if [ -z "$MARKER" ]; then
    echo "Couldn't find a content marker"
    exit 1
fi

DATA="`mktemp`"
sed -n "/^--$MARKER$/,/^--$MARKER--$/p" "$1" > $DATA
OUTNAME="`sed -n 's/^ name="\([^"]*\)"/\1/p' $DATA`"
BSFDATA="`sed -n '/^$/,$p' $DATA | head -n -1`"
rm "$DATA"

if [ -z "$OUTNAME" ]; then
    echo "Couldn't find output filename"
    exit 1
fi

if [ -z "$BSFDATA" ]; then
    echo "Couldn't find base64 encoded data"
    exit 1
fi

echo "$BSFDATA" | base64 -d > "$OUTNAME"
echo "$OUTNAME"

I post it for a number of reasons:
1) Does anyone have improvements? I've tried to remove bash-isms and keep dependencies low.
2) Does anyone know what program I should "actually" be using for this? It seems every time I make a script, someone else made a much better program ten years ago that does more XD

Offline

#1450 2011-04-22 20:24:54

strangeways
Member
Registered: 2011-01-18
Posts: 3

Re: Post your handy self made command line utilities

This script is designed to find installed python eggs that are not managed by pacman.

#! /usr/bin/python2

import subprocess
from pkg_resources import working_set

eggs = [e.key for e in working_set]

for e in eggs:
    proc = subprocess.Popen(
        ["/usr/bin/pacman", "-Qsq", e],
        stdout=open('/dev/null')
    )
    rc = proc.wait()
    if rc == 1:
        print(e)

Offline

Board footer

Powered by FluxBB