You are not logged in.

#826 2010-01-30 22:30:19

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

Re: Post your handy self made command line utilities

If you're ever going to be moving between partitions you should also add error checking. In case disk is full, etc

Offline

#827 2010-01-30 22:33:05

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

Re: Post your handy self made command line utilities

Daenyth wrote:

If you're ever going to be moving between partitions you should also add error checking. In case disk is full, etc

thanks for the pointer:)

right now its all on the same partition, i just get abit ocd with my file/folder layout

Last edited by markp1989 (2010-01-30 22:36:33)


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

#828 2010-02-03 00:18:26

Runiq
Member
From: Germany
Registered: 2008-10-29
Posts: 1,053

Re: Post your handy self made command line utilities

$ curl -s http://www2.radioparadise.com/nowplay_3.php | html2text | sed -n '2p'

Handy little one-liner for getting the currently playing song from my favourite radio station, Radio Paradise.

- Put this in a script
- Define a hotkey to start it
- When you hear a song you like, press the key
→ the currently playing song is added to a text file of music that you definitely need to buy. smile

Offline

#829 2010-02-03 13:05:17

dunz0r
Member
From: Sweden
Registered: 2009-03-30
Posts: 258
Website

Re: Post your handy self made command line utilities

Small script to view an image without downloading it

#!/bin/bash
IMG=$1
CURL=`which curl`
VIEWER=`which display`

if [ -z $IMG ]; then
        printf "You need to specify an image to download\n"
        exit 1;
else
        $CURL $IMG | $VIEWER -
fi

RTFM or GTFO
hax0r.se

Offline

#830 2010-02-03 13:26:27

dunz0r
Member
From: Sweden
Registered: 2009-03-30
Posts: 258
Website

Re: Post your handy self made command line utilities

markp1989 wrote:

...
stuff
...

...
code
...

How did you set up your rtorrent to do this? I've been wondering about this a while now but never really took the time to investigate.


RTFM or GTFO
hax0r.se

Offline

#831 2010-02-03 15:43:36

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

Re: Post your handy self made command line utilities

Runiq wrote:
$ curl -s http://www2.radioparadise.com/nowplay_3.php | html2text | sed -n '2p'

Handy little one-liner for getting the currently playing song from my favourite radio station, Radio Paradise.

Cool! I wrote a quicky version for my favorite radio station, Soma.fm's Groove Salad:

curl -s http://somafm.com/groovesalad |html2text |grep "(Now)" |colrm 1 16

Offline

#832 2010-02-03 15:55:05

Runiq
Member
From: Germany
Registered: 2008-10-29
Posts: 1,053

Re: Post your handy self made command line utilities

jdarnold wrote:

Cool! I wrote a quicky version for my favorite radio station, Soma.fm's Groove Salad:

curl -s http://somafm.com/groovesalad |html2text |grep "(Now)" |colrm 1 16

Huh, last night I fount out that the output's all garbled. sad When I just redirect the output into a textfile, there are weird ^H characters in it... Will look into that.

Offline

#833 2010-02-03 17:37:51

milomouse
Member
Registered: 2009-03-24
Posts: 940
Website

Re: Post your handy self made command line utilities

dunz0r wrote:
markp1989 wrote:

...
stuff
...

How did you set up your rtorrent to do this? I've been wondering about this a while now but never really took the time to investigate.

I'm also curious about this as it may be an alternative to rtorrent's watch/set directories, although they seem to work fine. Also, rtorrent has: on_finished = notify,"execute=SOMENOTIFIER,$d.get_base_filename=,finished" could work for (email/etc) notification. Is this how you execute the script, though?

Last edited by milomouse (2010-02-03 17:42:10)

Offline

#834 2010-02-03 17:47:22

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

Re: Post your handy self made command line utilities

milomouse wrote:
dunz0r wrote:
markp1989 wrote:

...
stuff
...

How did you set up your rtorrent to do this? I've been wondering about this a while now but never really took the time to investigate.

I'm also curious about this as it may be an alternative to rtorrent's watch/set directories, although they seem to work fine. Also, rtorrent has: on_finished = notify,"execute=SOMENOTIFIER,$d.get_base_filename=,finished" could work for (email/etc) notification. Is this how you execute the script, though?

i have this line in my rtorrent.rc (i dont know if this works with the most recent version of rtorrent ) 

on_finished = notify_me,"execute=/home/mark/rtorrentmove.sh,$d.get_name="


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

#835 2010-02-03 18:06:25

scj
Member
From: Sweden
Registered: 2007-09-23
Posts: 158

Re: Post your handy self made command line utilities

dunz0r wrote:

Small script to view an image without downloading it

#!/bin/bash
IMG=$1
CURL=`which curl`
VIEWER=`which display`

if [ -z $IMG ]; then
        printf "You need to specify an image to download\n"
        exit 1;
else
        $CURL $IMG | $VIEWER -
fi

Why do you need to specify an image to download when the script can view images without downloading?

Offline

#836 2010-02-03 18:09:53

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

Re: Post your handy self made command line utilities

The way you use $CURL and $VIEWER in that script are 100% redundant

Offline

#837 2010-02-03 18:34:38

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

Re: Post your handy self made command line utilities

scj wrote:
dunz0r wrote:

Small script to view an image without downloading it

#!/bin/bash
IMG=$1
CURL=`which curl`
VIEWER=`which display`

if [ -z $IMG ]; then
        printf "You need to specify an image to download\n"
        exit 1;
else
        $CURL $IMG | $VIEWER -
fi

Why do you need to specify an image to download when the script can view images without downloading?

that should probably be "download and view an image without saving it".  i imagine $1 has to be a url to an image.

Offline

#838 2010-02-03 18:40:26

dunz0r
Member
From: Sweden
Registered: 2009-03-30
Posts: 258
Website

Re: Post your handy self made command line utilities

brisbin33 wrote:
scj wrote:
dunz0r wrote:

Small script to view an image without downloading it

#!/bin/bash
IMG=$1
CURL=`which curl`
VIEWER=`which display`

if [ -z $IMG ]; then
        printf "You need to specify an image to download\n"
        exit 1;
else
        $CURL $IMG | $VIEWER -
fi

Why do you need to specify an image to download when the script can view images without downloading?

that should probably be "download and view an image without saving it".  i imagine $1 has to be a url to an image.

brisbin33 got it right. Bad description, sry smile


RTFM or GTFO
hax0r.se

Offline

#839 2010-02-03 18:45:50

dunz0r
Member
From: Sweden
Registered: 2009-03-30
Posts: 258
Website

Re: Post your handy self made command line utilities

markp1989 wrote:
milomouse wrote:
dunz0r wrote:

How did you set up your rtorrent to do this? I've been wondering about this a while now but never really took the time to investigate.

I'm also curious about this as it may be an alternative to rtorrent's watch/set directories, although they seem to work fine. Also, rtorrent has: on_finished = notify,"execute=SOMENOTIFIER,$d.get_base_filename=,finished" could work for (email/etc) notification. Is this how you execute the script, though?

i have this line in my rtorrent.rc (i dont know if this works with the most recent version of rtorrent ) 

on_finished = notify_me,"execute=/home/mark/rtorrentmove.sh,$d.get_name="

Does this set the 'new' directory for rtorrent as well? So it won't stop seeding just because it gets moved?


RTFM or GTFO
hax0r.se

Offline

#840 2010-02-03 19:34:57

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

Re: Post your handy self made command line utilities

dunz0r wrote:
markp1989 wrote:
milomouse wrote:

I'm also curious about this as it may be an alternative to rtorrent's watch/set directories, although they seem to work fine. Also, rtorrent has: on_finished = notify,"execute=SOMENOTIFIER,$d.get_base_filename=,finished" could work for (email/etc) notification. Is this how you execute the script, though?

i have this line in my rtorrent.rc (i dont know if this works with the most recent version of rtorrent ) 

on_finished = notify_me,"execute=/home/mark/rtorrentmove.sh,$d.get_name="

Does this set the 'new' directory for rtorrent as well? So it won't stop seeding just because it gets moved?

i dont think it sets the new direcory, but my torrents still seed after they have been moved.

il look in to having it set the new folder, if i cannot set it i will have the script make a link from where the original folder was to the new location,

Last edited by markp1989 (2010-02-03 19:46:13)


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

#841 2010-02-03 21:08:58

dunz0r
Member
From: Sweden
Registered: 2009-03-30
Posts: 258
Website

Re: Post your handy self made command line utilities

Small utility for adding a specified number of random songs to mpd's playlist based on search terms.

#!/bin/bash
mpc search $1 "$2" | shuf -n$3 | mpc add

RTFM or GTFO
hax0r.se

Offline

#842 2010-02-04 16:33:26

Hiato
Member
Registered: 2009-01-21
Posts: 76

Re: Post your handy self made command line utilities

Something I put together not thirty seconds ago. I couldn't find any good cw suites, so I decided to throw together a Morse -> kdb led programme in python. It needs sudo/root priv. and python. Now that it's finished, I've realised how much harder it is to visually interpret Morse code - as opposed to listening to it. I might add that this is in no way limited to Morse code output, but I just cant think of anything else yet... Feel free to point out the bugs/bad style, though there shouldn't be any of either tongue

#!/usr/bin/env python
from os import system
from sys import argv
from time import sleep

def setl(i,s,t):
    a='-'
    if s: a='+'
    system("sudo setleds %s%s < /dev/tty%s" %(a,i,t))

# Arguments:     ttyID (usually 0), led name (eg: scroll), 
#        dit length (s), dah length (s), gap length (s), space length (s)
#        input as [.|-|/| ]
#Example:
#./led.py 0 scroll 0.2 0.4 0.25 0.6 '.... . .-.. .-.. ---/- --- -- ..--.'

ltr,cs,tty,id,dit,dah,gap,spc=True,0,argv[1],argv[2],float(argv[3]),float(argv[4]),float(argv[5]),float(argv[6])

setl(id,False,tty)

for k in argv[7]:
    if k==' ': cs,ltr=gap,False
    elif k=='/': cs,ltr=spc,False
    elif k=='-': cs,ltr=dah,True
    elif k=='.': cs,ltr=dit,True
    if ltr: setl(id,True,tty)
    sleep(cs)
    if ltr: 
        setl(id,False,tty)
        sleep(gap)

Offline

#843 2010-02-04 18:59:29

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

Re: Post your handy self made command line utilities

I use this when encoding videos for use on my ipod: because my server has a better cpu then my laptop i use scp to copy the file over to the server, use ffmpeg to convert the file (for some reason it still only uses 1 core, any one knows how to get it to use both cores i will appriciate it) then uses scp to copy it back, its simple , but makes my life alot easier smile

im sure a similar principle can be used for other cpu intensive tasks aswell

#Use remote cpu to encode a video

##chose what folder to use for tempory files on the host. 
encodedir=/media/encode 

#copy original file to the server for encoding
echo "copying file to server for encoding" 
scp -r "$1" "mark@192.168.1.99:$encodedir"

#encoding the video for use on my ipod 
ssh 192.168.1.99 ffmpeg -y -i "$encodedir/$1"  -s 320x180 -threads 2 -vcodec mpeg4 -ab 128k -acodec libfaac -ac 2 -ab 64k -f mp4 "$encodedir/$1-ipod.mp4" 

#Copys the result from the host to the client
echo "copying results from the server"  
scp -r  "mark@192.168.1.99:$encodedir/$1-ipod.mp4" "$1-ipod.mp4"

Last edited by markp1989 (2010-02-04 19:30:39)


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

#844 2010-02-04 21:41:04

scj
Member
From: Sweden
Registered: 2007-09-23
Posts: 158

Re: Post your handy self made command line utilities

Couldn't you avoid the intermediate file shuffling and use a pipe instead?

Something like

cat $1 | ssh server ffmpeg -i - $rest_of_flags - > $1-ipod.mp4

Offline

#845 2010-02-07 04:12:33

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

Re: Post your handy self made command line utilities

Function to make pacman ask for root privileges when required:

pacman() {
    if [[ "$1" =~ ^-S[cuy]|^-S$|^-R|^-U ]]
    then
        sudo pacman-color $@
    else
        pacman-color $@
    fi
}

NOTE:
Regex may need some work. It works for my common usage patterns though it could be missing a few options.
Might be an easier way to do this. smile

EDIT: Fixed regex. Made a couple of stupid mistakes.

Last edited by mikesd (2010-02-11 11:28:50)

Offline

#846 2010-02-07 04:50:52

res
Member
Registered: 2010-01-14
Posts: 55

Re: Post your handy self made command line utilities

^ Nice idea.

This one breaks less because it doesn't have to be the first operand, nor do the S,R,U operators need to be the first on the -xyz string:

shopt -s extglob

pacman() {
if [[ "$*" == *-@(*([^ilps ])S*([^ilps ])|*@(R|U)*)\ * ]]; then
  sudo pacman "$@"
else
  pacman "$@"
fi
}

e: hmm, might be even better to do this with compgen and comp_command..

Last edited by res (2010-02-07 05:16:34)

Offline

#847 2010-02-07 14:41:21

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 =~ and a regex rather than that fugly ==.

if [[ "$*" =~ -\w*[SRU] ]]; then

Not sure if it takes \w but if not you can always use a class.

Offline

#848 2010-02-08 03:12:42

res
Member
Registered: 2010-01-14
Posts: 55

Re: Post your handy self made command line utilities

Doesn't match the right pattern, nor does it take benign S options in account...

[[ '--S' =~ -\w*S ]]; echo $?
0

Thankfully, pacman just errs out... but running random commands with sudo is still running random commands with sudo. wink

Offline

#849 2010-02-09 03:20:50

mar77i
Member
Registered: 2009-02-16
Posts: 21

Re: Post your handy self made command line utilities

This is my ABSGET w/ AUR support and integrated update query and package search:

absget() {
        if ! (( $2 )); then
                # Since I use this func at most once in a week, I want to be asked
                read -en 1 -p "Synchronize ABS? [Yn]"
                [[ $(tr '[[:lower:]]' '[[:upper:]]' <<<$REPLY) = "N" ]] || sudo abs
        fi
        item=$1
        dest=$HOME/abs
        OLDIFS="$IFS"
        if [[ $item == /var/abs/* ]]; then
                # copy the package from abs
                cp -r $item $dest
                echo "Package ${item##*/} has been copied to \"$dest\"."
        else
                # otherwise, display any matching package in /var/abs
                arr=($(find /var/abs -type d -wholename "*$item*"))
                if (( ${#arr[@]} == 1 )); then
                        # if it's only one, grab it right away
                        echo "found $item in ${arr[0]}"
                        absget ${arr[0]} 1
                elif (( ${#arr[@]} == 0 )); then
                        # no package found here, look in AUR
                        entries=$(yaourt -Ss $item)
                        IFS=$'\n'
                        arr=($(\grep aur/ <<<"$entries"))
                        if (( "${#arr[@]}" == 0 )); then
                                echo "$item not found on AUR" >&2
                        elif (( "${#arr[@]}" == 1 )); then
                                # single entries can be downloaded from AUR
                                mkdir $dest/$item
                                ( cd $dest/$item; yaourt -G $item; )
                        else
                                # multiple entries are listed
                                yaourt -Ss $item
                        fi
                else
                        # display a list of packages
                        IFS=$'\n'
                        echo "${arr[*]}"
                fi
        fi
        IFS="$OLDIFS"
}

Last edited by mar77i (2010-02-09 04:22:54)


<rickh> f(Arch) = ((Gentoo - Compiletime) + (Slackware + Depency resolution and Downloading))

Offline

#850 2010-02-09 05:23:39

hullap
Member
From: New Delhi, India
Registered: 2008-08-17
Posts: 84
Website

Re: Post your handy self made command line utilities

Addiction to South Park

#!/bin/bash
# Play a random Sp episode.
cd '/media/disk/SOUTH PARK/';
smplayer "$( ls ./ | grep .avi | shuf -n1 )"
exit 0 # Respect my goddamn authoritah

Offline

Board footer

Powered by FluxBB