You are not logged in.

#301 2009-04-12 20:24:03

quarkup
Member
From: Portugal
Registered: 2008-09-07
Posts: 497
Website

Re: Post your handy self made command line utilities

a shellscript for test with multiple input's a program. uses the diff utility (or the colordiff)
edit: those "\e[xx;xxm" are colors..


#! /bin/bash
 
##--##--##--##--##--##--##--##--##--##--##--##--##
## useful flags for this script: -y --suppress-common-lines
## (the same used with the diff command)
#
 x="a.out";
 testsfolder="tests/";
 diff="diff";
 [ `which "colordiff"` ] && diff="colordiff";
 
 # tests name and extensions-settings
 name="test";
 ext_out=".out";
 ext_res=".res";
 ext_in=".in";
##--##--##--##--##--##--##--##--##--##--##--##--##
 
 
 printf "\n\e[01;32mCompiling... \e[01;00m\n\n";
 make || exit 1;
 
 printf "\n\n\e[01;32mTesting...\e[01;00m\n\n";
 [ -e "${testsfolder}" ] && cd "${testsfolder}" || exit 1;
 
 [ ! -e "${x}" ] && ln -s ../${x} ./;
 
 for input in `ls "${name}"*"${ext_in}"`
  do
 
output=${input//"${ext_in}"/"${ext_out}"};
   result=${input//"${ext_in}"/"${ext_res}"};
   [ -e "${result}" ] && rm -f "${result}";
 
   printf "\e[01;34m(${input})\e[01;00m \t------------------------------\t ";
   ./${x} < "${input}" > "${result}" || exit 1;
   X=`diff "${output}" "${result}"`;
 
   if [ ! -e "${output}" ]
    then
printf "\e[01;31m(error: output testfile not found)\e[00;00m\n";
   elif [ "$X" == "" ]
    then
printf "\e[01;36m(ok)\e[00;00m\n";
    else
printf "\e[01;31m(not ok)\e[00;00m\n";
   fi
 
if [ "$*" != "" ]
    then
printf "\e[01;32m";
     cat -n "${input}";
     printf "\e[01;00m\n---\n";
     ${diff} $* "${output}" "${result}";
     read;
     printf "\n\n";
   fi
 
done
 
 [ -e "${x}" ] && rm -f ./${x};
 
 cd ..;
 printf "\n\e[01;32mDone.\e[00;00m\n";
 
exit 0;

Last edited by quarkup (2009-04-12 20:24:54)


If people do not believe that mathematics is simple, it is only because they do not realize how complicated life is.
Simplicity is the ultimate sophistication.

Offline

#302 2009-04-12 20:26:35

Dieter@be
Forum Fellow
From: Belgium
Registered: 2006-11-05
Posts: 2,001
Website

Re: Post your handy self made command line utilities

jumzi wrote:

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

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

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

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

dieter@dieter-ws-a7n8x-arch ~ mpc | grep - | wmiir /rbar/mpd
usage: %$%s [-a <address>] {create | read | ls [-ld] | remove | rm | write} <file>
       %$%s [-a <address>] xwrite <file> <data>
       %$%s -v
dieter@dieter-ws-a7n8x-arch ~  wmiir ls /rbar/
status

Doesn't work here, maybe because I i have /rbar/mpd ? however i tried 'wmiir write /rbar/status' and that didn't do anything.

EDIT: I just edited my wmiirc to do it much simpler:

status() {
        echo -n $(uptime | sed 's/.*://; s/,//g') '|' $(date) "`mpc | grep - 2>/dev/null`"
}

Last edited by Dieter@be (2009-04-12 21:19:23)


< Daenyth> and he works prolifically
4 8 15 16 23 42

Offline

#303 2009-04-12 20:33:34

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

Re: Post your handy self made command line utilities

marxav wrote:

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

i installed that, and it still doesnt work, insted of running the application, it just open up the launcher file in firefox :S ?


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

#304 2009-04-12 21:08:10

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

Re: Post your handy self made command line utilities

madeye wrote:

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

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

#! /bin/bash

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

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

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

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

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

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

# Remove wav file
rm "$FILNAME.wav"

Nice! I convert flv to mp3 all the time using ffmpeg, with a simple bash function:

# Convert Flash video to MP3
flvmp3() {
  ffmpeg -i $1 -ar 44100 -ab 192k -ac 2 $2
}

So just "flvmp3 youtube.flv mynew.mp3" smile However I'm curious if your method results in better quality, although most .flv's I grab (from YT and such) are usually pretty average to low quality as it is...

Offline

#305 2009-04-13 08:15:24

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

Re: Post your handy self made command line utilities

colbert wrote:

Nice! I convert flv to mp3 all the time using ffmpeg, with a simple bash function:

# Convert Flash video to MP3
flvmp3() {
  ffmpeg -i $1 -ar 44100 -ab 192k -ac 2 $2
}

So just "flvmp3 youtube.flv mynew.mp3" smile However I'm curious if your method results in better quality, although most .flv's I grab (from YT and such) are usually pretty average to low quality as it is...

I use downloadhelper in firefox to download the videos from youtube. Just make sure to choose the file that is called "video.flv" as that typically contain the version you are watching on the screen.

I tried using ffmpeg, but always got mono sound even from stereo videos. Maybe I did something wrong? (probably smile  )


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

Offline

#306 2009-04-13 08:41:54

rwd
Member
Registered: 2009-02-08
Posts: 664

Re: Post your handy self made command line utilities

Varreon wrote:

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

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

import urllib

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

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

Why not use Google? That way you get the exact page. I use this scriptlet in Firefox to do 'search within current site':
make a bookmark with

location:

javascript:void(location.href='http://www.google.com/search?&q=site:'+location.href.split(%22/%22)[2]+'+%s&sourceid=firefox')

keyword: h:

Then you can just type in the address bar:

h: some searchterms

Last edited by rwd (2009-04-13 08:44:50)

Offline

#307 2009-04-13 08:46:44

bluewind
Administrator
From: Austria
Registered: 2008-07-13
Posts: 172
Website

Re: Post your handy self made command line utilities

madeye wrote:

I tried using ffmpeg, but always got mono sound even from stereo videos. Maybe I did something wrong? (probably smile  )

Youtube's .flv videos are only mono. Switch to the .mp4 (&fmt=18) version to get stereo.
If that still doesn't work use

 mplayer "foo.mp4" -ao pcm:file=/tmp/mplayer_conv.wav; lame -h /tmp/mplayer_conv.wav "foo.mp3"

Offline

#308 2009-04-13 18:14:06

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

Re: Post your handy self made command line utilities

madeye wrote:

I use downloadhelper in firefox to download the videos from youtube. Just make sure to choose the file that is called "video.flv" as that typically contain the version you are watching on the screen.
I tried using ffmpeg, but always got mono sound even from stereo videos. Maybe I did something wrong? (probably smile  )

Oh yeah, I use DownloadHelper as well, great add-on smile The reason you got mono is probably missing the option I put above: "-ac 2" it ensures two (stereo) channels smile

Request: I have rsyncs in my crontab that do ">> ~/logs/backup_$(date +.%m.%d.%y_%T).log" and I'm wondering how I can make it so that only the most recent .logs are kept, for example the last 5??

Offline

#309 2009-04-13 18:39:52

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

Re: Post your handy self made command line utilities

colbert wrote:

Oh yeah, I use DownloadHelper as well, great add-on smile The reason you got mono is probably missing the option I put above: "-ac 2" it ensures two (stereo) channels smile

I compared your ffmpeg command to mine, and saw that I indeed was missing the "-ac 2" option.
Oh well. Now I've made the script, I might as well use it smile


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

Offline

#310 2009-04-13 18:53:53

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

Re: Post your handy self made command line utilities

colbert wrote:
madeye wrote:

I use downloadhelper in firefox to download the videos from youtube. Just make sure to choose the file that is called "video.flv" as that typically contain the version you are watching on the screen.
I tried using ffmpeg, but always got mono sound even from stereo videos. Maybe I did something wrong? (probably smile  )

Oh yeah, I use DownloadHelper as well, great add-on smile The reason you got mono is probably missing the option I put above: "-ac 2" it ensures two (stereo) channels smile

Request: I have rsyncs in my crontab that do ">> ~/logs/backup_$(date +.%m.%d.%y_%T).log" and I'm wondering how I can make it so that only the most recent .logs are kept, for example the last 5??

Use the tools that are already there.  Set up logrotate to roll ~/logs/backup.log every day and roll 5 logs.  backup.log will be the most recent, backup.log.4 will be from 4 days ago.


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

Offline

#311 2009-04-13 20:02:50

elmer_42
Member
From: /na/usa/ca
Registered: 2008-10-11
Posts: 427

Re: Post your handy self made command line utilities

Well, it's far from perfect (for example, if there is no entry for the term it just gives no output), but I made a quick (one-lined) script I call thes that uses lynx to get thesaurus entries from thesaurus.reference.com. You could probably integrate it into your .bashrc very easily, but for some reason I just put it in /usr/bin and ran chmod +x on it.

lynx -nonumbers -dump http://thesaurus.reference.com/browse/$1|grep -E -i -A10 "Main Entry: "|cut -c4-100

[ lamy + pilot ] [ arch64 | wmii ] [ ati + amd ]

Offline

#312 2009-04-14 18:35:08

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

Re: Post your handy self made command line utilities

just threw this together for my dual screen setup

my set up consists of two screens . 1440x900, totalling 2880x900
when i full screen the windows, they only take up 1 monitor, this script makes the active window take up both of the screens.

im planing to eventualy make it a toggle script so that if the window is allready split screened then it will make it size 1024*768.

1 problem i am having right now is that it wont do anything if the window is maximised by the wm,

if you plan to use this you will need to change resolutions 2 fit your dual screen setup.

#!/bin/bash
CURR=$(xdotool getactivewindow)
xdotool windowsize $CURR 2880 900 &
xdotool windowmove $CURR 0 0 &

this is my first ever deal with xdotool, its quite cool. is there any way to ave xdotool print the current size of the window?

im planing something like this

if window size = 2880x900 then 
CURR=$(xdotool getactivewindow)
xdotool windowsize $CURR 1024 768 &
xdotool windowmove $CURR $random $random &
else
CURR=$(xdotool getactivewindow)
xdotool windowsize $CURR 2880 900 &
xdotool windowmove $CURR 0 0 &
fi

Last edited by markp1989 (2009-04-14 18:48:52)


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

#313 2009-04-15 23:25:44

bintang
Member
Registered: 2009-04-15
Posts: 5

Re: Post your handy self made command line utilities

#!/bin/bash

targetTime=120
crunchTime=30
session=`echo $(($targetTime/crunchTime))`
breakTime=5


for ((i=1;i<=session;i++)); do
        utimer -t ${crunchTime}m
        (echo 'You may rest!.') | dzen2 -p 5 -x 480 -y 400 -w 300 -fn fixed -fg black -bg green
        utimer -t ${breakTime}m
        (echo 'Back to work!') | dzen2 -p 10 -x 480 -y 400 -w 300 -fn fixed -fg black -bg red
done

Offline

#314 2009-04-16 02:05:17

fumbles
Member
Registered: 2006-12-22
Posts: 246

Re: Post your handy self made command line utilities

.

Last edited by fumbles (2020-09-26 11:44:49)

Offline

#315 2009-04-16 20:11:48

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

Re: Post your handy self made command line utilities

i don't know if i'd call this handy, but i enjoy it.  i _know_ it could be done better, and probably with an awk one liner.  but this is how i did it.

first, save this file as $HOME/.mquotes

then, use this script to call a random mitch hedberg quote.  priceless.

#!/bin/bash

WD="/tmp/quotes"
file="$HOME/.mquotes"
color0="[1;32m"

[ -d $WD ] || mkdir $WD

# number of quote blocks, length of file and a random number
NOM=$(grep -c MARK $file)
NOL=$(cat $file | wc -l)
RNUM=$[ ( $RANDOM % $NOM ) + 1 ]

touch $WD/mark.lst

count=1
grep -nx MARK $file | while read line; do
  echo "$count $line" >> $WD/mark.lst
  count=$(( count+1 ))
done

getlinenum() {
  start_mark=$1
  stop_mark=$(( start_mark + 1 ))
  start_line=$(grep ^$start_mark\  $WD/mark.lst | awk '{print $2}' | cut -d ":" -f 1)
  stop_line=$(grep ^$stop_mark\  $WD/mark.lst | awk '{print $2}' | cut -d ":" -f 1)
  HL=$(( stop_line - 1 ))
  TL=$(( stop_line - start_line - 1 ))
}

getlinenum $RNUM

echo ""
echo -e "\e${color0}Random Mitch quote number $RNUM\e[0m"
cat $file | head -n$HL | tail -n$TL
echo ""

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

exit 0

you could make your own quote files following the same format and it's like your own fortune-mod package.

Last edited by brisbin33 (2009-04-16 20:21:57)

Offline

#316 2009-04-16 20:19:35

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

Re: Post your handy self made command line utilities

That would be much better suited as a fortune-mod file.

Offline

#317 2009-04-16 20:23:33

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

Re: Post your handy self made command line utilities

learning exercise my friend.  it suits me just fine as is wink

Offline

#318 2009-04-16 20:39:58

Yannick_LM
Member
Registered: 2008-12-22
Posts: 142

Re: Post your handy self made command line utilities

<slightly off-topic>
The manpage for strfile (the program which parses fortunes files) is definitively worth reading ...
</off topic>

Offline

#319 2009-04-16 21:04:02

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

Re: Post your handy self made command line utilities

Yannick, that manpage was both useful and humorous.  thanks.

Offline

#320 2009-04-20 19:52:37

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

Re: Post your handy self made command line utilities

Here are two scripts to remove recursion using ln, for applications that don't work with recursion, or because you want to inspect a complex tree.

Softlinking, this is useful for single use because it returns the new directory to find the files in (in /tmp), I use this for comix like this: comix $(softlinker comic_vol1)
If you use it a lot (100 times on a 125 file directory = 50MB of softlinks) remove the directories in /tmp: rm -R /tmp/softlink*

#! /bin/bash
[ $# -ne 1 ] && exit 1
[ ! -d "$1" ] && exit 1
mkdir /tmp/softlink$$ || exit 1

if [[ $1 =~ ^/ ]]; then
#absolute path
abspath="$1"
else
#relative path
abspath="$PWD/$1"
fi

IFS="
"
for file in $(find "$abspath" -type f); do
ln -s "$file" /tmp/softlink$$/"$(sed 's/\//_/g;s/ /_/g' <<< "$file")" > /dev/null
done
echo /tmp/softlink$$

And hardlinking: this takes two arguments and produces a lot of output on what it's doing, because it is more prone to error. The first argument is the source directory and the second is the target. It will run find on the source and link everything to target dir. I use this for easytag, because easytag doesn't work reliably with softlinks.

#! /bin/bash

[ $# -ne 2 ] && exit
[ ! -d "$1" ] && exit
[ ! -d "$2" ] && exit

IFS="
"
for file in $(find "$1" -type f); do
newf=$(echo "$file" | sed 's/\//_/g')
ln -v "$file" "$2/$newf"
done

Common errors you can run into are too long filenames, because the whole directory structure is prepended to the filename with slashes replaced of course.

EDIT: and another thing is that ln -v will print the information as target ==> source, so that can be a bit of a shock, but there is no -f so there should be no worry about files being overwritten.

Last edited by Procyon (2009-04-20 20:00:07)

Offline

#321 2009-04-20 20:12:30

Zariel
Member
Registered: 2008-10-07
Posts: 446

Re: Post your handy self made command line utilities

I wrote this to print the output of what mpd is currently playing instead of having to use mpc, you need libmpdclient{c,h} in the dir (if someone could make it so you just need them installed)

Save it is mpdnp.c

/*
Copyright (c) 2008 Chris Bannister,
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
   notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
   notice, this list of conditions and the following disclaimer in the
   documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
   derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "libmpdclient.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

int main(){
    mpd_Connection * conn;
    char *host = getenv("MPD_HOST");
    char *port = getenv("MPD_PORT");

    if(host == NULL) {
        host = "localhost";
    }

    if(port == NULL) {
        port = "6600";
    }

    conn = mpd_newConnection(host, atoi(port), 10);

    if(conn->error) {
        mpd_closeConnection(conn);
        /* Just return 0 to hide it from xmobar */
        return 0;
    }

    mpd_Status * status;
    mpd_InfoEntity * entity;

    mpd_sendCommandListOkBegin(conn);
    mpd_sendStatusCommand(conn);
    mpd_sendCurrentSongCommand(conn);
    mpd_sendCommandListEnd(conn);

    status = mpd_getStatus(conn);
    int *state = &status->state;

    if(*state == MPD_STATUS_STATE_STOP) {
        return 0;
    }

    char *artist;
    char *title;

    /*float per = ((float) status->elapsedTime / (float) status->totalTime) * 100; */

    mpd_nextListOkCommand(conn);

    while((entity = mpd_getNextInfoEntity(conn))) {
        mpd_Song * song = entity->info.song;
        artist = song->artist;
        title = song->title;
    }

    if(*state == MPD_STATUS_STATE_PLAY) {
        fprintf(stdout, "%s - %s\n", artist, title);
    } else if(*state == MPD_STATUS_STATE_PAUSE) {
        fprintf(stdout, "%s - %s*\n", artist, title);
    }

    return 0;
}

then make with

gcc -Wall -ggdb mpdnp.c libmpdclient.c -o mpdnp

Last edited by Zariel (2009-04-20 20:51:56)

Offline

#322 2009-04-21 00:44:05

kourosh
Member
From: England
Registered: 2009-03-10
Posts: 241
Website

Re: Post your handy self made command line utilities

Another badly written script to connect or disconnect from my WLAN, uses Zenity and gksudo, I use it from my openbox menu like my exit script posted earlier:

#!/bin/bash

# Networking script for WLAN, integrate this with openbox menu.
# kourosh 21/04/2009

connect() {
    zenity --question --ok-label="Yes" --cancel-label="No" \
    --text="Are you sure you want to connect to WLAN?"; echo $? > /tmp/test
    if [ $(cat /tmp/test) = 0 ]; then
        rm /tmp/test
        gksudo netcfg [profile] | tee >(zenity --progress --text="Connecting..." --pulsate) > /dev/null
    else
        rm /tmp/test
        exit 0
    fi
}

disconnect() {
    zenity --question --ok-label="Yes" --cancel-label="No" \
    --text="Are you sure you want to disconnect WLAN?"; echo $? > /tmp/test
    if [ $(cat /tmp/test) = 0 ]; then
        gksudo netcfg down [profile] | tee >(zenity --progress --text="Disconnecting..." --pulsate) > /dev/null
        rm /tmp/test
        exit 0
    else
        rm /tmp/test
        exit 0
    fi
}

# Determine what to do and call one of the above
if [ "$1" = "connect" ]
then
    connect
elif [ "$1" = "disconnect" ]
then
    disconnect
else
    zenity --error --text="Usage: network.sh [options] \n \n Options: \n   connect \n   disconnect \n"
    exit 1
fi

Last edited by kourosh (2009-04-21 00:47:13)

Offline

#323 2009-04-23 17:09:34

vlearner
Member
Registered: 2009-03-16
Posts: 52

Re: Post your handy self made command line utilities

[sorry wrong topic]...

Last edited by vlearner (2009-04-23 17:10:12)


I LOVE archlinux

Offline

#324 2009-04-23 19:32:16

hatten
Arch Linux f@h Team Member
From: Sweden, Borlange
Registered: 2009-02-23
Posts: 736

Re: Post your handy self made command line utilities

Mashi wrote:

try
Try a command until it executes successfully. Optionally takes the number of times to try until it is successful.

#!/bin/bash

COUNT=-1
if [[ $1 =~ ^[0-9]+$ ]]; then
    COUNT=$1
    shift    
fi

STATUS=0

while [ "$COUNT" -ne 0 ]; do
    let COUNT-=1
    $*
    STATUS=$?
    if [ $STATUS -eq 0 ]; then
        exit $STATUS
    fi
done
exit $STATUS

thanks, i added a 15m sleep and "tryed" wgetting the ubuntu torrent file last night, after about 50 tries it succeeded, 12 hours after it was launched it exited successfully, and rtorrent could start and download ubuntu big_smile

Offline

#325 2009-04-24 03:18:47

elmer_42
Member
From: /na/usa/ca
Registered: 2008-10-11
Posts: 427

Re: Post your handy self made command line utilities

The kimag.es redesign (looks great btw) broke my previous way of uploading. Here's the updated version. It works as of 23 April 2009.

curl -# -F userfile1=@$1 -D kimagtemp http://kimag.es/upload.php
echo -n "http://kimag.es"
cat kimagtemp|grep /view.php?i=|cut -c11-34
rm kimagtemp

[ lamy + pilot ] [ arch64 | wmii ] [ ati + amd ]

Offline

Board footer

Powered by FluxBB