Skip navigation.

My pasteblog

This is not my Zettelkasten but a durable .bash_history

Posts tagged with "bash"

bash sort integer

,

Seems I am getting disconnected from the world of the cl.

ls | sort -g

*sigh* busadm == Windows-World... :frown:

bash Variable inkrementieren increment

,

EIN -- FUER -- ALLE -- MAL!
i=$(($i+1))

mathmagicians

,

Bought a book explaining mental arithmetic and wrote a quick bash script to pose subtraction-questions:
while (true); do clear; pause=6;divisibleBy=1; max=999; min=11; rnumber1=$(((RANDOM%(max-min+divisibleBy))/divisibleBy*divisibleBy+min)); echo $rnumber1; max=$[${rnumber1}-1]; rnumber2=$(((RANDOM%(max-min+divisibleBy))/divisibleBy*divisibleBy+min)); echo $rnumber2; echo $rnumber1 "minus" $rnumber2 | festival --tts; sleep $pause; result=$[$rnumber1-$rnumber2]; echo "-------"; echo $result; echo "======="; echo $result | festival --tts; echo ""; done


Random code taken from http://tldp.org/LDP/abs/html/randomvar.html

Mastering The Linux Shell - Bash Shortcuts Explained

,

bash spaces filename

,

bash $IFS ls -1
find $dir -name '*.foo' | while read f;do echo $f;done

egrep

, , , ...

egrep "image.*s.*(Los|sport)" /var/log/apache2/access_log | awk '{print $1}' | sort -n | uniq -c | sort -rn

resizing images

, , ,

I know that I know nothing.

And I especially know that I always forget `imagemagick`s command line options :( So here is a tagged remedy:

for f in `ls *JPG`; do echo $f; convert -resize 800x800 $f $f; done


And to rename based on exif tags:
for f in `ls *.JPG`; do echo $f; create_date=""; create_date=`exiftime "$f" 2>&1 | grep -i image\ created | cut -d" " -f3 | sed -e 's/:/-/g'`;if [ "$create_date" != "" ];then echo $create_date;fi;done

More bash var chopping

,

http://my.opera.com/cpr/blog/show.dml/206175

Leaving basename() behind by chopping from the end of the variable-string:

$ for f in `ls *gif`;do echo $f; convert.exe $f ${f%.gif}.png;done
first_basic_admin.gif
first_comments_under_post.gif
first_congrats.gif
first_crud.gif
first_crud_layout.gif
first_custom_admin.gif
first_form_validation.gif
first_login.gif
first_routing.gif
first_welcome.gif
bash-3.00$ ls
first_basic_admin.gif          first_crud.png             first_login.gif
first_basic_admin.png          first_crud_layout.gif      first_login.png
first_comments_under_post.gif  first_crud_layout.png      first_routing.gif
first_comments_under_post.png  first_custom_admin.gif     first_routing.png
first_congrats.gif             first_custom_admin.png     first_welcome.gif
first_congrats.png             first_form_validation.gif  first_welcome.png
first_crud.gif                 first_form_validation.png  symfony_favicon.png
$ for p in `ls *png`; do echo \\pgfdeclareimage\{${p%.png}\}{pictures/${p%.png}};done

Caveat: Sanitize underscore in pgfimage handle

IMG_0020.JPG 020.JPG IMG_x020.JPG
IMG_0021.JPG 021.JPG IMG_x021.JPG
IMG_0022.JPG 022.JPG IMG_x022.JPG
IMG_0023.JPG 023.JPG IMG_x023.JPG
bash-3.1$ for f in `ls *JPG`; do mv $f IMG_x${f#IMG_0};  done

Mass-renaming MySQL tables with simple bash scripting

,

I found out more about stripping from bash variables at IBM's developerworks, written by Daniel Robbins.

~ $ mysql espressopunkt --exec "SHOW TABLES;" > tables.txt #CAVEAT: Rremove additional line at top. THere's probably an automated way for that but this post already tales longer than the task, so why bother...
~ $ for t in `cat tables.txt`;do echo $t;_t=${t#kaffeeweb_};echo $_t;mysql espressopunkt_dev --exec "ALTER TABLE $t RENAME $_t";done

Archiving eBay auctions with wget, input from textfile parsed with awk

, , , ...

#!/bin/bash
awk -F"\t" '

  function makeEasyAccess()
  {
    system("mv " $1 "/cgi.ebay.de/ws/*html " $1 "/cgi.ebay.de/ws/index.html")
    system("sed s~##path##~cgi.ebay.de/ws/index.html~ index.html.tpl > " $1 "/index.html")
  }
  function conditionalFetch()
  {
    #http://www.unix.org.ua/orelly/unix/sedawk/ch10_03.htm
    if (system("test -r " $1 )) {
      print "\t not mirrored, fetching..."
      system(command)
      makeEasyAccess()
    }
    else print "\t already mirrored"
  }

  {
  URL="cgi.ebay.de%2Fws%2FeBayISAPI.dll%3FViewItem%26item" "=" $1
  command = ("/usr/bin/wget --quiet -P " $1 " -F -E -H -k -K -p http://" URL)

  if ( $2 !~ /^shop$/ ) {
    ebayEndtime = mktime ( 20 substr($2,7,2) " " substr($2,4,2) " " substr($2,1,2) " " substr($2,10,2) " " substr($2,13,2) " " substr($2,16,2) )
    if ( ebayEndtime < systime()) {
      print $1 ": ebayEndtime is in past"
      conditionalFetch()
    }
    else print $1 ": ebayEndtime is in future"
  }
  else {
    print $1 ": is a shop offer"
    conditionalFetch()
  }
}' Id_Endtime.txt


The input format is a plain tab-delimeted file with the end time in german format. Other formats need to adjust the above line "ebayEndtime = mktime ( 20 substr($2,7,2) " " substr($2,4,2) " " substr($2,1,2) " " substr($2,10,2) " " substr($2,13,2) " " substr($2,16,2) )"

7392197359 26.02.06 23:51:14 MEZ
7391483206 27.02.06 07:46:37 MEZ
7391548097 27.02.06 20:03:00 MEZ
7387433771 28.02.06 21:30:00 MEZ
6607816962 01.03.06 20:45:00 MEZ
7392366671 02.03.06 16:06:06 MEZ
6608401423 06.03.06 20:35:00 MEZ
7326030533 shop
7351499282 shop
7393652292 07.03.06 19:15:00 MEZ

shell script via Apache/PHP

, , , ...

NOPASSWD: /bin/sh, /path/to/script.sh
script.sh chmod 6755
November 2009
S M T W T F S
October 2009December 2009
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30